Parses query options into a normalized key/value object.
| 691 | |
| 692 | // Parses query options into a normalized key/value object. |
| 693 | Value QueryProfileToolAccessor::GetQueryOptions(Document::AllocatorType& alloc) const { |
| 694 | Value obj(rapidjson::kObjectType); |
| 695 | const Value* summary = GetSummaryPtr(); |
| 696 | if (summary == nullptr) return obj; |
| 697 | static const vector<const char*> option_keys = { |
| 698 | "Query Options (set by configuration)", |
| 699 | "Query Options (set by configuration and planner)"}; |
| 700 | for (const auto* option_key : option_keys) { |
| 701 | if (!summary->HasMember(option_key) || !(*summary)[option_key].IsString()) continue; |
| 702 | const Value& options_value = (*summary)[option_key]; |
| 703 | const string_view options( |
| 704 | options_value.GetString(), options_value.GetStringLength()); |
| 705 | size_t item_start = 0; |
| 706 | while (item_start < options.size()) { |
| 707 | const size_t comma = options.find(',', item_start); |
| 708 | const size_t item_end = comma == string_view::npos ? options.size() : comma; |
| 709 | string_view option = options.substr(item_start, item_end - item_start); |
| 710 | item_start = comma == string_view::npos ? options.size() : comma + 1; |
| 711 | if (option.empty()) continue; |
| 712 | |
| 713 | const size_t eq = option.find('='); |
| 714 | if (eq == string_view::npos) continue; |
| 715 | const string_view key = TrimWhiteSpace(option.substr(0, eq)); |
| 716 | const string_view value = TrimWhiteSpace(option.substr(eq + 1)); |
| 717 | if (key.empty()) continue; |
| 718 | |
| 719 | Value key_json(rapidjson::kStringType); |
| 720 | key_json.SetString( |
| 721 | key.data(), static_cast<rapidjson::SizeType>(key.size()), alloc); |
| 722 | if (obj.HasMember(key_json)) { |
| 723 | obj[key_json].SetString( |
| 724 | value.data(), static_cast<rapidjson::SizeType>(value.size()), alloc); |
| 725 | } else { |
| 726 | obj.AddMember( |
| 727 | MakeJsonString(key, alloc), |
| 728 | MakeJsonString(value, alloc), alloc); |
| 729 | } |
| 730 | } |
| 731 | } |
| 732 | return obj; |
| 733 | } |
| 734 | |
| 735 | // Returns the list of queried tables from Summary metadata. |
| 736 | Value QueryProfileToolAccessor::GetTablesQueried(Document::AllocatorType& alloc) const { |
no test coverage detected