| 1041 | } |
| 1042 | |
| 1043 | void ImpalaHttpHandler::CatalogHandler(const Webserver::WebRequest& req, |
| 1044 | Document* document) { |
| 1045 | TGetDbsResult get_dbs_result; |
| 1046 | Status status = server_->exec_env_->frontend()->GetDbs(NULL, NULL, &get_dbs_result); |
| 1047 | if (!status.ok()) { |
| 1048 | Value error(status.GetDetail(), document->GetAllocator()); |
| 1049 | document->AddMember("error", error, document->GetAllocator()); |
| 1050 | return; |
| 1051 | } |
| 1052 | |
| 1053 | TGetCatalogInfoResult catalog_info; |
| 1054 | status = server_->exec_env_->frontend()->GetCatalogInfo(&catalog_info); |
| 1055 | |
| 1056 | if (!status.ok()) { |
| 1057 | Value error(status.GetDetail().c_str(), document->GetAllocator()); |
| 1058 | document->AddMember("error", error, document->GetAllocator()); |
| 1059 | return; |
| 1060 | } |
| 1061 | |
| 1062 | Value info(kArrayType); |
| 1063 | for (const string& str: catalog_info.info) { |
| 1064 | Value str_val(str.c_str(), document->GetAllocator()); |
| 1065 | Value value(kObjectType); |
| 1066 | value.AddMember("value", str_val, document->GetAllocator()); |
| 1067 | info.PushBack(value, document->GetAllocator()); |
| 1068 | } |
| 1069 | document->AddMember("info", info, document->GetAllocator()); |
| 1070 | |
| 1071 | Value databases(kArrayType); |
| 1072 | for (const TDatabase& db: get_dbs_result.dbs) { |
| 1073 | Value database(kObjectType); |
| 1074 | Value str(db.db_name, document->GetAllocator()); |
| 1075 | database.AddMember("name", str, document->GetAllocator()); |
| 1076 | |
| 1077 | TGetTablesResult get_table_results; |
| 1078 | status = server_->exec_env_->frontend()->GetTableNames( |
| 1079 | db.db_name, nullptr, nullptr, &get_table_results); |
| 1080 | if (!status.ok()) { |
| 1081 | Value error(status.GetDetail(), document->GetAllocator()); |
| 1082 | database.AddMember("error", error, document->GetAllocator()); |
| 1083 | continue; |
| 1084 | } |
| 1085 | |
| 1086 | Value table_array(kArrayType); |
| 1087 | for (const string& table: get_table_results.tables) { |
| 1088 | Value table_obj(kObjectType); |
| 1089 | if(!FLAGS_use_local_catalog){ |
| 1090 | // Creates hyperlinks for /catalog_object. This is disabled in local catalog mode |
| 1091 | Value fq_name(Substitute("$0.$1", db.db_name, table), |
| 1092 | document->GetAllocator()); |
| 1093 | table_obj.AddMember("fqtn", fq_name, document->GetAllocator()); |
| 1094 | } |
| 1095 | Value table_name(table, document->GetAllocator()); |
| 1096 | table_obj.AddMember("name", table_name, document->GetAllocator()); |
| 1097 | table_array.PushBack(table_obj, document->GetAllocator()); |
| 1098 | } |
| 1099 | database.AddMember("num_tables", table_array.Size(), document->GetAllocator()); |
| 1100 | database.AddMember("tables", table_array, document->GetAllocator()); |
nothing calls this directly
no test coverage detected