From e7d2e8b3f7f9e15e141f908c88e801624e95cdf2 Mon Sep 17 00:00:00 2001 From: wcmolin Date: Thu, 20 Apr 2023 17:16:14 +0800 Subject: [PATCH] [Fix-13814] [Built-in variable] shell task transfer param --- .../dolphinscheduler/spi/task/paramparser/ParamUtils.java | 6 ++++-- .../apache/dolphinscheduler/plugin/task/sql/SqlTask.java | 5 ++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/task/paramparser/ParamUtils.java b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/task/paramparser/ParamUtils.java index a96fd298836d..dc869c9cfd00 100644 --- a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/task/paramparser/ParamUtils.java +++ b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/task/paramparser/ParamUtils.java @@ -69,7 +69,7 @@ public static Map convert(TaskRequest taskExecutionContext, Ab Map varParams = parameters.getVarPoolMap(); - if (MapUtils.isEmpty(globalParams) && MapUtils.isEmpty(localParams)) { + if (MapUtils.isEmpty(globalParams) && MapUtils.isEmpty(localParams) && MapUtils.isEmpty(varParams)) { return null; } // if it is a complement, @@ -98,7 +98,9 @@ public static Map convert(TaskRequest taskExecutionContext, Ab convertedParams = localParams; } if (varParams != null) { - varParams.putAll(globalParams); + if (globalParams != null) { + varParams.putAll(globalParams); + } globalParams = varParams; for (Map.Entry entry : varParams.entrySet()) { convertedParams.put(entry.getKey(), entry.getValue()); diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-sql/src/main/java/org/apache/dolphinscheduler/plugin/task/sql/SqlTask.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-sql/src/main/java/org/apache/dolphinscheduler/plugin/task/sql/SqlTask.java index a26013042326..2ae7769af918 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-sql/src/main/java/org/apache/dolphinscheduler/plugin/task/sql/SqlTask.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-sql/src/main/java/org/apache/dolphinscheduler/plugin/task/sql/SqlTask.java @@ -436,6 +436,8 @@ private SqlBinds getSqlAndSqlParamsMap(String sql) { Map sqlParamsMap = new HashMap<>(); StringBuilder sqlBuilder = new StringBuilder(); + //replace variable TIME with $[YYYYmmddd...] in sql when history run job and batch complement job + sql = ParameterUtils.replaceScheduleTime(sql, taskExecutionContext.getScheduleTime()); // combining local and global parameters Map paramsMap = ParamUtils.convert(taskExecutionContext, getParameters()); @@ -452,9 +454,6 @@ private SqlBinds getSqlAndSqlParamsMap(String sql) { sqlParameters.setTitle(title); } - //new - //replace variable TIME with $[YYYYmmddd...] in sql when history run job and batch complement job - sql = ParameterUtils.replaceScheduleTime(sql, taskExecutionContext.getScheduleTime()); // special characters need to be escaped, ${} needs to be escaped setSqlParamsMap(sql, rgex, sqlParamsMap, paramsMap,taskExecutionContext.getTaskInstanceId()); //Replace the original value in sql !{...} ,Does not participate in precompilation