Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion hplsql/src/main/java/org/apache/hive/hplsql/Exec.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion hplsql/src/test/results/local/if3_bteq.out.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Ln:1 IF
Ln:1 IF TRUE executed
Ln:1 QUIT
0
Leaving Program: 0
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading