Skip to content

Commit

Permalink
[Bug]Fix variable can`t throw error (#4114)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaoyan1998 authored Jan 4, 2025
1 parent 779d803 commit 2d94bc7
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions dinky-core/src/main/java/org/dinky/executor/VariableManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,25 +134,21 @@ public Object getVariable(String variableName) {
checkArgument(
!StringUtils.isNullOrWhitespaceOnly(variableName),
"sql variable name or jexl key cannot be null or empty.");
try {
if (variables.containsKey(variableName)) {
return variables.get(variableName);
}
// load expression variable class
if (parseAndMatchExpressionVariable(variableName)) {
return ENGINE.eval(variableName, EngineContextHolder.getEngineContext(), null);
}
return null;
} catch (Exception e) {
String error = format(
"The variable name or jexl key of sql \"${%s}\" does not exist.\n"
+ "Please follow the following methods to resolve the problem:\n"
+ "1. global variables are enabled ? \n"
+ "2. variable is exists ? it`s defined in sql ? or global variable is defined ? \n"
+ "3. If it is a custom function variable, please check whether the class is loaded correctly",
variableName);
throw new BusException(error);
if (variables.containsKey(variableName)) {
return variables.get(variableName);
}
// load expression variable class
if (parseAndMatchExpressionVariable(variableName)) {
return ENGINE.eval(variableName, EngineContextHolder.getEngineContext(), null);
}
String error = format(
"The variable name or jexl key of sql \"${%s}\" does not exist.\n"
+ "Please follow the following methods to resolve the problem:\n"
+ "1. global variables are enabled ? \n"
+ "2. variable is exists ? it`s defined in sql ? or global variable is defined ? \n"
+ "3. If it is a custom function variable, please check whether the class is loaded correctly",
variableName);
throw new BusException(error);
}

public boolean parseAndMatchExpressionVariable(String variableName) {
Expand Down

0 comments on commit 2d94bc7

Please sign in to comment.