This is an automated email from the ASF dual-hosted git repository.
SbloodyS pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new 974271457b [Fix-18682][Common] Handle whitespace after SQL statement
terminators (#18683)
974271457b is described below
commit 974271457b9b958049fbe3fc07215381a24cb058
Author: csurong <[email protected]>
AuthorDate: Fri Oct 9 16:26:53 2026 +0800
[Fix-18682][Common] Handle whitespace after SQL statement terminators
(#18683)
---
.../common/sql/ClasspathSqlScriptParser.java | 2 +-
.../common/sql/ClasspathSqlScriptParserTest.java | 27 ++++++++++++++++++++++
2 files changed, 28 insertions(+), 1 deletion(-)
diff --git
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/sql/ClasspathSqlScriptParser.java
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/sql/ClasspathSqlScriptParser.java
index d6684b3272..8d24f5d79c 100644
---
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/sql/ClasspathSqlScriptParser.java
+++
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/sql/ClasspathSqlScriptParser.java
@@ -93,7 +93,7 @@ public class ClasspathSqlScriptParser implements
SqlScriptParser {
// begin to parse sql until;
List<String> sqlLines = new ArrayList<>();
sqlLines.add(line);
- while (!line.endsWith(";")) {
+ while (!line.trim().endsWith(";")) {
line = lineNumberReader.readLine();
if (line == null) {
break;
diff --git
a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/sql/ClasspathSqlScriptParserTest.java
b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/sql/ClasspathSqlScriptParserTest.java
index 5eea77e72d..a88b796b60 100644
---
a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/sql/ClasspathSqlScriptParserTest.java
+++
b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/sql/ClasspathSqlScriptParserTest.java
@@ -18,13 +18,40 @@
package org.apache.dolphinscheduler.common.sql;
import java.io.IOException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
class ClasspathSqlScriptParserTest {
+ @Test
+ void testStatementTerminatorsWithTrailingWhitespace(@TempDir Path
directory) throws IOException {
+ ClassLoader originalClassLoader =
Thread.currentThread().getContextClassLoader();
+ try (
+ URLClassLoader classLoader =
+ new URLClassLoader(new
URL[]{directory.toUri().toURL()}, originalClassLoader)) {
+ Thread.currentThread().setContextClassLoader(classLoader);
+ for (String whitespace : Arrays.asList("", " ", "\t", " \t ")) {
+ List<String> statements =
+ Arrays.asList("SELECT 1;" + whitespace, "SELECT\n2;" +
whitespace, "SELECT 3;");
+ Files.write(directory.resolve("trailing_whitespace.sql"),
+ String.join("\n",
statements).getBytes(StandardCharsets.UTF_8));
+ Assertions.assertEquals(statements,
+ new
ClasspathSqlScriptParser("trailing_whitespace.sql").getAllSql());
+ }
+ } finally {
+ Thread.currentThread().setContextClassLoader(originalClassLoader);
+ }
+ }
+
@Test
void testMysqlDmlSql() throws IOException {
ClasspathSqlScriptParser classpathSqlScriptParser = new
ClasspathSqlScriptParser("sql/mysql_dml.sql");