Unverified Commit 7cdc3bf8 authored by luoshangjie's avatar luoshangjie Committed by GitHub

[Fix-3587] Fix the stack overflow issue occurring when removing comments from SQL (#3603)

parent f54fd772
...@@ -35,7 +35,6 @@ import org.dinky.data.model.SystemConfiguration; ...@@ -35,7 +35,6 @@ import org.dinky.data.model.SystemConfiguration;
import org.dinky.executor.Executor; import org.dinky.executor.Executor;
import org.dinky.executor.ExecutorConfig; import org.dinky.executor.ExecutorConfig;
import org.dinky.executor.ExecutorFactory; import org.dinky.executor.ExecutorFactory;
import org.dinky.interceptor.FlinkInterceptor;
import org.dinky.parser.SqlType; import org.dinky.parser.SqlType;
import org.dinky.resource.BaseResourceManager; import org.dinky.resource.BaseResourceManager;
import org.dinky.trans.Operations; import org.dinky.trans.Operations;
...@@ -252,9 +251,8 @@ public class Submitter { ...@@ -252,9 +251,8 @@ public class Submitter {
Optional<JobClient> jobClient = Optional.empty(); Optional<JobClient> jobClient = Optional.empty();
for (String statement : statements) { for (String statement : statements) {
String sqlStatement = executor.pretreatStatement(statement); if (ExecuteJarParseStrategy.INSTANCE.match(statement)) {
if (ExecuteJarParseStrategy.INSTANCE.match(sqlStatement)) { ExecuteJarOperation executeJarOperation = new ExecuteJarOperation(statement);
ExecuteJarOperation executeJarOperation = new ExecuteJarOperation(sqlStatement);
Pipeline pipeline = executeJarOperation.getStreamGraph(executor.getCustomTableEnvironment()); Pipeline pipeline = executeJarOperation.getStreamGraph(executor.getCustomTableEnvironment());
ReadableConfig configuration = ReadableConfig configuration =
executor.getStreamExecutionEnvironment().getConfiguration(); executor.getStreamExecutionEnvironment().getConfiguration();
...@@ -285,14 +283,14 @@ public class Submitter { ...@@ -285,14 +283,14 @@ public class Submitter {
jobClient = Optional.of(client); jobClient = Optional.of(client);
break; break;
} }
if (Operations.getOperationType(sqlStatement) == SqlType.ADD) { if (Operations.getOperationType(statement) == SqlType.ADD) {
File[] info = AddJarSqlParseStrategy.getInfo(sqlStatement); File[] info = AddJarSqlParseStrategy.getInfo(statement);
Arrays.stream(info).forEach(executor.getDinkyClassLoader().getUdfPathContextHolder()::addOtherPlugins); Arrays.stream(info).forEach(executor.getDinkyClassLoader().getUdfPathContextHolder()::addOtherPlugins);
if (GatewayType.get(type).isKubernetesApplicationMode()) { if (GatewayType.get(type).isKubernetesApplicationMode()) {
executor.addJar(info); executor.addJar(info);
} }
} else if (Operations.getOperationType(sqlStatement) == SqlType.ADD_FILE) { } else if (Operations.getOperationType(statement) == SqlType.ADD_FILE) {
File[] info = AddFileSqlParseStrategy.getInfo(sqlStatement); File[] info = AddFileSqlParseStrategy.getInfo(statement);
Arrays.stream(info).forEach(executor.getDinkyClassLoader().getUdfPathContextHolder()::addFile); Arrays.stream(info).forEach(executor.getDinkyClassLoader().getUdfPathContextHolder()::addFile);
if (GatewayType.get(type).isKubernetesApplicationMode()) { if (GatewayType.get(type).isKubernetesApplicationMode()) {
executor.addJar(info); executor.addJar(info);
...@@ -311,24 +309,23 @@ public class Submitter { ...@@ -311,24 +309,23 @@ public class Submitter {
List<StatementParam> execute = new ArrayList<>(); List<StatementParam> execute = new ArrayList<>();
for (String item : statements) { for (String item : statements) {
String statement = FlinkInterceptor.pretreatStatement(executor, item); if (item.isEmpty()) {
if (statement.isEmpty()) {
continue; continue;
} }
SqlType operationType = Operations.getOperationType(statement); SqlType operationType = Operations.getOperationType(item);
if (operationType.equals(SqlType.INSERT) || operationType.equals(SqlType.SELECT)) { if (operationType.equals(SqlType.INSERT) || operationType.equals(SqlType.SELECT)) {
trans.add(new StatementParam(statement, operationType)); trans.add(new StatementParam(item, operationType));
if (!executorConfig.isUseStatementSet()) { if (!executorConfig.isUseStatementSet()) {
break; break;
} }
} else if (operationType.equals(SqlType.EXECUTE)) { } else if (operationType.equals(SqlType.EXECUTE)) {
execute.add(new StatementParam(statement, operationType)); execute.add(new StatementParam(item, operationType));
if (!executorConfig.isUseStatementSet()) { if (!executorConfig.isUseStatementSet()) {
break; break;
} }
} else { } else {
ddl.add(new StatementParam(statement, operationType)); ddl.add(new StatementParam(item, operationType));
} }
} }
......
...@@ -61,7 +61,7 @@ public class SqlUtil { ...@@ -61,7 +61,7 @@ public class SqlUtil {
// Remove the special-space characters // Remove the special-space characters
sql = sql.replaceAll("\u00A0", " ").replaceAll("[\r\n]+", "\n"); sql = sql.replaceAll("\u00A0", " ").replaceAll("[\r\n]+", "\n");
// Remove annotations Support '--aa' , '/**aaa*/' , '//aa' , '#aaa' // Remove annotations Support '--aa' , '/**aaa*/' , '//aa' , '#aaa'
Pattern p = Pattern.compile("(?ms)('(?:''|[^'])*')|--.*?$|/\\*[^+].*?\\*/|"); Pattern p = Pattern.compile("(?ms)('(?:[^'])*')|--.*?$|/\\*[^+].*?\\*/|");
String presult = p.matcher(sql).replaceAll("$1"); String presult = p.matcher(sql).replaceAll("$1");
return presult.trim(); return presult.trim();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment