From 3fd3884b321fff60d367fa166d481b429f7daa16 Mon Sep 17 00:00:00 2001 From: chertus Date: Wed, 6 Feb 2019 19:44:47 +0300 Subject: [PATCH] one more minor refactoring --- dbms/src/Interpreters/AnalyzedJoin.h | 9 ++++++++ dbms/src/Interpreters/SyntaxAnalyzer.cpp | 26 ++++++------------------ 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/dbms/src/Interpreters/AnalyzedJoin.h b/dbms/src/Interpreters/AnalyzedJoin.h index 396b92cefbd..e53363e8f73 100644 --- a/dbms/src/Interpreters/AnalyzedJoin.h +++ b/dbms/src/Interpreters/AnalyzedJoin.h @@ -61,6 +61,15 @@ struct AnalyzedJoin /// It's columns_from_joined_table without duplicate columns and possibly modified types. JoinedColumnsList available_joined_columns; + void addSimpleKey(const ASTPtr & ast) + { + key_names_left.push_back(ast->getColumnName()); + key_names_right.push_back(ast->getAliasOrColumnName()); + + key_asts_left.push_back(ast); + key_asts_right.push_back(ast); + } + ExpressionActionsPtr createJoinedBlockActions( const JoinedColumnsList & columns_added_by_join, /// Subset of available_joined_columns. const ASTSelectQuery * select_query_with_join, diff --git a/dbms/src/Interpreters/SyntaxAnalyzer.cpp b/dbms/src/Interpreters/SyntaxAnalyzer.cpp index fd61112d108..90ed9b6065b 100644 --- a/dbms/src/Interpreters/SyntaxAnalyzer.cpp +++ b/dbms/src/Interpreters/SyntaxAnalyzer.cpp @@ -612,30 +612,16 @@ void collectJoinedColumns(AnalyzedJoin & analyzed_join, const ASTSelectQuery * s const auto & table_expression = static_cast(*node->table_expression); DatabaseAndTableWithAlias joined_table_name(table_expression, context.getCurrentDatabase()); - auto add_name_to_join_keys = [&](Names & join_keys, ASTs & join_asts, const ASTPtr & ast, bool right_table) - { - String name; - if (right_table) - { - name = ast->getAliasOrColumnName(); - if (source_columns.count(name)) - name = joined_table_name.getQualifiedNamePrefix() + name; - } - else - name = ast->getColumnName(); - - join_keys.push_back(name); - join_asts.push_back(ast); - }; - if (table_join.using_expression_list) { auto & keys = typeid_cast(*table_join.using_expression_list); for (const auto & key : keys.children) - { - add_name_to_join_keys(analyzed_join.key_names_left, analyzed_join.key_asts_left, key, false); - add_name_to_join_keys(analyzed_join.key_names_right, analyzed_join.key_asts_right, key, true); - } + analyzed_join.addSimpleKey(key); + + /// @warning wrong qualification if the right key is an alias + for (auto & name : analyzed_join.key_names_right) + if (source_columns.count(name)) + name = joined_table_name.getQualifiedNamePrefix() + name; } else if (table_join.on_expression) collectJoinedColumnsFromJoinOnExpr(analyzed_join, select_query, source_columns, context);