From 709043314659a73a03c3ddd8b90299644d992e17 Mon Sep 17 00:00:00 2001 From: feiniaofeiafei <53502832+feiniaofeiafei@users.noreply.github.com> Date: Fri, 26 Jul 2024 10:25:39 +0800 Subject: [PATCH] [Fix](nereids) fix normalize repeat alias rewrite (#38166) Induced by #34196. In NormalizeRepeat, when NormalizeToSlot is called, aggregate function parameters, grouping scalar function parameters, and all expressions in grouping sets (including columns and column aliases) are pushed down to the lower-level project output. In the previous PR #34196, the context was split into two, but the two contexts were not consistent. It is possible that the triplets in one context save (id, c1, id as c1), and the triplets in the other context save (id, id, id). This causes id as c1 to be pushed down, but there is a reference to id in the upper-level LogicalRepeat, which causes the slot to be not found. This pr has been modified. If the same slot in the projection column has different aliases, for example, select id as c1, id, id as c3, grouping(id) from table1 group by grouping sets((id, value2),(id)); then id as c1 (using the first alias) will be pushed down to the project. In both the LogicalRepeat operator and the LogicalAggregate operator, c1 is referenced as the input slot, and id and c3 will not be used as input slots. before NormalizeRepeat: LogicalResultSink[32] ( outputExprs=[c1#3, id#0, c3#4, __grouping_3#5] ) +--LogicalRepeat ( groupingSets=[[id#0, value2#2], [id#0]], outputExpressions=[id#0 AS `c1`#3, id#0, id#0 AS `c3`#4, Grouping(id#0) AS `Grouping(id)`#5] ) +--LogicalOlapScan (qualified=table1) After NormalizeRepeat: LogicalResultSink[33] (outputExprs=[c1#3, id#0, c3#4, __grouping_3#5]) +--LogicalAggregate[30] (groupByExpr=[c1#3, value2#2, GROUPING_ID#7, GROUPING_PREFIX_c1#6 originExpression=Grouping(c1#3)], outputExpr=[c1#3, c1#3 AS `id`#0, c1#3 AS `c3`#4, GROUPING_PREFIX_c1#6 originExpression=Grouping(c1#3) AS `GROUPING_PREFIX_c1`#5], hasRepeat=true ) +--LogicalRepeat (groupingSets=[[c1#3, value2#2], [c1#3]], outputExpressions=[c1#3, value2#2, GROUPING_ID#7, GROUPING_PREFIX_c1#6 originExpression=Grouping(c1#3)] ) +--LogicalProject[28] (projects=[id#0 AS `c1`#3, value2#2]) +--LogicalOlapScan (qualified=table1) --- .../rules/analysis/NormalizeRepeat.java | 46 +- .../doris/nereids/util/ExpressionUtils.java | 9 + .../grouping_sets/grouping_alias_test.out | 531 ++++++++++++++++++ .../grouping_sets/grouping_alias_test.groovy | 111 ++++ 4 files changed, 684 insertions(+), 13 deletions(-) create mode 100644 regression-test/data/nereids_rules_p0/grouping_sets/grouping_alias_test.out create mode 100644 regression-test/suites/nereids_rules_p0/grouping_sets/grouping_alias_test.groovy diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/NormalizeRepeat.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/NormalizeRepeat.java index 6465b81da30539..96ea874f259422 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/NormalizeRepeat.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/NormalizeRepeat.java @@ -51,6 +51,8 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -133,9 +135,9 @@ private static LogicalAggregate normalizeRepeat(LogicalRepeat repeat Set needToSlotsGroupingExpr = collectNeedToSlotGroupingExpr(repeat); NormalizeToSlotContext groupingExprContext = buildContext(repeat, needToSlotsGroupingExpr); Map groupingExprMap = groupingExprContext.getNormalizeToSlotMap(); - Set existsAlias = getExistsAlias(repeat, groupingExprMap); + Map existsAlias = getExistsAlias(repeat, groupingExprMap); Set needToSlotsArgs = collectNeedToSlotArgsOfGroupingScalarFuncAndAggFunc(repeat); - NormalizeToSlotContext argsContext = NormalizeToSlotContext.buildContext(existsAlias, needToSlotsArgs); + NormalizeToSlotContext argsContext = buildContextWithAlias(repeat, existsAlias, needToSlotsArgs); // normalize grouping sets to List> ImmutableList.Builder> normalizedGroupingSetBuilder = ImmutableList.builder(); @@ -254,12 +256,27 @@ private static Plan pushDownProject(Set pushedExprs, Plan origi /** buildContext */ public static NormalizeToSlotContext buildContext(Repeat repeat, Set sourceExpressions) { - Set aliases = ExpressionUtils.collect(repeat.getOutputExpressions(), Alias.class::isInstance); + List aliases = ExpressionUtils.collectToList(repeat.getOutputExpressions(), Alias.class::isInstance); Map existsAliasMap = Maps.newLinkedHashMap(); for (Alias existsAlias : aliases) { + if (existsAliasMap.containsKey(existsAlias.child())) { + continue; + } existsAliasMap.put(existsAlias.child(), existsAlias); } + Map normalizeToSlotMap = Maps.newLinkedHashMap(); + for (Expression expression : sourceExpressions) { + Optional pushDownTriplet = + toGroupingSetExpressionPushDownTriplet(expression, existsAliasMap.get(expression)); + pushDownTriplet.ifPresent( + normalizeToSlotTriplet -> normalizeToSlotMap.put(expression, normalizeToSlotTriplet)); + } + return new NormalizeToSlotContext(normalizeToSlotMap); + } + + private static NormalizeToSlotContext buildContextWithAlias(Repeat repeat, + Map existsAliasMap, Collection sourceExpressions) { List groupingSetExpressions = ExpressionUtils.flatExpressions(repeat.getGroupingSets()); Map normalizeToSlotMap = Maps.newLinkedHashMap(); for (Expression expression : sourceExpressions) { @@ -270,10 +287,8 @@ public static NormalizeToSlotContext buildContext(Repeat repeat, pushDownTriplet = Optional.of( NormalizeToSlotTriplet.toTriplet(expression, existsAliasMap.get(expression))); } - - if (pushDownTriplet.isPresent()) { - normalizeToSlotMap.put(expression, pushDownTriplet.get()); - } + pushDownTriplet.ifPresent( + normalizeToSlotTriplet -> normalizeToSlotMap.put(expression, normalizeToSlotTriplet)); } return new NormalizeToSlotContext(normalizeToSlotMap); } @@ -304,18 +319,23 @@ private static Expression normalizeAggFuncChildrenAndGroupingScalarFunc(Normaliz } } - private static Set getExistsAlias(LogicalRepeat repeat, + private static Map getExistsAlias(LogicalRepeat repeat, Map groupingExprMap) { - Set existsAlias = Sets.newHashSet(); - Set aliases = ExpressionUtils.collect(repeat.getOutputExpressions(), Alias.class::isInstance); - existsAlias.addAll(aliases); + Map existsAliasMap = new HashMap<>(); for (NormalizeToSlotTriplet triplet : groupingExprMap.values()) { if (triplet.pushedExpr instanceof Alias) { Alias alias = (Alias) triplet.pushedExpr; - existsAlias.add(alias); + existsAliasMap.put(triplet.originExpr, alias); + } + } + List aliases = ExpressionUtils.collectToList(repeat.getOutputExpressions(), Alias.class::isInstance); + for (Alias alias : aliases) { + if (existsAliasMap.containsKey(alias.child())) { + continue; } + existsAliasMap.put(alias.child(), alias); } - return existsAlias; + return existsAliasMap; } /* diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/ExpressionUtils.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/ExpressionUtils.java index b19d4b096e27d4..2f238b68757613 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/ExpressionUtils.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/ExpressionUtils.java @@ -699,6 +699,15 @@ public static Set collect(Collection expressions, return set.build(); } + public static List collectToList(Collection expressions, + Predicate> predicate) { + ImmutableList.Builder list = ImmutableList.builder(); + for (Expression expr : expressions) { + list.addAll(expr.collectToList(predicate)); + } + return list.build(); + } + /** * extract uniform slot for the given predicate, such as a = 1 and b = 2 */ diff --git a/regression-test/data/nereids_rules_p0/grouping_sets/grouping_alias_test.out b/regression-test/data/nereids_rules_p0/grouping_sets/grouping_alias_test.out new file mode 100644 index 00000000000000..27a165a1256003 --- /dev/null +++ b/regression-test/data/nereids_rules_p0/grouping_sets/grouping_alias_test.out @@ -0,0 +1,531 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !alias -- +1 +1 +2 +2 +3 +3 +4 +4 + +-- !alias_grouping_scalar -- +1 0 +1 0 +2 0 +2 0 +3 0 +3 0 +4 0 +4 0 + +-- !alias_agg_func -- +1 1 +1 1 +2 2 +2 2 +3 3 +3 3 +4 4 +4 4 + +-- !same_column_different_alias -- +1 1 +1 1 +2 2 +2 2 +3 3 +3 3 +4 4 +4 4 + +-- !same_column_different_alias_grouping_scalar -- +1 1 0 +1 1 0 +2 2 0 +2 2 0 +3 3 0 +3 3 0 +4 4 0 +4 4 0 + +-- !same_column_different_alias_agg_func -- +1 1 1 +1 1 1 +2 2 2 +2 2 2 +3 3 3 +3 3 3 +4 4 4 +4 4 4 + +-- !same_column_different_alias_3_column -- +1 1 1 +1 1 1 +2 2 2 +2 2 2 +3 3 3 +3 3 3 +4 4 4 +4 4 4 + +-- !same_column_different_alias_3_column_grouping_scalar -- +1 1 1 0 +1 1 1 0 +2 2 2 0 +2 2 2 0 +3 3 3 0 +3 3 3 0 +4 4 4 0 +4 4 4 0 + +-- !same_column_different_alias_3_column_agg_func -- +1 1 1 1 +1 1 1 1 +2 2 2 2 +2 2 2 2 +3 3 3 3 +3 3 3 3 +4 4 4 4 +4 4 4 4 + +-- !same_column_one_has_alias_the_other_do_not -- +1 1 +1 1 +2 2 +2 2 +3 3 +3 3 +4 4 +4 4 + +-- !same_column_one_has_alias_the_other_do_not_grouping_scalar -- +1 1 0 +1 1 0 +2 2 0 +2 2 0 +3 3 0 +3 3 0 +4 4 0 +4 4 0 + +-- !same_column_one_has_alias_the_other_do_not_agg_func -- +1 1 1 +1 1 1 +2 2 2 +2 2 2 +3 3 3 +3 3 3 +4 4 4 +4 4 4 + +-- !alias_expr -- +2 +2 +3 +3 +4 +4 +5 +5 + +-- !alias_grouping_scalar_expr -- +2 0 +2 0 +3 0 +3 0 +4 0 +4 0 +5 0 +5 0 + +-- !alias_agg_func_expr -- +2 2 +2 2 +3 3 +3 3 +4 4 +4 4 +5 5 +5 5 + +-- !same_expr_different_alias -- +2 2 +2 2 +3 3 +3 3 +4 4 +4 4 +5 5 +5 5 + +-- !same_expr_different_alias_grouping_scalar -- +2 2 0 +2 2 0 +3 3 0 +3 3 0 +4 4 0 +4 4 0 +5 5 0 +5 5 0 + +-- !same_expr_different_alias_agg_func -- +2 2 2 +2 2 2 +3 3 3 +3 3 3 +4 4 4 +4 4 4 +5 5 5 +5 5 5 + +-- !same_expr_different_alias_3_expr -- +2 2 2 +2 2 2 +3 3 3 +3 3 3 +4 4 4 +4 4 4 +5 5 5 +5 5 5 + +-- !same_expr_different_alias_3_expr_grouping_scalar -- +2 2 2 0 +2 2 2 0 +3 3 3 0 +3 3 3 0 +4 4 4 0 +4 4 4 0 +5 5 5 0 +5 5 5 0 + +-- !same_expr_different_alias_3_expr_agg_func -- +2 2 2 2 +2 2 2 2 +3 3 3 3 +3 3 3 3 +4 4 4 4 +4 4 4 4 +5 5 5 5 +5 5 5 5 + +-- !same_expr_one_has_alias_the_other_do_not -- +2 2 +2 2 +3 3 +3 3 +4 4 +4 4 +5 5 +5 5 + +-- !same_expr_one_has_alias_the_other_do_not_grouping_scalar -- +2 2 0 +2 2 0 +3 3 0 +3 3 0 +4 4 0 +4 4 0 +5 5 0 +5 5 0 + +-- !same_expr_one_has_alias_the_other_do_not_agg_func -- +2 2 2 +2 2 2 +3 3 3 +3 3 3 +4 4 4 +4 4 4 +5 5 5 +5 5 5 + +-- !expr_without_alias -- +2 +2 +3 +3 +4 +4 +5 +5 + +-- !expr_without_alias_grouping_scalar -- +2 0 +2 0 +3 0 +3 0 +4 0 +4 0 +5 0 +5 0 + +-- !expr_without_alias_agg_func -- +2 2 +2 2 +3 3 +3 3 +4 4 +4 4 +5 5 +5 5 + +-- !same_expr_without_alias -- +2 2 +2 2 +3 3 +3 3 +4 4 +4 4 +5 5 +5 5 + +-- !same_expr_without_alias_grouping_scalar -- +2 2 0 +2 2 0 +3 3 0 +3 3 0 +4 4 0 +4 4 0 +5 5 0 +5 5 0 + +-- !same_expr_without_alias_agg_func -- +2 2 2 +2 2 2 +3 3 3 +3 3 3 +4 4 4 +4 4 4 +5 5 5 +5 5 5 + +-- !expr_with_or_without_alias_3_expr -- +2 2 2 +2 2 2 +3 3 3 +3 3 3 +4 4 4 +4 4 4 +5 5 5 +5 5 5 + +-- !expr_with_or_without_alias_3_expr_grouping_scalar -- +2 2 2 0 +2 2 2 0 +3 3 3 0 +3 3 3 0 +4 4 4 0 +4 4 4 0 +5 5 5 0 +5 5 5 0 + +-- !expr_with_or_without_alias_3_expr_agg_func -- +2 2 2 2 +2 2 2 2 +3 3 3 3 +3 3 3 3 +4 4 4 4 +4 4 4 4 +5 5 5 5 +5 5 5 5 + +-- !alias_in_grouping -- +1 +1 +2 +2 +3 +3 +4 +4 + +-- !alias_grouping_scalar_in_grouping -- +1 0 +1 0 +2 0 +2 0 +3 0 +3 0 +4 0 +4 0 + +-- !alias_agg_func_in_grouping -- +1 1 +1 1 +2 2 +2 2 +3 3 +3 3 +4 4 +4 4 + +-- !same_column_different_alias_in_grouping -- +1 1 +1 1 +2 2 +2 2 +3 3 +3 3 +4 4 +4 4 + +-- !same_column_different_alias_grouping_scalar_in_grouping -- +1 1 0 +1 1 0 +2 2 0 +2 2 0 +3 3 0 +3 3 0 +4 4 0 +4 4 0 + +-- !same_column_different_alias_agg_func_in_grouping -- +1 1 1 +1 1 1 +2 2 2 +2 2 2 +3 3 3 +3 3 3 +4 4 4 +4 4 4 + +-- !same_column_different_alias_in_grouping_3_column -- +1 1 1 +1 1 1 +2 2 2 +2 2 2 +3 3 3 +3 3 3 +4 4 4 +4 4 4 + +-- !same_column_different_alias_in_grouping_3_column_grouping_scalar -- +1 1 1 0 +1 1 1 0 +2 2 2 0 +2 2 2 0 +3 3 3 0 +3 3 3 0 +4 4 4 0 +4 4 4 0 + +-- !same_column_different_alias_in_grouping_3_column_agg_func -- +1 1 1 1 +1 1 1 1 +2 2 2 2 +2 2 2 2 +3 3 3 3 +3 3 3 3 +4 4 4 4 +4 4 4 4 + +-- !same_column_one_has_alias_in_grouping_the_other_do_not -- +1 1 +1 1 +2 2 +2 2 +3 3 +3 3 +4 4 +4 4 + +-- !same_column_one_has_alias_in_grouping_the_other_do_not_grouping_scalar -- +1 1 0 +1 1 0 +2 2 0 +2 2 0 +3 3 0 +3 3 0 +4 4 0 +4 4 0 + +-- !same_column_one_has_alias_in_grouping_the_other_do_not_agg_func -- +1 1 1 +1 1 1 +2 2 2 +2 2 2 +3 3 3 +3 3 3 +4 4 4 +4 4 4 + +-- !alias_in_grouping_expr -- +2 +2 +3 +3 +4 +4 +5 +5 + +-- !alias_in_grouping_grouping_scalar_expr -- +2 0 +2 0 +3 0 +3 0 +4 0 +4 0 +5 0 +5 0 + +-- !alias_in_grouping_agg_func_expr -- +2 2 +2 2 +3 3 +3 3 +4 4 +4 4 +5 5 +5 5 + +-- !same_expr_different_alias_in_grouping -- +2 2 +2 2 +3 3 +3 3 +4 4 +4 4 +5 5 +5 5 + +-- !same_expr_different_alias_in_grouping_grouping_scalar -- +2 2 0 +2 2 0 +3 3 0 +3 3 0 +4 4 0 +4 4 0 +5 5 0 +5 5 0 + +-- !same_expr_different_alias_in_grouping_agg_func -- +2 2 2 +2 2 2 +3 3 3 +3 3 3 +4 4 4 +4 4 4 +5 5 5 +5 5 5 + +-- !same_expr_different_alias_in_grouping_3_expr -- +2 2 2 0 2 +2 2 2 0 2 +3 3 3 0 3 +3 3 3 0 3 +4 4 4 0 4 +4 4 4 0 4 +5 5 5 0 5 +5 5 5 0 5 + +-- !same_expr_one_has_alias_in_grouping_the_other_do_not -- +2 2 0 2 +2 2 0 2 +3 3 0 3 +3 3 0 3 +4 4 0 4 +4 4 0 4 +5 5 0 5 +5 5 0 5 + diff --git a/regression-test/suites/nereids_rules_p0/grouping_sets/grouping_alias_test.groovy b/regression-test/suites/nereids_rules_p0/grouping_sets/grouping_alias_test.groovy new file mode 100644 index 00000000000000..ee1b9b998b4f7f --- /dev/null +++ b/regression-test/suites/nereids_rules_p0/grouping_sets/grouping_alias_test.groovy @@ -0,0 +1,111 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite("grouping_alias_test"){ + sql "SET enable_nereids_planner=true" + sql "SET enable_fallback_to_original_planner=false" + sql"drop table if exists grouping_alias_test_t" + sql """ + CREATE TABLE grouping_alias_test_t ( + id INT, + value1 INT, + value2 VARCHAR(50) + )distributed by hash(id) properties("replication_num"="1"); + """ + sql """ + INSERT INTO grouping_alias_test_t (id, value1, value2) VALUES + (1, 10, 'A'), + (2, 20, 'B'), + (3, 30, 'C'), + (4, 40, 'D'); + """ + + qt_alias "select id as c1 from grouping_alias_test_t group by grouping sets((id,value2),(id)) order by 1;" + qt_alias_grouping_scalar "select id as c1, grouping(id) from grouping_alias_test_t group by grouping sets((id,value2),(id)) order by 1,2;" + qt_alias_agg_func "select id as c1, sum(id) from grouping_alias_test_t group by grouping sets((id,value2),(id)) order by 1,2;" + + qt_same_column_different_alias "select id as c1, id as c2 from grouping_alias_test_t group by grouping sets((id,value2),(id)) order by 1,2;" + qt_same_column_different_alias_grouping_scalar "select id as c1, id as c2, grouping(id) from grouping_alias_test_t group by grouping sets((id,value2),(id)) order by 1,2,3;" + qt_same_column_different_alias_agg_func "select id as c1, id as c2 , sum(id) from grouping_alias_test_t group by grouping sets((id,value2),(id)) order by 1,2,3;" + + qt_same_column_different_alias_3_column "select id as c1, id as c2, id as c3 from grouping_alias_test_t group by grouping sets((id,value2),(id)) order by 1,2,3;" + qt_same_column_different_alias_3_column_grouping_scalar "select id as c1, id as c2, id as c3,grouping(id) from grouping_alias_test_t group by grouping sets((id,value2),(id)) order by 1,2,3,4;" + qt_same_column_different_alias_3_column_agg_func "select id as c1, id as c2, id as c3 ,sum(id) from grouping_alias_test_t group by grouping sets((id,value2),(id)) order by 1,2,3,4;" + + qt_same_column_one_has_alias_the_other_do_not "select id , id as c2 from grouping_alias_test_t group by grouping sets((id,value2),(id)) order by 1,2;" + qt_same_column_one_has_alias_the_other_do_not_grouping_scalar "select id , id as c2 ,grouping(id) from grouping_alias_test_t group by grouping sets((id,value2),(id)) order by 1,2,3;" + qt_same_column_one_has_alias_the_other_do_not_agg_func "select id , id as c2 ,sum(id) from grouping_alias_test_t group by grouping sets((id,value2),(id)) order by 1,2,3;" + + qt_alias_expr "select id+1 as c1 from grouping_alias_test_t group by grouping sets((id+1,value2),(id+1)) order by 1;" + qt_alias_grouping_scalar_expr "select id+1 as c1, grouping(id+1) from grouping_alias_test_t group by grouping sets((id+1,value2),(id+1)) order by 1,2;" + qt_alias_agg_func_expr "select id+1 as c1, sum(id+1) from grouping_alias_test_t group by grouping sets((id+1,value2),(id+1)) order by 1,2;" + + qt_same_expr_different_alias "select id+1 as c1, id+1 as c2 from grouping_alias_test_t group by grouping sets((id+1,value2),(id+1)) order by 1,2;" + qt_same_expr_different_alias_grouping_scalar "select id+1 as c1, id+1 as c2, grouping(id+1) from grouping_alias_test_t group by grouping sets((id+1,value2),(id+1)) order by 1,2,3;" + qt_same_expr_different_alias_agg_func "select id+1 as c1, id+1 as c2 , sum(id+1) from grouping_alias_test_t group by grouping sets((id+1,value2),(id+1)) order by 1,2,3;" + + qt_same_expr_different_alias_3_expr "select id+1 as c1, id+1 as c2, id+1 as c3 from grouping_alias_test_t group by grouping sets((id+1,value2),(id+1)) order by 1,2,3;" + qt_same_expr_different_alias_3_expr_grouping_scalar "select id+1 as c1, id+1 as c2, id+1 as c3,grouping(id+1) from grouping_alias_test_t group by grouping sets((id+1,value2),(id+1)) order by 1,2,3,4;" + qt_same_expr_different_alias_3_expr_agg_func "select id+1 as c1, id+1 as c2, id+1 as c3 ,sum(id+1) from grouping_alias_test_t group by grouping sets((id+1,value2),(id+1)) order by 1,2,3,4;" + + qt_same_expr_one_has_alias_the_other_do_not "select id+1 , id+1 as c2 from grouping_alias_test_t group by grouping sets((id+1,value2),(id+1)) order by 1,2;" + qt_same_expr_one_has_alias_the_other_do_not_grouping_scalar "select id+1 , id+1 as c2 ,grouping(id+1) from grouping_alias_test_t group by grouping sets((id+1,value2),(id+1)) order by 1,2,3;" + qt_same_expr_one_has_alias_the_other_do_not_agg_func "select id+1 , id+1 as c2 ,sum(id+1) from grouping_alias_test_t group by grouping sets((id+1,value2),(id+1)) order by 1,2,3;" + + qt_expr_without_alias "select id+1 from grouping_alias_test_t group by grouping sets((id+1,value2),(id+1)) order by 1;" + qt_expr_without_alias_grouping_scalar "select id+1, grouping(id+1) from grouping_alias_test_t group by grouping sets((id+1,value2),(id+1)) order by 1,2;" + qt_expr_without_alias_agg_func "select id+1, sum(id+1) from grouping_alias_test_t group by grouping sets((id+1,value2),(id+1)) order by 1,2;" + + qt_same_expr_without_alias "select id+1, id+1 from grouping_alias_test_t group by grouping sets((id+1,value2),(id+1)) order by 1,2;" + qt_same_expr_without_alias_grouping_scalar "select id+1, id+1, grouping(id+1) from grouping_alias_test_t group by grouping sets((id+1,value2),(id+1)) order by 1,2,3;" + qt_same_expr_without_alias_agg_func "select id+1, id+1, sum(id+1) from grouping_alias_test_t group by grouping sets((id+1,value2),(id+1)) order by 1,2,3;" + + qt_expr_with_or_without_alias_3_expr "select id+1, id+1, id+1 as c1 from grouping_alias_test_t group by grouping sets((id+1,value2),(id+1)) order by 1,2,3;" + qt_expr_with_or_without_alias_3_expr_grouping_scalar "select id+1, id+1, id+1 as c3,grouping(id+1) from grouping_alias_test_t group by grouping sets((id+1,value2),(id+1)) order by 1,2,3,4;" + qt_expr_with_or_without_alias_3_expr_agg_func "select id+1 as c1, id+1, id+1,sum(id+1) from grouping_alias_test_t group by grouping sets((id+1,value2),(id+1)) order by 1,2,3,4;" + + qt_alias_in_grouping "select id as c1 from grouping_alias_test_t group by grouping sets((c1,value2),(id)) order by 1;" + qt_alias_grouping_scalar_in_grouping "select id as c1, grouping(id) from grouping_alias_test_t group by grouping sets((c1,value2),(id)) order by 1,2;" + qt_alias_agg_func_in_grouping "select id as c1, sum(id) from grouping_alias_test_t group by grouping sets((id,value2),(c1)) order by 1,2;" + + // TODO: The query result of the following example is different from pg. It needs to be modified later. + qt_same_column_different_alias_in_grouping "select id as c1, id as c2 from grouping_alias_test_t group by grouping sets((c1,value2),(c2)) order by 1,2;" + qt_same_column_different_alias_grouping_scalar_in_grouping "select id as c1, id as c2, grouping(id) from grouping_alias_test_t group by grouping sets((c1,value2),(c2)) order by 1,2,3;" + qt_same_column_different_alias_agg_func_in_grouping "select id as c1, id as c2 , sum(id) from grouping_alias_test_t group by grouping sets((c1,value2),(c2)) order by 1,2,3;" + + qt_same_column_different_alias_in_grouping_3_column "select id as c1, id as c2, id as c3 from grouping_alias_test_t group by grouping sets((c1,value2),(c2,c3)) order by 1,2,3;" + qt_same_column_different_alias_in_grouping_3_column_grouping_scalar "select id as c1, id as c2, id as c3,grouping(id) from grouping_alias_test_t group by grouping sets((c1,value2),(c2,c3)) order by 1,2,3,4;" + qt_same_column_different_alias_in_grouping_3_column_agg_func "select id as c1, id as c2, id as c3 ,sum(id) from grouping_alias_test_t group by grouping sets((c1,value2),(c2,c3)) order by 1,2,3,4;" + + qt_same_column_one_has_alias_in_grouping_the_other_do_not "select id , id as c2 from grouping_alias_test_t group by grouping sets((id,value2),(c2)) order by 1,2;" + qt_same_column_one_has_alias_in_grouping_the_other_do_not_grouping_scalar "select id , id as c2 ,grouping(id) from grouping_alias_test_t group by grouping sets((id,value2),(c2)) order by 1,2,3;" + qt_same_column_one_has_alias_in_grouping_the_other_do_not_agg_func "select id , id as c2 ,sum(id) from grouping_alias_test_t group by grouping sets((id,value2),(c2)) order by 1,2,3;" + + qt_alias_in_grouping_expr "select id+1 as c1 from grouping_alias_test_t group by grouping sets((id+1,value2),(c1)) order by 1;" + qt_alias_in_grouping_grouping_scalar_expr "select id+1 as c1, grouping(id+1) from grouping_alias_test_t group by grouping sets((id+1,value2),(c1)) order by 1,2;" + qt_alias_in_grouping_agg_func_expr "select id+1 as c1, sum(id+1) from grouping_alias_test_t group by grouping sets((id+1,value2),(c1)) order by 1,2;" + + qt_same_expr_different_alias_in_grouping "select id+1 as c1, id+1 as c2 from grouping_alias_test_t group by grouping sets((c1,value2),(id+1,c2)) order by 1,2;" + qt_same_expr_different_alias_in_grouping_grouping_scalar "select id+1 as c1, id+1 as c2, grouping(id+1) from grouping_alias_test_t group by grouping sets((c1,value2),(id+1,c2)) order by 1,2,3;" + qt_same_expr_different_alias_in_grouping_agg_func "select id+1 as c1, id+1 as c2 , sum(id+1) from grouping_alias_test_t group by grouping sets((c1,value2),(c2)) order by 1,2,3;" + + qt_same_expr_different_alias_in_grouping_3_expr "select id+1 as c1, id+1 as c2, id+1 as c3,grouping(id+1),sum(id+1) as c3 from grouping_alias_test_t group by grouping sets((c1,value2),(c2,c3,id+1)) order by 1,2,3;" + + qt_same_expr_one_has_alias_in_grouping_the_other_do_not "select id+1 , id+1 as c2,grouping(id+1),sum(id+1) from grouping_alias_test_t group by grouping sets((c2,value2),(id+1)) order by 1,2;" + + +} \ No newline at end of file