| 1369 | } |
| 1370 | |
| 1371 | Status ClientRequestState::WaitInternal() { |
| 1372 | // Explain requests have already populated the result set. Nothing to do here. |
| 1373 | if (exec_request().stmt_type == TStmtType::EXPLAIN) { |
| 1374 | return Status::OK(); |
| 1375 | } |
| 1376 | |
| 1377 | // Wait until the query has passed through admission control and is either running or |
| 1378 | // cancelled or encountered an error. |
| 1379 | if (async_exec_thread_.get() != nullptr) async_exec_thread_->Join(); |
| 1380 | |
| 1381 | vector<ChildQuery*> child_queries; |
| 1382 | Status child_queries_status = child_query_executor_->WaitForAll(&child_queries); |
| 1383 | { |
| 1384 | lock_guard<mutex> l(lock_); |
| 1385 | RETURN_IF_ERROR(query_status_); |
| 1386 | RETURN_IF_ERROR(UpdateQueryStatus(child_queries_status)); |
| 1387 | } |
| 1388 | if (!child_queries.empty()) query_events_->MarkEvent("Child queries finished"); |
| 1389 | |
| 1390 | bool isCTAS = catalog_op_type() == TCatalogOpType::DDL |
| 1391 | && ddl_type() == TDdlType::CREATE_TABLE_AS_SELECT; |
| 1392 | |
| 1393 | if (GetCoordinator() != NULL) { |
| 1394 | Status status = GetCoordinator()->Wait(); |
| 1395 | if (UNLIKELY(!status.ok())) { |
| 1396 | if (InKuduTransaction()) AbortKuduTransaction(); |
| 1397 | return status; |
| 1398 | } |
| 1399 | RETURN_IF_ERROR(UpdateCatalog()); |
| 1400 | } else { |
| 1401 | // When the coordinator is not available for CTAS that requires a coordinator, check |
| 1402 | // further if the query has been cancelled. If so, return immediately as there will |
| 1403 | // be no query result available (IMPALA-11006). |
| 1404 | if (isCTAS) { |
| 1405 | RETURN_IF_CANCELLED(this); |
| 1406 | } |
| 1407 | } |
| 1408 | |
| 1409 | if (catalog_op_type() == TCatalogOpType::DDL && |
| 1410 | ddl_type() == TDdlType::COMPUTE_STATS && child_queries.size() > 0) { |
| 1411 | RETURN_IF_ERROR(UpdateTableAndColumnStats(child_queries)); |
| 1412 | } |
| 1413 | |
| 1414 | if (!returns_result_set()) { |
| 1415 | // Queries that do not return a result are finished at this point. This includes |
| 1416 | // DML operations. |
| 1417 | eos_.Store(true); |
| 1418 | } else if (isCTAS) { |
| 1419 | SetCreateTableAsSelectResultSet(); |
| 1420 | } |
| 1421 | return Status::OK(); |
| 1422 | } |
| 1423 | |
| 1424 | Status ClientRequestState::FetchRows(const int32_t max_rows, |
| 1425 | QueryResultSet* fetched_rows, int64_t block_on_wait_time_us) { |