日期:2014-05-16 浏览次数:20609 次
public boolean execute(String sql) throws SQLException { if (isClosed) { throw new SQLException("Can't execute after statement has been closed"); } try { closeClientOperation(); TExecuteStatementReq execReq = new TExecuteStatementReq(sessHandle, sql); execReq.setConfOverlay(sessConf); TExecuteStatementResp execResp = client.ExecuteStatement(execReq); if (execResp.getStatus().getStatusCode().equals(TStatusCode.STILL_EXECUTING_STATUS)) { warningChain = Utils.addWarning(warningChain, new SQLWarning("Query execuing asynchronously")); } else { Utils.verifySuccessWithInfo(execResp.getStatus()); } stmtHandle = execResp.getOperationHandle(); } catch (SQLException eS) { throw eS; } catch (Exception ex) { throw new SQLException(ex.toString(), "08S01", ex); } if (!stmtHandle.isHasResultSet()) { return false; } resultSet = new HiveQueryResultSet.Builder().setClient(client).setSessionHandle(sessHandle) .setStmtHandle(stmtHandle).setMaxRows(maxRows).setFetchSize(fetchSize) .setScrollable(isScrollableResultset) .build(); return true; }
if (!stmtHandle.isHasResultSet()) { return false; }
public boolean execute(String sql) throws SQLException { if (isClosed) { throw new SQLException("Can't execute after statement has been closed"); } try { closeClientOperation(); TExecuteStatementReq execReq = new TExecuteStatementReq(sessHandle, sql); execReq.setConfOverlay(sessConf); TExecuteStatementResp execResp = client.ExecuteStatement(execReq); if (execResp.getStatus().getStatusCode().equals(TStatusCode.STILL_EXECUTING_STATUS)) { warningChain = Utils.addWarning(warningChain, new SQLWarning("Query execuing asynchronously")); } else { Utils.verifySuccessWithInfo(execResp.getStatus()); } stmtHandle = execResp.getOperationHandle(); } catch (SQLException eS) { throw eS; } catch (Exception ex) { throw new SQLException(ex.toString(), "08S01", ex); } if (!stmtHandle.isHasResultSet()) { // Poll until the query has completed one way or another. DML queries will not return a result // set, but we should not return from this method until the query has completed to avoid // racing with possible subsequent session shutdown, or queries that depend on the results // materialised here. TGetOperationStatusReq statusReq = new TGetOperationStatusReq(stmtHandle); boolean requestComplete = false; while (!requestComplete) { try { TGetOperationStatusResp statusResp = client.GetOperationStatus(statusReq); Utils.verifySuccessWithInfo(statusResp.getStatus()); if (statusResp.isSetOperationState()) { switch (statusResp.getOperationState()) { case CLOSED_STATE: case FINISHED_STATE: return false; case CANCELED_STATE: // 01000 -> warning throw new SQLException("Query was cancelled", "01000"); case ERROR_STATE: // HY000 -> general error throw new SQLException("Query failed", "HY000"); case UKNOW