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

soumyakantidas 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 f3496f30b07 HIVE-29497: [HPLSQL] quit is not exiting from execution 
flow in HPLSQL. (#6405)
f3496f30b07 is described below

commit f3496f30b0731b82059ec0bbc5ad2d62bf12b2cd
Author: Dayakar M <[email protected]>
AuthorDate: Tue Apr 7 00:29:51 2026 +0530

    HIVE-29497: [HPLSQL] quit is not exiting from execution flow in HPLSQL. 
(#6405)
---
 hplsql/src/main/java/org/apache/hive/hplsql/Exec.java  | 12 +++++++++++-
 hplsql/src/test/results/local/if3_bteq.out.txt         |  2 +-
 .../org/apache/hive/beeline/TestHplSqlViaBeeLine.java  | 18 ++++++++++++++++++
 3 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/hplsql/src/main/java/org/apache/hive/hplsql/Exec.java 
b/hplsql/src/main/java/org/apache/hive/hplsql/Exec.java
index a8d5187b773..de233e225f6 100644
--- a/hplsql/src/main/java/org/apache/hive/hplsql/Exec.java
+++ b/hplsql/src/main/java/org/apache/hive/hplsql/Exec.java
@@ -1037,11 +1037,13 @@ public void printExceptions() {
       } else if (sig.type == Signal.Type.VALIDATION) {
         error(((HplValidationException)sig.exception).getCtx(), 
sig.exception.getMessage());
       } else if (sig.type == Signal.Type.SQLEXCEPTION) {
-        console.printError("Unhandled exception in HPL/SQL");
+        console.printError("Unhandled exception in HPL/SQL: " + sig.value);
       } else if (sig.type == Signal.Type.UNSUPPORTED_OPERATION) {
         console.printError(sig.value == null ? "Unsupported operation" : 
sig.value);
       } else if (sig.exception != null) {
         console.printError("HPL/SQL error: " + 
ExceptionUtils.getStackTrace(sig.exception));
+      } else if (sig.type == Signal.Type.LEAVE_PROGRAM) {
+        console.printLine("Leaving Program: " + sig.value);
       } else if (sig.value != null) {
         console.printError(sig.value);
       } else {
@@ -1096,6 +1098,14 @@ public Integer visitStmt(HplsqlParser.StmtContext ctx) {
         return 0;
       }
     }
+
+    if (!exec.signals.empty()) {
+      Signal sig = exec.signals.peek();
+      if (sig.type == Signal.Type.LEAVE_PROGRAM) {
+        return 0;
+      }
+    }
+
     Var prev = stackPop();
     if (prev != null && prev.value != null) {
       console.printLine(prev.toString());
diff --git a/hplsql/src/test/results/local/if3_bteq.out.txt 
b/hplsql/src/test/results/local/if3_bteq.out.txt
index cf2e0899a14..e7adb8f19d4 100644
--- a/hplsql/src/test/results/local/if3_bteq.out.txt
+++ b/hplsql/src/test/results/local/if3_bteq.out.txt
@@ -1,4 +1,4 @@
 Ln:1 IF
 Ln:1 IF TRUE executed
 Ln:1 QUIT
-0
+Leaving Program: 0
diff --git 
a/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestHplSqlViaBeeLine.java
 
b/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestHplSqlViaBeeLine.java
index 2aa433990e8..e186790d487 100644
--- 
a/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestHplSqlViaBeeLine.java
+++ 
b/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestHplSqlViaBeeLine.java
@@ -1401,6 +1401,24 @@ public void testPrintMessageAfterExecuteSetHiveConfig() 
throws Throwable {
     testScriptFile(scriptText, args(), "Should print this message!...", 
OutStream.ERR);
   }
 
+  @Test
+  public void testQuit() throws Throwable {
+    String scriptText =
+        "SET hplsql.onerror='seterror';\n" +
+            "INSERT INTO abc VALUES('Tbl1 Not Exists');\n" +
+            "PRINT 'ERRORCODE: ' || ERRORCODE;\n" +
+            "IF ERRORCODE <> 0 THEN\n" +
+            "    PRINT 'Error detected. Exiting...';\n" +
+            "    .QUIT ERRORCODE;\n" +
+            "END IF;\n" +
+            "INSERT INTO def VALUES('Tbl2 Not Exists');\n" +
+            "PRINT 'Should not print this message'";
+    // Inverted match, output should not have 'Table not found def' error
+    testScriptFile(scriptText, args(),
+        "^(.(?!(Caused by: 
org.apache.hadoop.hive.ql.metadata.InvalidTableException: Table not found 
def)))*$",
+        OutStream.ERR);
+  }
+
   private static List<String> args() {
     return Arrays.asList("-d", BeeLine.BEELINE_DEFAULT_JDBC_DRIVER,
             "-u", miniHS2.getBaseJdbcURL() + ";mode=hplsql", "-n", USER_NAME);

Reply via email to