| 632 | } |
| 633 | |
| 634 | Status ImpalaServer::FetchInternal(const TUniqueId& query_id, const bool start_over, |
| 635 | const int32_t fetch_size, beeswax::Results* query_results) { |
| 636 | bool timed_out = false; |
| 637 | int64_t block_on_wait_time_us = 0; |
| 638 | QueryHandle query_handle; |
| 639 | RETURN_IF_ERROR( |
| 640 | WaitForResults(query_id, &query_handle, &block_on_wait_time_us, &timed_out)); |
| 641 | if (timed_out) { |
| 642 | query_results->__set_ready(false); |
| 643 | query_results->__set_has_more(true); |
| 644 | query_results->__isset.columns = false; |
| 645 | query_results->__isset.data = false; |
| 646 | return Status::OK(); |
| 647 | } |
| 648 | |
| 649 | int64_t start_time_ns = MonotonicNanos(); |
| 650 | lock_guard<mutex> frl(*query_handle->fetch_rows_lock()); |
| 651 | lock_guard<mutex> l(*query_handle->lock()); |
| 652 | int64_t lock_wait_time_ns = MonotonicNanos() - start_time_ns; |
| 653 | query_handle->AddClientFetchLockWaitTime(lock_wait_time_ns); |
| 654 | |
| 655 | if (query_handle->num_rows_fetched() == 0) { |
| 656 | query_handle->set_fetched_rows(); |
| 657 | } |
| 658 | |
| 659 | // Check for cancellation or an error. |
| 660 | RETURN_IF_ERROR(query_handle->query_status()); |
| 661 | |
| 662 | // ODBC-190: set Beeswax's Results.columns to work around bug ODBC-190; |
| 663 | // TODO: remove the block of code when ODBC-190 is resolved. |
| 664 | const TResultSetMetadata* result_metadata = query_handle->result_metadata(); |
| 665 | query_results->columns.resize(result_metadata->columns.size()); |
| 666 | for (int i = 0; i < result_metadata->columns.size(); ++i) { |
| 667 | // TODO: As of today, the ODBC driver does not support boolean and timestamp data |
| 668 | // type but it should. This is tracked by ODBC-189. We should verify that our |
| 669 | // boolean and timestamp type are correctly recognized when ODBC-189 is closed. |
| 670 | // TODO: Handle complex types. |
| 671 | const TColumnType& type = result_metadata->columns[i].columnType; |
| 672 | query_results->columns[i] = ColumnTypeToBeeswaxTypeString(type); |
| 673 | } |
| 674 | query_results->__isset.columns = true; |
| 675 | |
| 676 | // Results are always ready because we're blocking. |
| 677 | query_results->__set_ready(true); |
| 678 | // It's likely that ODBC doesn't care about start_row, but Hue needs it. For Hue, |
| 679 | // start_row starts from zero, not one. |
| 680 | query_results->__set_start_row(query_handle->num_rows_fetched()); |
| 681 | |
| 682 | Status fetch_rows_status; |
| 683 | query_results->data.clear(); |
| 684 | if (!query_handle->eos()) { |
| 685 | scoped_ptr<QueryResultSet> result_set(QueryResultSet::CreateAsciiQueryResultSet( |
| 686 | *query_handle->result_metadata(), &query_results->data, |
| 687 | query_handle->query_options().stringify_map_keys)); |
| 688 | fetch_rows_status = |
| 689 | query_handle->FetchRows(fetch_size, result_set.get(), block_on_wait_time_us); |
| 690 | } |
| 691 | query_results->__set_has_more(!query_handle->eos()); |
nothing calls this directly
no test coverage detected