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

Function tryMakeUsingColumnASTWithAlias

src/Analyzer/JoinNode.cpp:62–94  ·  view source on GitHub ↗

There is a special workaround for the case when ARRAY JOIN alias is used in USING statement. Example: ... ARRAY JOIN arr AS dummy INNER JOIN system.one USING (dummy); In case of ARRAY JOIN, the column is renamed, so the query tree will look like: JOIN EXPRESSION LIST COLUMN id: 16, column_name: dummy EXPRESSION LIST COLUMN id: 18, column_name: __array_join_exp_1 COLUMN id: 19, column_name: dummy

Source from the content-addressed store, hash-verified

60///
61/// See 03448_analyzer_array_join_alias_in_join_using_bug
62static ASTPtr tryMakeUsingColumnASTWithAlias(const QueryTreeNodePtr & node)
63{
64 const auto * column_node = node->as<ColumnNode>();
65 if (!column_node)
66 return nullptr;
67
68 const auto & expr = column_node->getExpression();
69 if (!expr)
70 return nullptr;
71
72 const auto * expr_list_node = expr->as<ListNode>();
73 if (!expr_list_node)
74 return nullptr;
75
76 if (expr_list_node->getNodes().size() != 2)
77 return nullptr;
78
79 const auto * lhs_column_node = expr_list_node->getNodes()[0]->as<ColumnNode>();
80 const auto * rhs_column_node = expr_list_node->getNodes()[1]->as<ColumnNode>();
81 if (!lhs_column_node || !rhs_column_node)
82 return nullptr;
83
84 /// If USING column resolved from projection, keep its name
85 if (lhs_column_node->hasExpression())
86 return nullptr;
87
88 if (lhs_column_node->getColumnName() == rhs_column_node->getColumnName())
89 return nullptr;
90
91 auto node_ast = make_intrusive<ASTIdentifier>(lhs_column_node->getColumnName());
92 node_ast->setAlias(rhs_column_node->getColumnName());
93 return node_ast;
94}
95
96static ASTPtr makeUsingAST(const QueryTreeNodePtr & node)
97{

Callers 1

makeUsingASTFunction · 0.85

Calls 6

getNodesMethod · 0.80
hasExpressionMethod · 0.80
getExpressionMethod · 0.45
sizeMethod · 0.45
getColumnNameMethod · 0.45
setAliasMethod · 0.45

Tested by

no test coverage detected