diff --git a/src/Interpreters/AnyInputOptimize.cpp b/src/Interpreters/AnyInputOptimize.cpp index 13246fd8172..1b31ea4024b 100644 --- a/src/Interpreters/AnyInputOptimize.cpp +++ b/src/Interpreters/AnyInputOptimize.cpp @@ -71,10 +71,13 @@ void AnyInputMatcher::visit(ASTPtr & current_ast, Data data) && function_argument && function_argument->as()) { auto name = function_node->name; + auto alias = function_node->alias; + ///cut any or anyLast if (!function_argument->as()->arguments->children.empty()) { current_ast = function_argument->clone(); + current_ast->setAlias(alias); for (size_t i = 0; i < current_ast->as()->arguments->children.size(); ++i) changeAllIdentifiers(current_ast, i, name); } diff --git a/tests/queries/0_stateless/01398_any_with_alias.reference b/tests/queries/0_stateless/01398_any_with_alias.reference new file mode 100644 index 00000000000..4f8e72ef29c --- /dev/null +++ b/tests/queries/0_stateless/01398_any_with_alias.reference @@ -0,0 +1,8 @@ +"n" +0 +SELECT any(number) * any(number) AS n +FROM numbers(100) +"n" +0,0 +SELECT (any(number), any(number) * 2) AS n +FROM numbers(100) diff --git a/tests/queries/0_stateless/01398_any_with_alias.sql b/tests/queries/0_stateless/01398_any_with_alias.sql new file mode 100644 index 00000000000..32e67f3f4b6 --- /dev/null +++ b/tests/queries/0_stateless/01398_any_with_alias.sql @@ -0,0 +1,5 @@ +SELECT any(number * number) AS n FROM numbers(100) FORMAT CSVWithNames; +EXPLAIN SYNTAX SELECT any(number * number) AS n FROM numbers(100); + +SELECT any((number, number * 2)) as n FROM numbers(100) FORMAT CSVWithNames; +EXPLAIN SYNTAX SELECT any((number, number * 2)) as n FROM numbers(100);