Make sure to update table_join children properly

This commit is contained in:
Raúl Marín 2024-11-04 20:11:33 +01:00
parent 157e1695d5
commit b4a3f6d370
3 changed files with 15 additions and 2 deletions

View File

@ -48,9 +48,15 @@ ASTPtr JoinNode::toASTTableJoin() const
auto join_expression_ast = children[join_expression_child_index]->toAST(); auto join_expression_ast = children[join_expression_child_index]->toAST();
if (is_using_join_expression) if (is_using_join_expression)
join_ast->using_expression_list = std::move(join_expression_ast); {
join_ast->using_expression_list = join_expression_ast;
join_ast->children.push_back(join_ast->using_expression_list);
}
else else
join_ast->on_expression = std::move(join_expression_ast); {
join_ast->on_expression = join_expression_ast;
join_ast->children.push_back(join_ast->on_expression);
}
} }
return join_ast; return join_ast;

View File

@ -161,7 +161,13 @@ void QueryNormalizer::visit(ASTTablesInSelectQueryElement & node, const ASTPtr &
{ {
auto & join = node.table_join->as<ASTTableJoin &>(); auto & join = node.table_join->as<ASTTableJoin &>();
if (join.on_expression) if (join.on_expression)
{
ASTPtr original_on_expression = join.on_expression;
visit(join.on_expression, data); visit(join.on_expression, data);
if (join.on_expression != original_on_expression)
join.children = { join.on_expression };
}
} }
} }

View File

@ -245,6 +245,7 @@ namespace
table_join->strictness = JoinStrictness::Semi; table_join->strictness = JoinStrictness::Semi;
table_join->on_expression = makeASTFunction("equals", makeASTColumn(data_table_id, TimeSeriesColumnNames::ID), makeASTColumn(tags_table_id, TimeSeriesColumnNames::ID)); table_join->on_expression = makeASTFunction("equals", makeASTColumn(data_table_id, TimeSeriesColumnNames::ID), makeASTColumn(tags_table_id, TimeSeriesColumnNames::ID));
table_join->children.push_back(table_join->on_expression);
table->table_join = table_join; table->table_join = table_join;
auto table_exp = std::make_shared<ASTTableExpression>(); auto table_exp = std::make_shared<ASTTableExpression>();