Skip to content

Commit

Permalink
fix sql task bug #2739 (#2741)
Browse files Browse the repository at this point in the history
* Solve the failure to execute non-query sql

* fix sql task bug

Co-authored-by: sunchaohe <sunzhaohe@linklogis.com>
Co-authored-by: qiaozhanwei <qiaozhanwei@outlook.com>
Co-authored-by: lgcareer <18610854716@163.com>
  • Loading branch information
4 people committed May 21, 2020
1 parent cfd8323 commit 6d0375e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,27 +213,28 @@ public static String handleEscapes(String inputString){
return inputString;
}


/**
* new
* $[yyyyMMdd] replace scheduler time
* $[yyyyMMdd] replace schedule time
* @param text
* @param paramsMap
* @param scheduleTime
* @return
*/
public static String replaceScheduleTime(String text, Date scheduleTime, Map<String, Property> paramsMap) {
if (paramsMap != null) {
public static String replaceScheduleTime(String text, Date scheduleTime) {
Map<String, Property> paramsMap = new HashMap<>();
//if getScheduleTime null ,is current date
if (null == scheduleTime) {
scheduleTime = new Date();
}

String dateTime = org.apache.dolphinscheduler.common.utils.DateUtils.format(scheduleTime, Constants.PARAMETER_FORMAT_TIME);
Property p = new Property();
p.setValue(dateTime);
p.setProp(Constants.PARAMETER_SHECDULE_TIME);
paramsMap.put(Constants.PARAMETER_SHECDULE_TIME, p);
text = ParameterUtils.convertParameterPlaceholders2(text, convert(paramsMap));
}
return text;

return text;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private SqlBinds getSqlAndSqlParamsMap(String sql) {
}
//new
//replace variable TIME with $[YYYYmmddd...] in sql when history run job and batch complement job
sql = ParameterUtils.replaceScheduleTime(sql, taskExecutionContext.getScheduleTime(), paramsMap);
sql = ParameterUtils.replaceScheduleTime(sql, taskExecutionContext.getScheduleTime());
// special characters need to be escaped, ${} needs to be escaped
String rgex = "['\"]*\\$\\{(.*?)\\}['\"]*";
setSqlParamsMap(sql, rgex, sqlParamsMap, paramsMap);
Expand Down

0 comments on commit 6d0375e

Please sign in to comment.