diff --git a/beeline/src/java/org/apache/hive/beeline/Commands.java b/beeline/src/java/org/apache/hive/beeline/Commands.java index a25e09b..28c359f 100644 --- a/beeline/src/java/org/apache/hive/beeline/Commands.java +++ b/beeline/src/java/org/apache/hive/beeline/Commands.java @@ -67,7 +67,7 @@ public class Commands { private final BeeLine beeLine; - private static final int DEFAULT_QUERY_PROGRESS_INTERVAL = 1000; + private static final int DEFAULT_QUERY_PROGRESS_INTERVAL = 500; private static final int DEFAULT_QUERY_PROGRESS_THREAD_TIMEOUT = 10 * 1000; /** diff --git a/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java b/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java index a242501..5f478af 100644 --- a/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java +++ b/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java @@ -49,6 +49,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.TimeUnit; /** * HiveStatement. @@ -344,8 +345,23 @@ TGetOperationStatusResp waitForOperationToComplete() throws SQLException { TGetOperationStatusReq statusReq = new TGetOperationStatusReq(stmtHandle); TGetOperationStatusResp statusResp = null; + long start = System.currentTimeMillis(); + long oldLongPollingTimeout = 0; // Poll on the operation status, till the operation is complete while (!isOperationComplete) { + long elapsedTime = System.currentTimeMillis() - start; + // A step function to increase the plling timeout by 500 ms every 10 sec. The initial value is 500 ms. + long longPollingTimout = (elapsedTime / TimeUnit.SECONDS.toMillis(10) + 1) * 500; + + if (longPollingTimout != oldLongPollingTimeout) { + try { + UpdatePollingTimeout(longPollingTimout); + oldLongPollingTimeout = longPollingTimout; + } catch (Exception ex) { + LOG.warn("Ignoring the errors when setting the long polling timeout", ex); + } + } + try { /** * For an async SQLOperation, GetOperationStatus will use the long polling approach It will @@ -388,6 +404,25 @@ TGetOperationStatusResp waitForOperationToComplete() throws SQLException { return statusResp; } + + private void UpdatePollingTimeout(long timeout) throws SQLException + { + String command = String.format("set hive.server2.long.polling.timeout=%d", timeout); + TExecuteStatementReq execReq = new TExecuteStatementReq(sessHandle, command); + + execReq.setRunAsync(false); + execReq.setConfOverlay(null); + execReq.setQueryTimeout(0); + + try { + TExecuteStatementResp execResp = client.ExecuteStatement(execReq); + Utils.verifySuccessWithInfo(execResp.getStatus()); + } catch (SQLException e) { + throw e; + } catch (Exception e) { + throw new SQLException(e.toString(), "08S01", e); + } + } private void checkConnection(String action) throws SQLException { if (isClosed) {