From 3725cf4aa7a9aa022b11d08b2f8e4f7f0dd70283 Mon Sep 17 00:00:00 2001 From: kssenii Date: Wed, 7 Dec 2022 11:26:32 +0100 Subject: [PATCH] Better --- src/Interpreters/TreeRewriter.cpp | 41 +++++++++++++++---------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/Interpreters/TreeRewriter.cpp b/src/Interpreters/TreeRewriter.cpp index 6b019609dd9..805392a9430 100644 --- a/src/Interpreters/TreeRewriter.cpp +++ b/src/Interpreters/TreeRewriter.cpp @@ -329,31 +329,27 @@ using ExistsExpressionVisitor = InDepthNodeVisitorgetSettingsRef().enable_positional_arguments) + if (select_query.groupBy()) { - if (select_query.groupBy()) + for (auto & expr : select_query.groupBy()->children) + replaceForPositionalArguments(expr, &select_query, ASTSelectQuery::Expression::GROUP_BY); + } + if (select_query.orderBy()) + { + for (auto & expr : select_query.orderBy()->children) { - for (auto & expr : select_query.groupBy()->children) - replaceForPositionalArguments(expr, &select_query, ASTSelectQuery::Expression::GROUP_BY); - } - if (select_query.orderBy()) - { - for (auto & expr : select_query.orderBy()->children) - { - auto & elem = assert_cast(*expr).children.at(0); - replaceForPositionalArguments(elem, &select_query, ASTSelectQuery::Expression::ORDER_BY); - } - } - if (select_query.limitBy()) - { - for (auto & expr : select_query.limitBy()->children) - replaceForPositionalArguments(expr, &select_query, ASTSelectQuery::Expression::LIMIT_BY); + auto & elem = assert_cast(*expr).children.at(0); + replaceForPositionalArguments(elem, &select_query, ASTSelectQuery::Expression::ORDER_BY); } } + if (select_query.limitBy()) + { + for (auto & expr : select_query.limitBy()->children) + replaceForPositionalArguments(expr, &select_query, ASTSelectQuery::Expression::LIMIT_BY); + } } }; @@ -1508,8 +1504,11 @@ void TreeRewriter::normalize( ExistsExpressionVisitor::Data exists; ExistsExpressionVisitor(exists).visit(query); - ReplacePositionalArgumentsVisitor::Data data_replace_positional_arguments{context_}; - ReplacePositionalArgumentsVisitor(data_replace_positional_arguments).visit(query); + if (context_->getSettingsRef().enable_positional_arguments) + { + ReplacePositionalArgumentsVisitor::Data data_replace_positional_arguments; + ReplacePositionalArgumentsVisitor(data_replace_positional_arguments).visit(query); + } if (settings.transform_null_in) {