Skip to content

Commit

Permalink
[Fix-3587] Fix the stack overflow issue occurring when removing comme…
Browse files Browse the repository at this point in the history
…nts from SQL (DataLinkDC#3603)

Co-authored-by: luoshangjie <luoshangjie@yfpharmacy.com>
Co-authored-by: GH Action - Upstream Sync <action@github.com>
  • Loading branch information
3 people authored Jun 26, 2024
1 parent f54fd77 commit 7cdc3bf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.dinky.executor.Executor;
import org.dinky.executor.ExecutorConfig;
import org.dinky.executor.ExecutorFactory;
import org.dinky.interceptor.FlinkInterceptor;
import org.dinky.parser.SqlType;
import org.dinky.resource.BaseResourceManager;
import org.dinky.trans.Operations;
Expand Down Expand Up @@ -252,9 +251,8 @@ public static Optional<JobClient> executeJarJob(String type, Executor executor,
Optional<JobClient> jobClient = Optional.empty();

for (String statement : statements) {
String sqlStatement = executor.pretreatStatement(statement);
if (ExecuteJarParseStrategy.INSTANCE.match(sqlStatement)) {
ExecuteJarOperation executeJarOperation = new ExecuteJarOperation(sqlStatement);
if (ExecuteJarParseStrategy.INSTANCE.match(statement)) {
ExecuteJarOperation executeJarOperation = new ExecuteJarOperation(statement);
Pipeline pipeline = executeJarOperation.getStreamGraph(executor.getCustomTableEnvironment());
ReadableConfig configuration =
executor.getStreamExecutionEnvironment().getConfiguration();
Expand Down Expand Up @@ -285,14 +283,14 @@ public static Optional<JobClient> executeJarJob(String type, Executor executor,
jobClient = Optional.of(client);
break;
}
if (Operations.getOperationType(sqlStatement) == SqlType.ADD) {
File[] info = AddJarSqlParseStrategy.getInfo(sqlStatement);
if (Operations.getOperationType(statement) == SqlType.ADD) {
File[] info = AddJarSqlParseStrategy.getInfo(statement);
Arrays.stream(info).forEach(executor.getDinkyClassLoader().getUdfPathContextHolder()::addOtherPlugins);
if (GatewayType.get(type).isKubernetesApplicationMode()) {
executor.addJar(info);
}
} else if (Operations.getOperationType(sqlStatement) == SqlType.ADD_FILE) {
File[] info = AddFileSqlParseStrategy.getInfo(sqlStatement);
} else if (Operations.getOperationType(statement) == SqlType.ADD_FILE) {
File[] info = AddFileSqlParseStrategy.getInfo(statement);
Arrays.stream(info).forEach(executor.getDinkyClassLoader().getUdfPathContextHolder()::addFile);
if (GatewayType.get(type).isKubernetesApplicationMode()) {
executor.addJar(info);
Expand All @@ -311,24 +309,23 @@ public static Optional<JobClient> executeJob(Executor executor, String[] stateme
List<StatementParam> execute = new ArrayList<>();

for (String item : statements) {
String statement = FlinkInterceptor.pretreatStatement(executor, item);
if (statement.isEmpty()) {
if (item.isEmpty()) {
continue;
}

SqlType operationType = Operations.getOperationType(statement);
SqlType operationType = Operations.getOperationType(item);
if (operationType.equals(SqlType.INSERT) || operationType.equals(SqlType.SELECT)) {
trans.add(new StatementParam(statement, operationType));
trans.add(new StatementParam(item, operationType));
if (!executorConfig.isUseStatementSet()) {
break;
}
} else if (operationType.equals(SqlType.EXECUTE)) {
execute.add(new StatementParam(statement, operationType));
execute.add(new StatementParam(item, operationType));
if (!executorConfig.isUseStatementSet()) {
break;
}
} else {
ddl.add(new StatementParam(statement, operationType));
ddl.add(new StatementParam(item, operationType));
}
}

Expand Down
2 changes: 1 addition & 1 deletion dinky-common/src/main/java/org/dinky/utils/SqlUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static String removeNote(String sql) {
// Remove the special-space characters
sql = sql.replaceAll("\u00A0", " ").replaceAll("[\r\n]+", "\n");
// Remove annotations Support '--aa' , '/**aaa*/' , '//aa' , '#aaa'
Pattern p = Pattern.compile("(?ms)('(?:''|[^'])*')|--.*?$|/\\*[^+].*?\\*/|");
Pattern p = Pattern.compile("(?ms)('(?:[^'])*')|--.*?$|/\\*[^+].*?\\*/|");
String presult = p.matcher(sql).replaceAll("$1");
return presult.trim();
}
Expand Down

0 comments on commit 7cdc3bf

Please sign in to comment.