| 584 | } |
| 585 | |
| 586 | void ImpalaHttpHandler::QueryStateToJson(const QueryStateRecord& record, |
| 587 | Value* value, Document* document, bool inflight) { |
| 588 | Value user(record.effective_user, document->GetAllocator()); |
| 589 | value->AddMember("effective_user", user, document->GetAllocator()); |
| 590 | |
| 591 | Value default_db(record.default_db, document->GetAllocator()); |
| 592 | value->AddMember("default_db", default_db, document->GetAllocator()); |
| 593 | |
| 594 | // Redact the query string |
| 595 | std::string tmp_stmt = RedactCopy(record.stmt); |
| 596 | if(FLAGS_query_stmt_size && tmp_stmt.length() > FLAGS_query_stmt_size) { |
| 597 | tmp_stmt = tmp_stmt.substr(0, FLAGS_query_stmt_size).append("..."); |
| 598 | } |
| 599 | Value stmt(tmp_stmt, document->GetAllocator()); |
| 600 | value->AddMember("stmt", stmt, document->GetAllocator()); |
| 601 | |
| 602 | Value stmt_type(_TStmtType_VALUES_TO_NAMES.find(record.stmt_type)->second, |
| 603 | document->GetAllocator()); |
| 604 | value->AddMember("stmt_type", stmt_type, document->GetAllocator()); |
| 605 | |
| 606 | Value start_time(ToStringFromUnixMicros(record.start_time_us, |
| 607 | TimePrecision::Millisecond), document->GetAllocator()); |
| 608 | value->AddMember("start_time", start_time, document->GetAllocator()); |
| 609 | |
| 610 | Value end_time(ToStringFromUnixMicros(record.end_time_us, |
| 611 | TimePrecision::Millisecond), document->GetAllocator()); |
| 612 | value->AddMember("end_time", end_time, document->GetAllocator()); |
| 613 | |
| 614 | vector<string>::const_iterator it = std::find(record.event_sequence.labels.begin(), |
| 615 | record.event_sequence.labels.end(), |
| 616 | Coordinator::PROFILE_EVENT_LABEL_FIRST_ROW_FETCHED); |
| 617 | int64_t first_fetch_ns = 0; |
| 618 | if (it != record.event_sequence.labels.end()) { |
| 619 | first_fetch_ns = record.event_sequence.timestamps[it |
| 620 | - record.event_sequence.labels.begin()]; |
| 621 | } |
| 622 | const string& printed_first_fetch = PrettyPrinter::Print(first_fetch_ns, |
| 623 | TUnit::TIME_NS); |
| 624 | Value val_first_fetch(printed_first_fetch, document->GetAllocator()); |
| 625 | value->AddMember("first_fetch", val_first_fetch, document->GetAllocator()); |
| 626 | |
| 627 | const string& printed_client_fetch_duration = PrettyPrinter::Print( |
| 628 | record.client_fetch_wait_time_ns, TUnit::TIME_NS); |
| 629 | Value val_client_fetch_duration(printed_client_fetch_duration, |
| 630 | document->GetAllocator()); |
| 631 | value->AddMember("client_fetch_duration", val_client_fetch_duration, |
| 632 | document->GetAllocator()); |
| 633 | |
| 634 | // record.end_time_us might still be zero if the query is not yet done |
| 635 | // Use the current Unix time in that case. Note that the duration can be |
| 636 | // negative if a system clock reset happened after the query was initiated. |
| 637 | int64_t end_time_us = record.end_time_us > 0LL ? record.end_time_us : UnixMicros(); |
| 638 | int64_t duration_us = end_time_us - record.start_time_us; |
| 639 | const string& printed_duration = PrettyPrinter::Print(duration_us * NANOS_PER_MICRO, |
| 640 | TUnit::TIME_NS); |
| 641 | Value val_duration(printed_duration, document->GetAllocator()); |
| 642 | value->AddMember("duration", val_duration, document->GetAllocator()); |
| 643 |
nothing calls this directly
no test coverage detected