break60 4 years ago
parent
commit
4950549688
  1. 2
      NOTICE
  2. 2
      dolphinscheduler-dist/release-docs/NOTICE
  3. 31
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/sql/SqlTask.java

2
NOTICE

@ -1,5 +1,5 @@
Apache DolphinScheduler (incubating) Apache DolphinScheduler (incubating)
Copyright 2019-2020 The Apache Software Foundation Copyright 2019-2021 The Apache Software Foundation
This product includes software developed at This product includes software developed at
The Apache Software Foundation (http://www.apache.org/). The Apache Software Foundation (http://www.apache.org/).

2
dolphinscheduler-dist/release-docs/NOTICE vendored

@ -1,5 +1,5 @@
Apache DolphinScheduler (incubating) Apache DolphinScheduler (incubating)
Copyright 2019-2020 The Apache Software Foundation Copyright 2019-2021 The Apache Software Foundation
This product includes software developed at This product includes software developed at
The Apache Software Foundation (http://www.apache.org/). The Apache Software Foundation (http://www.apache.org/).

31
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/sql/SqlTask.java

@ -18,7 +18,9 @@ package org.apache.dolphinscheduler.server.worker.task.sql;
import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.dolphinscheduler.alert.utils.MailUtils; import org.apache.dolphinscheduler.alert.utils.MailUtils;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.common.enums.*; import org.apache.dolphinscheduler.common.enums.*;
@ -41,6 +43,7 @@ import org.apache.dolphinscheduler.server.utils.ParamUtils;
import org.apache.dolphinscheduler.server.utils.UDFUtils; import org.apache.dolphinscheduler.server.utils.UDFUtils;
import org.apache.dolphinscheduler.server.worker.task.AbstractTask; import org.apache.dolphinscheduler.server.worker.task.AbstractTask;
import org.apache.dolphinscheduler.service.bean.SpringApplicationContext; import org.apache.dolphinscheduler.service.bean.SpringApplicationContext;
import org.slf4j.Logger; import org.slf4j.Logger;
import java.sql.*; import java.sql.*;
@ -51,6 +54,7 @@ import java.util.stream.Collectors;
import static org.apache.dolphinscheduler.common.Constants.*; import static org.apache.dolphinscheduler.common.Constants.*;
import static org.apache.dolphinscheduler.common.enums.DbType.HIVE; import static org.apache.dolphinscheduler.common.enums.DbType.HIVE;
/** /**
* sql task * sql task
*/ */
@ -148,6 +152,7 @@ public class SqlTask extends AbstractTask {
/** /**
* ready to execute SQL and parameter entity Map * ready to execute SQL and parameter entity Map
*
* @return SqlBinds * @return SqlBinds
*/ */
private SqlBinds getSqlAndSqlParamsMap(String sql) { private SqlBinds getSqlAndSqlParamsMap(String sql) {
@ -182,7 +187,9 @@ public class SqlTask extends AbstractTask {
// special characters need to be escaped, ${} needs to be escaped // special characters need to be escaped, ${} needs to be escaped
String rgex = "['\"]*\\$\\{(.*?)\\}['\"]*"; String rgex = "['\"]*\\$\\{(.*?)\\}['\"]*";
setSqlParamsMap(sql, rgex, sqlParamsMap, paramsMap); setSqlParamsMap(sql, rgex, sqlParamsMap, paramsMap);
//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 // replace the ${} of the SQL statement with the Placeholder
String formatSql = sql.replaceAll(rgex, "?"); String formatSql = sql.replaceAll(rgex, "?");
sqlBuilder.append(formatSql); sqlBuilder.append(formatSql);
@ -192,6 +199,20 @@ public class SqlTask extends AbstractTask {
return new SqlBinds(sqlBuilder.toString(), sqlParamsMap); return new SqlBinds(sqlBuilder.toString(), sqlParamsMap);
} }
public String replaceOriginalValue(String content, String rgex, Map<String, Property> sqlParamsMap) {
Pattern pattern = Pattern.compile(rgex);
while (true) {
Matcher m = pattern.matcher(content);
if (!m.find()) {
break;
}
String paramName = m.group(1);
String paramValue = sqlParamsMap.get(paramName).getValue();
content = m.replaceFirst(paramValue);
}
return content;
}
@Override @Override
public AbstractParameters getParameters() { public AbstractParameters getParameters() {
return this.sqlParameters; return this.sqlParameters;
@ -199,6 +220,7 @@ public class SqlTask extends AbstractTask {
/** /**
* execute function and sql * execute function and sql
*
* @param mainSqlBinds main sql binds * @param mainSqlBinds main sql binds
* @param preStatementsBinds pre statements binds * @param preStatementsBinds pre statements binds
* @param postStatementsBinds post statements binds * @param postStatementsBinds post statements binds
@ -297,7 +319,6 @@ public class SqlTask extends AbstractTask {
* *
* @param connection connection * @param connection connection
* @param postStatementsBinds postStatementsBinds * @param postStatementsBinds postStatementsBinds
* @throws Exception
*/ */
private void postSql(Connection connection, private void postSql(Connection connection,
List<SqlBinds> postStatementsBinds) throws Exception { List<SqlBinds> postStatementsBinds) throws Exception {
@ -308,12 +329,12 @@ public class SqlTask extends AbstractTask {
} }
} }
} }
/** /**
* create temp function * create temp function
* *
* @param connection connection * @param connection connection
* @param createFuncs createFuncs * @param createFuncs createFuncs
* @throws Exception
*/ */
private void createTempFunction(Connection connection, private void createTempFunction(Connection connection,
List<String> createFuncs) throws Exception { List<String> createFuncs) throws Exception {
@ -390,6 +411,7 @@ public class SqlTask extends AbstractTask {
/** /**
* preparedStatement bind * preparedStatement bind
*
* @param connection connection * @param connection connection
* @param sqlBinds sqlBinds * @param sqlBinds sqlBinds
* @return PreparedStatement * @return PreparedStatement
@ -416,6 +438,7 @@ public class SqlTask extends AbstractTask {
/** /**
* send mail as an attachment * send mail as an attachment
*
* @param title title * @param title title
* @param content content * @param content content
*/ */
@ -463,6 +486,7 @@ public class SqlTask extends AbstractTask {
/** /**
* regular expressions match the contents between two specified strings * regular expressions match the contents between two specified strings
*
* @param content content * @param content content
* @param rgex rgex * @param rgex rgex
* @param sqlParamsMap sql params map * @param sqlParamsMap sql params map
@ -484,6 +508,7 @@ public class SqlTask extends AbstractTask {
/** /**
* print replace sql * print replace sql
*
* @param content content * @param content content
* @param formatSql format sql * @param formatSql format sql
* @param rgex rgex * @param rgex rgex

Loading…
Cancel
Save