def get_log(self, query_stmt): execute_statement_resp = self.execute_statement(query_stmt) # Fetch results to make sure errors are generated. Errors are only guaranteed to be # seen by the coordinator after FetchResults() returns eos. has_more_results = True while has_more_results: fetch_results_req = TCLIService.TFetchResultsReq() fetch_results_req.operationHandle = execute_statement_resp.operationHandle fetch_results_req.maxRows = 100 fetch_results_resp = self.hs2_client.FetchResults( fetch_results_req) TestHS2.check_response(fetch_results_resp) has_more_results = fetch_results_resp.hasMoreRows # Test that secret is validated. invalid_get_log_req = TCLIService.TGetLogReq() invalid_get_log_req.operationHandle = create_op_handle_without_secret( execute_statement_resp.operationHandle) TestHS2.check_invalid_query( self.hs2_client.GetLog(invalid_get_log_req), expect_legacy_err=True) get_log_req = TCLIService.TGetLogReq() get_log_req.operationHandle = execute_statement_resp.operationHandle get_log_resp = self.hs2_client.GetLog(get_log_req) TestHS2.check_response(get_log_resp) return get_log_resp.log
def test_invalid_secret(self): """Test that the FetchResults, GetResultSetMetadata and CloseOperation APIs validate the session secret.""" execute_req = TCLIService.TExecuteStatementReq( self.session_handle, "select 'something something'") execute_resp = self.hs2_client.ExecuteStatement(execute_req) HS2TestSuite.check_response(execute_resp) good_handle = execute_resp.operationHandle bad_handle = create_op_handle_without_secret(good_handle) # Fetching and closing operations with an invalid handle should be a no-op, i.e. # the later operations with the good handle should succeed. HS2TestSuite.check_invalid_query(self.hs2_client.FetchResults( TCLIService.TFetchResultsReq(operationHandle=bad_handle, maxRows=1024)), expect_legacy_err=True) HS2TestSuite.check_invalid_query(self.hs2_client.GetResultSetMetadata( TCLIService.TGetResultSetMetadataReq(operationHandle=bad_handle)), expect_legacy_err=True) HS2TestSuite.check_invalid_query(self.hs2_client.CloseOperation( TCLIService.TCloseOperationReq(operationHandle=bad_handle)), expect_legacy_err=True) # Ensure that the good handle remained valid. HS2TestSuite.check_response(self.hs2_client.FetchResults( TCLIService.TFetchResultsReq(operationHandle=good_handle, maxRows=1024))) HS2TestSuite.check_response(self.hs2_client.GetResultSetMetadata( TCLIService.TGetResultSetMetadataReq(operationHandle=good_handle))) HS2TestSuite.check_response(self.hs2_client.CloseOperation( TCLIService.TCloseOperationReq(operationHandle=good_handle)))
def test_get_operation_status(self): """Tests that GetOperationStatus returns a valid result for a running query""" statement = "SELECT COUNT(*) FROM functional.alltypes" execute_statement_resp = self.execute_statement(statement) get_operation_status_resp = \ self.get_operation_status(execute_statement_resp.operationHandle) TestHS2.check_response(get_operation_status_resp) # If ExecuteStatement() has completed but the results haven't been fetched yet, the # query must have reached either PENDING or RUNNING or FINISHED. assert get_operation_status_resp.operationState in \ [TCLIService.TOperationState.PENDING_STATE, TCLIService.TOperationState.RUNNING_STATE, TCLIService.TOperationState.FINISHED_STATE] fetch_results_req = TCLIService.TFetchResultsReq() fetch_results_req.operationHandle = execute_statement_resp.operationHandle fetch_results_req.maxRows = 100 fetch_results_resp = self.hs2_client.FetchResults(fetch_results_req) get_operation_status_resp = \ self.get_operation_status(execute_statement_resp.operationHandle) TestHS2.check_response(get_operation_status_resp) # After fetching the results, the query must be in state FINISHED. assert get_operation_status_resp.operationState == \ TCLIService.TOperationState.FINISHED_STATE # Validate that the operation secret is checked. TestHS2.check_invalid_query(self.get_operation_status( create_op_handle_without_secret( execute_statement_resp.operationHandle)), expect_legacy_err=True) close_operation_req = TCLIService.TCloseOperationReq() close_operation_req.operationHandle = execute_statement_resp.operationHandle TestHS2.check_response( self.hs2_client.CloseOperation(close_operation_req)) get_operation_status_resp = \ self.get_operation_status(execute_statement_resp.operationHandle) # GetOperationState should return 'Invalid or unknown query handle' if the query has # been closed. TestHS2.check_response(get_operation_status_resp, \ TCLIService.TStatusCode.ERROR_STATUS)