| 1918 | } |
| 1919 | |
| 1920 | String PlanPrinter::jsonMetaData( |
| 1921 | ASTPtr & query, AnalysisPtr analysis, ContextMutablePtr context, QueryPlanPtr & plan, const QueryMetadataSettings & settings) |
| 1922 | { |
| 1923 | Poco::JSON::Object::Ptr metadata_json = new Poco::JSON::Object(true); |
| 1924 | |
| 1925 | Poco::JSON::Array table_and_columns_info; |
| 1926 | const auto & used_columns_map = analysis->getUsedColumns(); |
| 1927 | for (const auto & [table_ast, storage_analysis] : analysis->getStorages()) |
| 1928 | { |
| 1929 | Poco::JSON::Object::Ptr used_table_info = new Poco::JSON::Object(true); |
| 1930 | |
| 1931 | used_table_info->set("Database", storage_analysis.database); |
| 1932 | used_table_info->set("Table", storage_analysis.table); |
| 1933 | |
| 1934 | Poco::JSON::Array used_columns; |
| 1935 | if (auto it = used_columns_map.find(storage_analysis.storage->getStorageID()); it != used_columns_map.end()) |
| 1936 | { |
| 1937 | for (const auto & column : it->second) |
| 1938 | used_columns.add(column); |
| 1939 | } |
| 1940 | |
| 1941 | used_table_info->set("Columns", used_columns); |
| 1942 | |
| 1943 | table_and_columns_info.add(used_table_info); |
| 1944 | } |
| 1945 | metadata_json->set("UsedTablesInfo", table_and_columns_info); |
| 1946 | |
| 1947 | |
| 1948 | Poco::JSON::Array used_functions; |
| 1949 | //get used functions |
| 1950 | for (const auto & func_name : analysis->getUsedFunctions()) |
| 1951 | used_functions.add(func_name); |
| 1952 | |
| 1953 | metadata_json->set("UsedFunctions", used_functions); |
| 1954 | |
| 1955 | // get settings |
| 1956 | Poco::JSON::Object::Ptr query_used_settings = new Poco::JSON::Object(true); |
| 1957 | SettingsChanges settings_changes = InterpreterSetQuery::extractSettingsFromQuery(query, context); |
| 1958 | for (const auto & setting : settings_changes) |
| 1959 | query_used_settings->set(setting.name, setting.value.toString()); |
| 1960 | metadata_json->set("UsedSettings", query_used_settings); |
| 1961 | |
| 1962 | Poco::JSON::Array output_descs; |
| 1963 | ASTPtr & select_ast = query; |
| 1964 | if (auto * insert_query = query->as<ASTInsertQuery>()) |
| 1965 | select_ast = insert_query->select; |
| 1966 | |
| 1967 | if (analysis->hasOutputDescription(*select_ast)) |
| 1968 | { |
| 1969 | for (const auto & desc : analysis->getOutputDescription(*select_ast)) |
| 1970 | output_descs.add(desc.name); |
| 1971 | } |
| 1972 | metadata_json->set("OutputDescriptions", output_descs); |
| 1973 | |
| 1974 | // get InsertInfo |
| 1975 | Poco::JSON::Object::Ptr insert_table_info = new Poco::JSON::Object(true); |
| 1976 | if (analysis->getInsert()) |
| 1977 | { |
nothing calls this directly
no test coverage detected