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

Method buildJoinTree

src/Analyzer/QueryTreeBuilder.cpp:929–1216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

927}
928
929QueryTreeNodePtr QueryTreeBuilder::buildJoinTree(bool is_subquery, const ASTSelectQuery & select_query, const ContextPtr & context) const
930{
931 const auto & tables_in_select_query = select_query.tables();
932 if (!tables_in_select_query)
933 {
934 /** If no table is specified in SELECT query,
935 * if 'implicit_table_at_top_level' is set, we substitute it as a table,
936 * otherwise, we substitute the system.one table: SELECT * FROM system.one;
937 */
938 if (!is_subquery)
939 {
940 String implicit_table = context->getSettingsRef()[Setting::implicit_table_at_top_level];
941 if (!implicit_table.empty())
942 return std::make_shared<IdentifierNode>(Identifier(implicit_table));
943 }
944
945 return std::make_shared<IdentifierNode>(Identifier("system.one"));
946 }
947
948 auto & tables = tables_in_select_query->as<ASTTablesInSelectQuery &>();
949
950 QueryTreeNodes table_expressions;
951
952 for (const auto & table_element_untyped : tables.children)
953 {
954 const auto & table_element = table_element_untyped->as<ASTTablesInSelectQueryElement &>();
955
956 if (table_element.table_expression)
957 {
958 auto & table_expression = table_element.table_expression->as<ASTTableExpression &>();
959 std::optional<TableExpressionModifiers> table_expression_modifiers;
960
961 if (table_expression.final || table_expression.sample_size || table_expression.stream_settings)
962 {
963 bool has_final = table_expression.final;
964 std::optional<TableExpressionModifiers::Rational> sample_size_ratio;
965 std::optional<TableExpressionModifiers::Rational> sample_offset_ratio;
966 std::optional<TableExpressionModifiers::StreamSettings> stream_settings;
967
968 if (table_expression.sample_size)
969 {
970 auto & ast_sample_size_ratio = table_expression.sample_size->as<ASTSampleRatio &>();
971 sample_size_ratio = ast_sample_size_ratio.ratio;
972
973 if (table_expression.sample_offset)
974 {
975 auto & ast_sample_offset_ratio = table_expression.sample_offset->as<ASTSampleRatio &>();
976 sample_offset_ratio = ast_sample_offset_ratio.ratio;
977 }
978 }
979
980 if (table_expression.stream_settings)
981 {
982 stream_settings = TableExpressionModifiers::StreamSettings{};
983 const auto & ast_stream_settings = table_expression.stream_settings->as<ASTStreamSettings &>();
984 if (ast_stream_settings.settings.cursor_tree.has_value())
985 stream_settings->cursor_tree = buildCursorTree(ast_stream_settings.settings.cursor_tree.value());
986 }

Callers

nothing calls this directly

Calls 15

buildCursorTreeFunction · 0.85
tablesMethod · 0.80
setOriginalASTMethod · 0.80
aliasesMethod · 0.80
getNodesMethod · 0.80
appendTableMethod · 0.80
setNaturalMethod · 0.80
IdentifierClass · 0.70
ExceptionClass · 0.50

Tested by

no test coverage detected