diff --git a/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java b/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java index 6a404bd..cdff4db 100644 --- a/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java +++ b/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java @@ -2082,7 +2082,7 @@ private static void populateLlapDaemonVarsSet(Set llapDaemonVarsSetLocal HIVE_SERVER2_THRIFT_BIND_HOST("hive.server2.thrift.bind.host", "", "Bind host on which to run the HiveServer2 Thrift service."), HIVE_SERVER2_PARALLEL_COMPILATION("hive.driver.parallel.compilation", false, "Whether to\n" + - "enable parallel compilation between sessions on HiveServer2. The default is false."), + "enable parallel compilation of the queries between sessions and within the same session on HiveServer2. The default is false."), HIVE_SERVER2_COMPILE_LOCK_TIMEOUT("hive.server2.compile.lock.timeout", "0s", new TimeValidator(TimeUnit.SECONDS), "Number of seconds a request will wait to acquire the compile lock before giving up. " + diff --git a/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcWithMiniHS2.java b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcWithMiniHS2.java index a01daa4..3beaaa2 100644 --- a/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcWithMiniHS2.java +++ b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcWithMiniHS2.java @@ -138,6 +138,40 @@ public void testConnection() throws Exception { } @Test + public void testParallelCompilation() throws Exception { + String tableName = "testParallelCompilation"; + hs2Conn = getConnection(); + Statement stmt = hs2Conn.createStatement(); + + // create table + stmt.execute("DROP TABLE IF EXISTS " + tableName); + stmt.execute("CREATE TABLE " + tableName + + " (under_col INT COMMENT 'the under column', value STRING) COMMENT ' test table'"); + + // load data + stmt.execute("load data local inpath '" + + kvDataFilePath.toString() + "' into table " + tableName); + + ResultSet res = stmt.executeQuery("SELECT * FROM " + tableName); + assertTrue(res.next()); + res.close(); + + stmt.execute("SET hive.driver.parallel.compilation=true"); + stmt.execute("SET hive.server2.async.exec.async.compile=true"); + + stmt.close(); + + Statement stmt1 = hs2Conn.createStatement(); + Statement stmt2 = hs2Conn.createStatement(); + ResultSet result1 = stmt1.executeQuery("select count(*) from " + tableName); + ResultSet result2 = stmt2.executeQuery("select value from " + tableName + " limit 1"); + assertEquals(3, result1.getInt(1)); + assertEquals(3, result2.getInt(1)); + stmt1.close(); + stmt2.close(); + } + + @Test public void testConcurrentStatements() throws Exception { String tableName = "testConcurrentStatements"; hs2Conn = getConnection(); diff --git a/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java b/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java index 38ccc78..ac4b85a 100644 --- a/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java +++ b/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java @@ -248,10 +248,10 @@ public void closeOnCompletion() throws SQLException { @Override public boolean execute(String sql) throws SQLException { runAsyncOnServer(sql); - waitForOperationToComplete(); + TGetOperationStatusResp status = waitForOperationToComplete(); // The query should be completed by now - if (!stmtHandle.isHasResultSet()) { + if (!status.isHasResultSet()) { return false; } resultSet = new HiveQueryResultSet.Builder(this).setClient(client).setSessionHandle(sessHandle) @@ -299,7 +299,7 @@ private void runAsyncOnServer(String sql) throws SQLException { * Run asynchronously whenever possible * Currently only a SQLOperation can be run asynchronously, * in a background operation thread - * Compilation is synchronous and execution is asynchronous + * Compilation can run asynchronously or synchronously and execution run asynchronously */ execReq.setRunAsync(true); execReq.setConfOverlay(sessConf); @@ -318,9 +318,9 @@ private void runAsyncOnServer(String sql) throws SQLException { } } - void waitForOperationToComplete() throws SQLException { + private TGetOperationStatusResp waitForOperationToComplete() throws SQLException { TGetOperationStatusReq statusReq = new TGetOperationStatusReq(stmtHandle); - TGetOperationStatusResp statusResp; + TGetOperationStatusResp statusResp = null; // Poll on the operation status, till the operation is complete while (!isOperationComplete) { @@ -363,6 +363,8 @@ void waitForOperationToComplete() throws SQLException { throw new SQLException(e.toString(), "08S01", e); } } + + return statusResp; } private void checkConnection(String action) throws SQLException { diff --git a/service/src/java/org/apache/hive/service/cli/OperationStatus.java b/service/src/java/org/apache/hive/service/cli/OperationStatus.java index 5e24d38..b0a26e3 100644 --- a/service/src/java/org/apache/hive/service/cli/OperationStatus.java +++ b/service/src/java/org/apache/hive/service/cli/OperationStatus.java @@ -28,13 +28,15 @@ private final String taskStatus; private final long operationStarted; private final long operationCompleted; + private final boolean hasResultSet; private final HiveSQLException operationException; - public OperationStatus(OperationState state, String taskStatus, long operationStarted, long operationCompleted, HiveSQLException operationException) { + public OperationStatus(OperationState state, String taskStatus, long operationStarted, long operationCompleted, boolean hasResultSet, HiveSQLException operationException) { this.state = state; this.taskStatus = taskStatus; this.operationStarted = operationStarted; this.operationCompleted = operationCompleted; + this.hasResultSet = hasResultSet; this.operationException = operationException; } @@ -54,6 +56,10 @@ public long getOperationCompleted() { return operationCompleted; } + public boolean getHasResultSet() { + return hasResultSet; + } + public HiveSQLException getOperationException() { return operationException; } diff --git a/service/src/java/org/apache/hive/service/cli/operation/Operation.java b/service/src/java/org/apache/hive/service/cli/operation/Operation.java index 0932884..d48b92c 100644 --- a/service/src/java/org/apache/hive/service/cli/operation/Operation.java +++ b/service/src/java/org/apache/hive/service/cli/operation/Operation.java @@ -144,7 +144,7 @@ public OperationStatus getStatus() { } catch (HiveSQLException sqlException) { LOG.error("Error getting task status for " + opHandle.toString(), sqlException); } - return new OperationStatus(state, taskStatus, operationStart, operationComplete, operationException); + return new OperationStatus(state, taskStatus, operationStart, operationComplete, hasResultSet, operationException); } public boolean hasResultSet() { diff --git a/service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIService.java b/service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIService.java index 5464e58..8bc3d94 100644 --- a/service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIService.java +++ b/service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIService.java @@ -629,6 +629,7 @@ public TGetOperationStatusResp GetOperationStatus(TGetOperationStatusReq req) th resp.setTaskStatus(operationStatus.getTaskStatus()); resp.setOperationStarted(operationStatus.getOperationStarted()); resp.setOperationCompleted(operationStatus.getOperationCompleted()); + resp.setHasResultSet(operationStatus.getHasResultSet()); if (opException != null) { resp.setSqlState(opException.getSQLState()); resp.setErrorCode(opException.getErrorCode());