This is an automated email from the ASF dual-hosted git repository.

abstractdog pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git


The following commit(s) were added to refs/heads/master by this push:
     new 3f98ee6f78d HIVE-30257: BeeLine cannot parse semicolons properly in 
source file (#6959)
3f98ee6f78d is described below

commit 3f98ee6f78db7f0a121109ea7b032e57cd0148b4
Author: ramitg254 <[email protected]>
AuthorDate: Fri Nov 20 16:28:47 2026 +0530

    HIVE-30257: BeeLine cannot parse semicolons properly in source file (#6959)
---
 .../src/java/org/apache/hive/beeline/Commands.java |  8 ++--
 .../test/org/apache/hive/beeline/TestCommands.java | 53 ++++++++++++++++++++++
 2 files changed, 58 insertions(+), 3 deletions(-)

diff --git a/beeline/src/java/org/apache/hive/beeline/Commands.java 
b/beeline/src/java/org/apache/hive/beeline/Commands.java
index f78979d96bf..4de2bdc770e 100644
--- a/beeline/src/java/org/apache/hive/beeline/Commands.java
+++ b/beeline/src/java/org/apache/hive/beeline/Commands.java
@@ -902,9 +902,11 @@ private boolean sourceFileInternal(File sourceFile) throws 
IOException {
           lines += "\n" + extra;
         }
       }
-      String[] cmds = lines.split(beeLine.getOpts().getDelimiter());
-      for (String c : cmds) {
-        c = c.trim();
+      if (lines == null || lines.isEmpty()) {
+        return true;
+      }
+      for (String c : getCmdList(lines, false)) {
+        c = HiveStringUtils.removeComments(c.trim());
         if (!executeInternal(c, false)) {
           return false;
         }
diff --git a/beeline/src/test/org/apache/hive/beeline/TestCommands.java 
b/beeline/src/test/org/apache/hive/beeline/TestCommands.java
index 2297865d487..b8009e531b5 100644
--- a/beeline/src/test/org/apache/hive/beeline/TestCommands.java
+++ b/beeline/src/test/org/apache/hive/beeline/TestCommands.java
@@ -21,9 +21,16 @@
 
 import static org.apache.hive.common.util.HiveStringUtils.removeComments;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
+import java.io.File;
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
 
 import org.junit.Test;
 
@@ -376,5 +383,51 @@ public void testGetCmdList() throws Exception {
       beeline.close();
     }
   }
+
+  @Test
+  public void testSourceFileDelimiterInQuery() throws Exception {
+    List<String> statements = Arrays.asList(
+        "select 'foo;bar' as s",
+        "select current_database() as db",
+        "select 1 as ok",
+        "select 2 as also_ok",
+        "select 1 as a",
+        "select /* part; two */ 2 as b");
+    assertEquals(statements, sourceScript(toScript(statements)));
+
+    assertEquals(Collections.emptyList(), sourceScript(""));
+    assertEquals(Collections.emptyList(),
+        sourceScript("-- only a comment; with semicolon\n# shell; comment\n"));
+
+    assertEquals(Arrays.asList("select 1", "select 2"),
+        sourceScript("select 1; -- note; more\nselect 2;\n"));
+  }
+
+  private static String toScript(List<String> statements) {
+    StringBuilder scriptText = new StringBuilder();
+    for (String statement : statements) {
+      scriptText.append(statement).append(";\n");
+    }
+    return scriptText.toString();
+  }
+
+  private static List<String> sourceScript(String scriptText) throws Exception 
{
+    BeeLine beeline = new BeeLine();
+    Commands commands = new Commands(beeline);
+    List<String> batch = new ArrayList<>();
+    beeline.setBatch(batch);
+    File script = File.createTempFile("hive-30257", ".sql");
+    try {
+      Files.write(script.toPath(), 
scriptText.getBytes(StandardCharsets.UTF_8));
+      assertTrue(commands.sql("source " + script.getAbsolutePath() + ";", 
false));
+      return batch;
+    } finally {
+      beeline.setBatch(null);
+      beeline.close();
+      if (!script.delete()) {
+        script.deleteOnExit();
+      }
+    }
+  }
 }
 

Reply via email to