diff --git beeline/src/java/org/apache/hive/beeline/Commands.java beeline/src/java/org/apache/hive/beeline/Commands.java index 6a3ad42..0cee438 100644 --- beeline/src/java/org/apache/hive/beeline/Commands.java +++ beeline/src/java/org/apache/hive/beeline/Commands.java @@ -1287,21 +1287,32 @@ private void debug(String message) { } private void updateQueryLog() throws SQLException { - for (String log : hiveStatement.getQueryLog()) { - commands.beeLine.info(log); + if (hiveStatement.hasMoreLogs()) { + for (String log : hiveStatement.getQueryLog()) { + commands.beeLine.info(log); + } } } + private void showRemainingLogsIfAny() { + commands.debug("Getting log thread is interrupted, since query is done!"); + commands.showRemainingLogsIfAny(hiveStatement); + } + @Override public void run() { while (hiveStatement.hasMoreLogs()) { try { + if (Thread.currentThread().isInterrupted()) { + showRemainingLogsIfAny(); + break; + } updateQueryLog(); Thread.sleep(queryProgressInterval); } catch (SQLException e) { commands.error(new SQLWarning(e)); } catch (InterruptedException e) { - commands.debug("Getting log thread is interrupted, since query is done!"); - commands.showRemainingLogsIfAny(hiveStatement); + showRemainingLogsIfAny(); + break; } } } @@ -1313,7 +1324,11 @@ private void showRemainingLogsIfAny(Statement statement) { List logs = null; do { try { - logs = hiveStatement.getQueryLog(); + if (hiveStatement.hasMoreLogs()) { + logs = hiveStatement.getQueryLog(); + } else { + return; + } } catch (SQLException e) { beeLine.error(new SQLWarning(e)); return; diff --git jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java index c846a76..5ab6c90 100644 --- jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java +++ jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java @@ -315,9 +315,11 @@ private void runAsyncOnServer(String sql) throws SQLException { isExecuteStatementFailed = false; } catch (SQLException eS) { isExecuteStatementFailed = true; + isLogBeingGenerated = false; throw eS; } catch (Exception ex) { isExecuteStatementFailed = true; + isLogBeingGenerated = false; throw new SQLException(ex.toString(), "08S01", ex); } }