Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix join duplicate table error #39

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions utils/local-engine/Parser/SerializedPlanParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,32 @@ DB::QueryPlanPtr SerializedPlanParser::parseJoin(substrait::JoinRel join, DB::Qu
}
table_join->addDisjunct();

table_join->setColumnsFromJoinedTable(right->getCurrentDataStream().header.getNamesAndTypesList());

NameSet left_columns_set;
for (const auto& col : left->getCurrentDataStream().header.getNames())
{
left_columns_set.emplace(col);
}
table_join->deduplicateAndQualifyColumnNames(left_columns_set, getUniqueName("right") + ".");
// fix right table key duplicate
NamesWithAliases right_table_alias;
for (size_t idx=0; idx < table_join->columnsFromJoinedTable().size() ; idx++)
{
auto origin_name = right->getCurrentDataStream().header.getByPosition(idx).name;
auto dedup_name = table_join->columnsFromJoinedTable().getNames().at(idx);
if (origin_name != dedup_name)
{
right_table_alias.emplace_back(NameWithAlias(origin_name, dedup_name));
}
}
if (!right_table_alias.empty())
{
ActionsDAGPtr project = std::make_shared<ActionsDAG>(right->getCurrentDataStream().header.getNamesAndTypesList());
project->addAliases(right_table_alias);
QueryPlanStepPtr project_step = std::make_unique<ExpressionStep>(right->getCurrentDataStream(), project);
right->addStep(std::move(project_step));
}
// support multiple join key
bool multiple_keys = join.expression().scalar_function().args(0).has_scalar_function();
auto join_key_num = multiple_keys ? join.expression().scalar_function().args_size() : 1;
Expand All @@ -1148,7 +1174,7 @@ DB::QueryPlanPtr SerializedPlanParser::parseJoin(substrait::JoinRel join, DB::Qu
ASTPtr right_key = std::make_shared<ASTIdentifier>(right->getCurrentDataStream().header.getByPosition(right_key_idx).name);
table_join->addOnKeys(left_key, right_key);
}
table_join->setColumnsFromJoinedTable(right->getCurrentDataStream().header.getNamesAndTypesList());

for (const auto & column : table_join->columnsFromJoinedTable())
{
table_join->addJoinedColumn(column);
Expand All @@ -1175,7 +1201,7 @@ DB::QueryPlanPtr SerializedPlanParser::parseJoin(substrait::JoinRel join, DB::Qu
Names after_join_names;
auto left_names = left->getCurrentDataStream().header.getNames();
after_join_names.insert(after_join_names.end(), left_names.begin(), left_names.end());
auto right_name = right->getCurrentDataStream().header.getNames();
auto right_name = table_join->columnsFromJoinedTable().getNames();
after_join_names.insert(after_join_names.end(), right_name.begin(), right_name.end());

if (join_opt_info.is_broadcast)
Expand Down