changebooks opened a new issue, #12858:
URL: https://github.com/apache/dolphinscheduler/issues/12858

   ### Search before asking
   
   - [X] I had searched in the 
[issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and 
found no similar feature requirement.
   
   
   ### Description
   
   SqlBinds 
org.apache.dolphinscheduler.plugin.task.sql.SqlTask::getSqlAndSqlParamsMap(String
 sql)
   
   简单描述修改内容:
   将 replace !{} 的代码:sql = replaceOriginalValue(sql, rgexo, paramsMap);
   移动到 replace ${} 的代码前面:setSqlParamsMap(sql, rgex, sqlParamsMap, 
paramsMap,taskExecutionContext.getTaskInstanceId());
   
   简单描述业务场景:
   SQL语句:INSERT OVERWRITE TABLE label_1 PARTITION (ds = '${date}') !{sql}
   参数:sql = "SELECT user_id FROM mbr_db.share_friend_num_dt_g WHERE ds = 
'\\${date}' AND group_id = 1 AND num > 0"
   注:参数 sql 中也有 ${date}
   
   先替换 !{sql} ,替换后SQL语句:INSERT OVERWRITE TABLE label_1 PARTITION (ds = 
'${date}') SELECT user_id FROM mbr_db.share_friend_num_dt_g WHERE ds = 
'${date}' AND group_id = 1 AND num > 0
   再分析${date},可确保 sql 参数中的 ${date} 也能被处理到。
   
   反过来,先分析${date},再替换!{sql},导致sql中的${date}未被处理。
   
   已亲测
   
   老代码:
   `
   //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
   
   String rgexo = "['\"]*\\!\\{(.*?)\\}['\"]*";
   
   sql = replaceOriginalValue(sql, rgexo, paramsMap);
   
   // replace the ${} of the SQL statement with the Placeholder
   
   String formatSql = sql.replaceAll(rgex, "?");
   
   sqlBuilder.append(formatSql);
   `
   
   新代码:
   `
   //new
   
   //Replace the original value in sql !{...} ,Does not participate in 
precompilation
   
   String rgexo = "['\"]*\\!\\{(.*?)\\}['\"]*";
   
   sql = replaceOriginalValue(sql, rgexo, paramsMap);
   
   //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 ${} of the SQL statement with the Placeholder
   
   String formatSql = sql.replaceAll(rgex, "?");
   
   sqlBuilder.append(formatSql);
   `
   
   ### Are you willing to submit a PR?
   
   - [X] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: 
[email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to