diff --git jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java index 2912ece..057fb8c 100644 --- jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java +++ jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java @@ -186,7 +186,7 @@ public boolean execute(String sql) throws SQLException { if (isClosed) { throw new SQLException("Can't execute after statement has been closed"); } - + TExecuteStatementResp execResp = null; try { if (stmtHandle != null) { closeClientOperation(); @@ -194,13 +194,16 @@ public boolean execute(String sql) throws SQLException { TExecuteStatementReq execReq = new TExecuteStatementReq(sessHandle, sql); execReq.setConfOverlay(sessConf); - TExecuteStatementResp execResp = client.ExecuteStatement(execReq); + execResp = client.ExecuteStatement(execReq); Utils.verifySuccessWithInfo(execResp.getStatus()); - stmtHandle = execResp.getOperationHandle(); } catch (SQLException eS) { throw eS; } catch (Exception ex) { throw new SQLException(ex.toString(), "08S01", ex); + } finally { + if (execResp != null) { + stmtHandle = execResp.getOperationHandle(); + } } if (!stmtHandle.isHasResultSet()) { diff --git service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java index 11c96b2..52bf848 100644 --- service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java +++ service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java @@ -184,14 +184,17 @@ private OperationHandle executeStatementInternal(String statement, Map tableTypes) throws HiveSQLException { - acquire(); + acquire(); + OperationHandle opHandle = null; try { MetadataOperation operation = getOperationManager().newGetTablesOperation(getSession(), catalogName, schemaName, tableName, tableTypes); + opHandle = operation.getHandle(); operation.run(); - OperationHandle opHandle = operation.getHandle(); - opHandleSet.add(opHandle); return opHandle; } finally { + if (opHandle != null) { + opHandleSet.add(opHandle); + } release(); } } public OperationHandle getTableTypes() throws HiveSQLException { - acquire(); + acquire(); + OperationHandle opHandle = null; try { GetTableTypesOperation operation = getOperationManager().newGetTableTypesOperation(getSession()); + opHandle = operation.getHandle(); operation.run(); - OperationHandle opHandle = operation.getHandle(); - opHandleSet.add(opHandle); return opHandle; } finally { + if (opHandle != null) { + opHandleSet.add(opHandle); + } release(); } } @@ -272,14 +290,17 @@ public OperationHandle getTableTypes() public OperationHandle getColumns(String catalogName, String schemaName, String tableName, String columnName) throws HiveSQLException { acquire(); + OperationHandle opHandle = null; try { GetColumnsOperation operation = getOperationManager().newGetColumnsOperation(getSession(), catalogName, schemaName, tableName, columnName); + opHandle = operation.getHandle(); operation.run(); - OperationHandle opHandle = operation.getHandle(); - opHandleSet.add(opHandle); return opHandle; } finally { + if (opHandle != null) { + opHandleSet.add(opHandle); + } release(); } } @@ -287,14 +308,17 @@ public OperationHandle getColumns(String catalogName, String schemaName, public OperationHandle getFunctions(String catalogName, String schemaName, String functionName) throws HiveSQLException { acquire(); + OperationHandle opHandle = null; try { GetFunctionsOperation operation = getOperationManager() .newGetFunctionsOperation(getSession(), catalogName, schemaName, functionName); + opHandle = operation.getHandle(); operation.run(); - OperationHandle opHandle = operation.getHandle(); - opHandleSet.add(opHandle); return opHandle; } finally { + if (opHandle != null) { + opHandleSet.add(opHandle); + } release(); } }