Skip to content

Commit

Permalink
Fix switch task use boolean type error (#14326)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanwenjun authored Jun 13, 2023
1 parent 61118d4 commit a55612e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.dolphinscheduler.plugin.task.api.model.Property;
import org.apache.dolphinscheduler.plugin.task.api.model.SwitchResultVo;
import org.apache.dolphinscheduler.plugin.task.api.parameters.SwitchParameters;
import org.apache.dolphinscheduler.plugin.task.api.parser.ParameterUtils;
import org.apache.dolphinscheduler.server.master.cache.ProcessInstanceExecCacheManager;
import org.apache.dolphinscheduler.server.master.exception.LogicTaskInitializeException;
import org.apache.dolphinscheduler.server.master.exception.MasterTaskExecuteException;
Expand Down Expand Up @@ -151,9 +152,11 @@ public String setTaskParams(String content, String rgex) {
if (property == null) {
return "";
}
String value = property.getValue();
if (!org.apache.commons.lang3.math.NumberUtils.isCreatable(value)) {
value = "\"" + value + "\"";
String value;
if (ParameterUtils.isNumber(property) || ParameterUtils.isBoolean(property)) {
value = "" + ParameterUtils.getParameterValue(property);
} else {
value = "\"" + ParameterUtils.getParameterValue(property) + "\"";
}
log.info("paramName:{},paramValue:{}", paramName, value);
content = content.replace("${" + paramName + "}", value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.sql.PreparedStatement;
import java.util.Date;
import java.util.HashMap;
Expand Down Expand Up @@ -149,6 +150,40 @@ public static void setInParameter(int index, PreparedStatement stmt, DataType da
}
}

public static Serializable getParameterValue(Property property) {
if (property == null) {
return null;
}
String value = property.getValue();
switch (property.getType()) {
case LONG:
return Long.valueOf(value);
case FLOAT:
return Float.valueOf(value);
case INTEGER:
return Integer.valueOf(value);
case DOUBLE:
return Double.valueOf(value);
case BOOLEAN:
return Boolean.valueOf(value);
// todo: add date type, list type....
default:
return value;
}
}

public static boolean isNumber(Property property) {
return property != null &&
(DataType.INTEGER.equals(property.getType())
|| DataType.LONG.equals(property.getType())
|| DataType.FLOAT.equals(property.getType())
|| DataType.DOUBLE.equals(property.getType()));
}

public static boolean isBoolean(Property property) {
return property != null && DataType.BOOLEAN.equals(property.getType());
}

public static String expandListParameter(Map<Integer, Property> params, String sql) {
Map<Integer, Property> expandMap = new HashMap<>();
if (params == null || params.isEmpty()) {
Expand Down

0 comments on commit a55612e

Please sign in to comment.