MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / buildQueryTreeDistributed

Function buildQueryTreeDistributed

src/Storages/StorageDistributed.cpp:865–954  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

863}
864
865QueryTreeNodePtr buildQueryTreeDistributed(SelectQueryInfo & query_info,
866 const StorageSnapshotPtr & distributed_storage_snapshot,
867 const StorageID & remote_storage_id,
868 const ASTPtr & remote_table_function)
869{
870 auto & planner_context = query_info.planner_context;
871 const auto & query_context = planner_context->getQueryContext();
872
873 std::optional<TableExpressionModifiers> table_expression_modifiers;
874
875 if (auto * query_info_table_node = query_info.table_expression->as<TableNode>())
876 table_expression_modifiers = query_info_table_node->getTableExpressionModifiers();
877 else if (auto * query_info_table_function_node = query_info.table_expression->as<TableFunctionNode>())
878 table_expression_modifiers = query_info_table_function_node->getTableExpressionModifiers();
879
880 QueryTreeNodePtr replacement_table_expression;
881
882 if (remote_table_function)
883 {
884 auto remote_table_function_query_tree = buildQueryTree(remote_table_function, query_context);
885 auto & remote_table_function_node = remote_table_function_query_tree->as<FunctionNode &>();
886
887 auto table_function_node = std::make_shared<TableFunctionNode>(remote_table_function_node.getFunctionName());
888 table_function_node->getArgumentsNode() = remote_table_function_node.getArgumentsNode();
889
890 if (table_expression_modifiers)
891 table_function_node->setTableExpressionModifiers(*table_expression_modifiers);
892
893 /// Subquery in table function `view` may reference tables that don't exist on the initiator.
894 if (table_function_node->getTableFunctionName() == "view")
895 {
896 auto get_column_options = GetColumnsOptions(GetColumnsOptions::All).withVirtuals(VirtualsKind::All, VirtualsMaterializationPlace::All);
897 auto column_names_and_types = distributed_storage_snapshot->getColumns(get_column_options);
898
899 StorageID fake_storage_id = StorageID::createEmpty();
900 if (auto * table_node = query_info.table_expression->as<TableNode>())
901 fake_storage_id = table_node->getStorage()->getStorageID();
902 else if (auto * original_table_function_node = query_info.table_expression->as<TableFunctionNode>())
903 fake_storage_id = original_table_function_node->getStorage()->getStorageID();
904
905 auto storage = std::make_shared<StorageDummy>(fake_storage_id, ColumnsDescription{column_names_and_types});
906
907 table_function_node->resolve({}, std::move(storage), query_context, /*unresolved_arguments_indexes_=*/{ 0 });
908 }
909 else
910 {
911 QueryAnalysisPass query_analysis_pass;
912 QueryTreeNodePtr node = table_function_node;
913 query_analysis_pass.run(node, query_context);
914 }
915
916 replacement_table_expression = std::move(table_function_node);
917 }
918 else
919 {
920 auto get_column_options = GetColumnsOptions(GetColumnsOptions::All).withVirtuals(VirtualsKind::All, VirtualsMaterializationPlace::All);
921
922 auto column_names_and_types = distributed_storage_snapshot->getColumns(get_column_options);

Callers 1

readMethod · 0.85

Calls 15

buildQueryTreeFunction · 0.85
createEmptyFunction · 0.85
buildQueryTreeForShardFunction · 0.85
withVirtualsMethod · 0.80
cloneAndReplaceMethod · 0.80
GetColumnsOptionsClass · 0.70
getQueryContextMethod · 0.45
getFunctionNameMethod · 0.45
getColumnsMethod · 0.45

Tested by

no test coverage detected