This is an automated email from the ASF dual-hosted git repository.
wenjun pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new a55612e4f7 Fix switch task use boolean type error (#14326)
a55612e4f7 is described below
commit a55612e4f718fb35401b7393d2eb2862f725b37b
Author: Wenjun Ruan <[email protected]>
AuthorDate: Tue Jun 13 13:26:05 2023 +0800
Fix switch task use boolean type error (#14326)
---
.../runner/task/switchtask/SwitchLogicTask.java | 9 ++++--
.../plugin/task/api/parser/ParameterUtils.java | 35 ++++++++++++++++++++++
2 files changed, 41 insertions(+), 3 deletions(-)
diff --git
a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/task/switchtask/SwitchLogicTask.java
b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/task/switchtask/SwitchLogicTask.java
index 47f978ce76..038cff7797 100644
---
a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/task/switchtask/SwitchLogicTask.java
+++
b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/task/switchtask/SwitchLogicTask.java
@@ -26,6 +26,7 @@ import
org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
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;
@@ -151,9 +152,11 @@ public class SwitchLogicTask extends
BaseSyncLogicTask<SwitchParameters> {
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);
diff --git
a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/parser/ParameterUtils.java
b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/parser/ParameterUtils.java
index aca4ed267a..920b635572 100644
---
a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/parser/ParameterUtils.java
+++
b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/parser/ParameterUtils.java
@@ -28,6 +28,7 @@ import
org.apache.dolphinscheduler.plugin.task.api.model.Property;
import org.apache.commons.lang3.StringUtils;
+import java.io.Serializable;
import java.sql.PreparedStatement;
import java.util.Date;
import java.util.HashMap;
@@ -149,6 +150,40 @@ public class ParameterUtils {
}
}
+ 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()) {