From 371c8ce796d6f1df2522bfb030f4694b84b4c91c Mon Sep 17 00:00:00 2001 From: Vyacheslav Alipov Date: Thu, 1 Aug 2013 14:43:04 +0000 Subject: [PATCH] fixed getRequiredColumns, getSelectSampleBlock, aliases dict and originalNestedName [#CONV-7967] --- dbms/src/Interpreters/ExpressionAnalyzer.cpp | 28 ++++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/dbms/src/Interpreters/ExpressionAnalyzer.cpp b/dbms/src/Interpreters/ExpressionAnalyzer.cpp index 3596a1dc3a5..a6c20d1c583 100644 --- a/dbms/src/Interpreters/ExpressionAnalyzer.cpp +++ b/dbms/src/Interpreters/ExpressionAnalyzer.cpp @@ -134,16 +134,16 @@ String ExpressionAnalyzer::getOriginalNestedName(const String & name) { if (select_query && select_query->array_join_identifier) { - String aliased_nested_table = select_query->array_join_identifier->getAlias(); - String nested_table = select_query->array_join_identifier->getColumnName(); + String nested_table_name = select_query->array_join_identifier->getColumnName(); + String nested_table_alias = select_query->array_join_identifier->getAlias(); - if (name == aliased_nested_table) - return nested_table; + if (name == nested_table_alias) + return nested_table_name; - if (DataTypeNested::extractNestedTableName(name) == aliased_nested_table) + if (DataTypeNested::extractNestedTableName(name) == nested_table_alias) { String nested_column = DataTypeNested::extractNestedColumnName(name); - return DataTypeNested::concatenateNestedName(nested_table, nested_column); + return DataTypeNested::concatenateNestedName(nested_table_name, nested_column); } } return name; @@ -152,6 +152,10 @@ String ExpressionAnalyzer::getOriginalNestedName(const String & name) void ExpressionAnalyzer::createAliasesDict(ASTPtr & ast) { + if (ASTIdentifier * node = dynamic_cast(&*ast)) + if (node->kind == ASTIdentifier::ArrayJoin) + return; + /// Обход снизу-вверх. Не опускаемся в подзапросы. for (ASTs::iterator it = ast->children.begin(); it != ast->children.end(); ++it) if (!dynamic_cast(&**it)) @@ -603,7 +607,9 @@ void ExpressionAnalyzer::addMultipleArrayJoinAction(ExpressionActions & actions) if (nested_column == nested_table_name || (nested_table == nested_table_name && array_joined_columns.count(nested_column))) { added_columns = true; - String array_joined_name = DataTypeNested::concatenateNestedName(nested_table_alias, nested_column); + String array_joined_name = nested_column == nested_table_name + ? nested_table_alias + : DataTypeNested::concatenateNestedName(nested_table_alias, nested_column); actions.add(ExpressionActions::Action::copyColumn(*it, array_joined_name)); } } @@ -1075,6 +1081,7 @@ Block ExpressionAnalyzer::getSelectSampleBlock() assertSelect(); ExpressionActions temp_actions(aggregated_columns, settings); + addMultipleArrayJoinAction(temp_actions); NamesWithAliases result_columns; ASTs asts = select_query->select_expression_list->children; @@ -1213,7 +1220,12 @@ void ExpressionAnalyzer::getRequiredColumnsImpl(ASTPtr ast, NamesSet & required_ if (ASTIdentifier * node = dynamic_cast(&*ast)) { if (node->kind == ASTIdentifier::Column && !ignored_names.count(node->name)) - required_columns.insert(node->name); + { + if (isArrayJoinedColumnName(node->name)) + required_columns.insert(getOriginalNestedName(node->name)); + else + required_columns.insert(node->name); + } return; }