You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2022/12/15 19:22:43 UTC

[doris] branch master updated: [fix](nereids) fix bug of expr rewrite and column prune rule of group by exprs (#15097)

This is an automated email from the ASF dual-hosted git repository.

morrysnow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 5e0d44ff25 [fix](nereids) fix bug of expr rewrite and column prune rule of group by exprs (#15097)
5e0d44ff25 is described below

commit 5e0d44ff25a06e6a0547ae3dc79d32b5aff675cf
Author: starocean999 <40...@users.noreply.github.com>
AuthorDate: Fri Dec 16 03:22:36 2022 +0800

    [fix](nereids) fix bug of expr rewrite and column prune rule of group by exprs (#15097)
---
 .../expression/rewrite/ExpressionRewrite.java      |   2 +-
 .../rewrite/logical/PruneAggChildColumns.java      |   2 +-
 .../doris/nereids/util/TypeCoercionUtils.java      |   3 +
 .../data/query_p0/keyword/order_group.out          | 167 +++++++++++----------
 .../suites/query_p0/keyword/order_group.groovy     |   6 +
 5 files changed, 95 insertions(+), 85 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rewrite/ExpressionRewrite.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rewrite/ExpressionRewrite.java
index acc433db52..951fed9ed9 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rewrite/ExpressionRewrite.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rewrite/ExpressionRewrite.java
@@ -115,7 +115,7 @@ public class ExpressionRewrite implements RewriteRuleFactory {
                 List<NamedExpression> outputExpressions = agg.getOutputExpressions();
                 List<NamedExpression> newOutputExpressions = outputExpressions.stream()
                         .map(expr -> (NamedExpression) rewriter.rewrite(expr)).collect(Collectors.toList());
-                if (outputExpressions.containsAll(newOutputExpressions)) {
+                if (outputExpressions.containsAll(newOutputExpressions) && groupByExprs.containsAll(newGroupByExprs)) {
                     return agg;
                 }
                 return new LogicalAggregate<>(newGroupByExprs, newOutputExpressions,
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/logical/PruneAggChildColumns.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/logical/PruneAggChildColumns.java
index 05047c7ad8..53667f1dec 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/logical/PruneAggChildColumns.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/logical/PruneAggChildColumns.java
@@ -56,7 +56,7 @@ public class PruneAggChildColumns extends OneRewriteRuleFactory {
     public Rule build() {
         return RuleType.COLUMN_PRUNE_AGGREGATION_CHILD.build(logicalAggregate().then(agg -> {
             List<Slot> childOutput = agg.child().getOutput();
-            if (isAggregateWithConstant(agg)) {
+            if (isAggregateWithConstant(agg) && agg.getGroupByExpressions().isEmpty()) {
                 Slot slot = ExpressionUtils.selectMinimumColumn(childOutput);
                 if (childOutput.size() == 1 && childOutput.get(0).equals(slot)) {
                     return agg;
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java
index d1cc520bbf..3700a204fa 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java
@@ -226,6 +226,9 @@ public class TypeCoercionUtils {
             } else if (left instanceof DateV2Type || right instanceof DateV2Type) {
                 tightestCommonType = DateV2Type.INSTANCE;
             }
+        } else if ((left instanceof DateLikeType && right instanceof IntegralType)
+                    || (right instanceof DateLikeType && left instanceof IntegralType)) {
+            tightestCommonType = BigIntType.INSTANCE;
         }
         return Optional.ofNullable(tightestCommonType);
     }
diff --git a/regression-test/data/query_p0/keyword/order_group.out b/regression-test/data/query_p0/keyword/order_group.out
index b3b3ceb32a..89177bcedf 100644
--- a/regression-test/data/query_p0/keyword/order_group.out
+++ b/regression-test/data/query_p0/keyword/order_group.out
@@ -63,17 +63,17 @@
 
 -- !orderBy5 --
 1	123.123
-2	1243.5
+2	1243.500
 3	24453.325
 
 -- !orderBy6 --
 1	123.123
-2	1243.5
+2	1243.500
 3	24453.325
 
 -- !orderBy7 --
 1	123.123
-2	1243.5
+2	1243.500
 3	24453.325
 
 -- !orderBy5 --
@@ -182,17 +182,17 @@
 1989	11011902
 
 -- !orderBy5 --
-1986	1243.5
+1986	1243.500
 1989	123.123
 1989	24453.325
 
 -- !orderBy6 --
-1986	1243.5
+1986	1243.500
 1989	123.123
 1989	24453.325
 
 -- !orderBy7 --
-1986	1243.5
+1986	1243.500
 1989	24453.325
 1989	123.123
 
@@ -303,16 +303,16 @@
 
 -- !orderBy5 --
 1001	123.123
-1001	1243.5
+1001	1243.500
 1002	24453.325
 
 -- !orderBy6 --
 1001	123.123
-1001	1243.5
+1001	1243.500
 1002	24453.325
 
 -- !orderBy7 --
-1001	1243.5
+1001	1243.500
 1001	123.123
 1002	24453.325
 
@@ -423,17 +423,17 @@
 
 -- !orderBy5 --
 11011902	123.123
-11011903	1243.5
+11011903	1243.500
 11011905	24453.325
 
 -- !orderBy6 --
 11011902	123.123
-11011903	1243.5
+11011903	1243.500
 11011905	24453.325
 
 -- !orderBy7 --
 11011902	123.123
-11011903	1243.5
+11011903	1243.500
 11011905	24453.325
 
 -- !orderBy5 --
@@ -498,122 +498,122 @@
 
 -- !orderBy5 --
 123.123	1
-1243.5	2
+1243.500	2
 24453.325	3
 
 -- !orderBy6 --
 123.123	1
-1243.5	2
+1243.500	2
 24453.325	3
 
 -- !orderBy7 --
 123.123	1
-1243.5	2
+1243.500	2
 24453.325	3
 
 -- !orderBy5 --
 123.123	1989
-1243.5	1986
+1243.500	1986
 24453.325	1989
 
 -- !orderBy6 --
 123.123	1989
-1243.5	1986
+1243.500	1986
 24453.325	1989
 
 -- !orderBy7 --
 123.123	1989
-1243.5	1986
+1243.500	1986
 24453.325	1989
 
 -- !orderBy5 --
 123.123	1001
-1243.5	1001
+1243.500	1001
 24453.325	1002
 
 -- !orderBy6 --
 123.123	1001
-1243.5	1001
+1243.500	1001
 24453.325	1002
 
 -- !orderBy7 --
 123.123	1001
-1243.5	1001
+1243.500	1001
 24453.325	1002
 
 -- !orderBy5 --
 123.123	11011902
-1243.5	11011903
+1243.500	11011903
 24453.325	11011905
 
 -- !orderBy6 --
 123.123	11011902
-1243.5	11011903
+1243.500	11011903
 24453.325	11011905
 
 -- !orderBy7 --
 123.123	11011902
-1243.5	11011903
+1243.500	11011903
 24453.325	11011905
 
 -- !orderBy5 --
 123.123	0.1
-1243.5	20.268
+1243.500	20.268
 24453.325	78945.0
 
 -- !orderBy6 --
 123.123	0.1
-1243.5	20.268
+1243.500	20.268
 24453.325	78945.0
 
 -- !orderBy7 --
 123.123	0.1
-1243.5	20.268
+1243.500	20.268
 24453.325	78945.0
 
 -- !orderBy5 --
 123.123	6.333
-1243.5	789.25
+1243.500	789.25
 24453.325	3654.0
 
 -- !orderBy6 --
 123.123	6.333
-1243.5	789.25
+1243.500	789.25
 24453.325	3654.0
 
 -- !orderBy7 --
 123.123	6.333
-1243.5	789.25
+1243.500	789.25
 24453.325	3654.0
 
 -- !orderBy5 --
 123.123	1989-03-21
-1243.5	1901-12-31
+1243.500	1901-12-31
 24453.325	2012-03-14
 
 -- !orderBy6 --
 123.123	1989-03-21
-1243.5	1901-12-31
+1243.500	1901-12-31
 24453.325	2012-03-14
 
 -- !orderBy7 --
 123.123	1989-03-21
-1243.5	1901-12-31
+1243.500	1901-12-31
 24453.325	2012-03-14
 
 -- !orderBy5 --
 123.123	1989-03-21T13:00
-1243.5	1989-03-21T13:00
+1243.500	1989-03-21T13:00
 24453.325	2000-01-01T00:00
 
 -- !orderBy6 --
 123.123	1989-03-21T13:00
-1243.5	1989-03-21T13:00
+1243.500	1989-03-21T13:00
 24453.325	2000-01-01T00:00
 
 -- !orderBy7 --
 123.123	1989-03-21T13:00
-1243.5	1989-03-21T13:00
+1243.500	1989-03-21T13:00
 24453.325	2000-01-01T00:00
 
 -- !orderBy5 --
@@ -678,17 +678,17 @@
 
 -- !orderBy5 --
 0.1	123.123
-20.268	1243.5
+20.268	1243.500
 78945.0	24453.325
 
 -- !orderBy6 --
 0.1	123.123
-20.268	1243.5
+20.268	1243.500
 78945.0	24453.325
 
 -- !orderBy7 --
 0.1	123.123
-20.268	1243.5
+20.268	1243.500
 78945.0	24453.325
 
 -- !orderBy5 --
@@ -798,17 +798,17 @@
 
 -- !orderBy5 --
 6.333	123.123
-789.25	1243.5
+789.25	1243.500
 3654.0	24453.325
 
 -- !orderBy6 --
 6.333	123.123
-789.25	1243.5
+789.25	1243.500
 3654.0	24453.325
 
 -- !orderBy7 --
 6.333	123.123
-789.25	1243.5
+789.25	1243.500
 3654.0	24453.325
 
 -- !orderBy5 --
@@ -917,17 +917,17 @@
 2012-03-14	11011905
 
 -- !orderBy5 --
-1901-12-31	1243.5
+1901-12-31	1243.500
 1989-03-21	123.123
 2012-03-14	24453.325
 
 -- !orderBy6 --
-1901-12-31	1243.5
+1901-12-31	1243.500
 1989-03-21	123.123
 2012-03-14	24453.325
 
 -- !orderBy7 --
-1901-12-31	1243.5
+1901-12-31	1243.500
 1989-03-21	123.123
 2012-03-14	24453.325
 
@@ -1038,16 +1038,16 @@
 
 -- !orderBy5 --
 1989-03-21T13:00	123.123
-1989-03-21T13:00	1243.5
+1989-03-21T13:00	1243.500
 2000-01-01T00:00	24453.325
 
 -- !orderBy6 --
 1989-03-21T13:00	123.123
-1989-03-21T13:00	1243.5
+1989-03-21T13:00	1243.500
 2000-01-01T00:00	24453.325
 
 -- !orderBy7 --
-1989-03-21T13:00	1243.5
+1989-03-21T13:00	1243.500
 1989-03-21T13:00	123.123
 2000-01-01T00:00	24453.325
 
@@ -1097,38 +1097,38 @@
 2000-01-01T00:00	2012-03-14
 
 -- !group1 --
-123.123
+123.123000000
 
 -- !group2 --
-24453.325
+24453.325000000
 
 -- !group3 --
 8606.649333333
 
 -- !group4 --
-25819.948
+25819.948000000
 
 -- !group5 --
 3
 
 -- !group6 --
-123.123
-1243.5
+123.123000000
+1243.500000000
 
 -- !group7 --
-123.123
-1243.5
-24453.325
+123.123000000
+1243.500000000
+24453.325000000
 
 -- !group8 --
-123.123
-1243.5
-24453.325
+123.123000000
+1243.500000000
+24453.325000000
 
 -- !group9 --
-123.123
-1243.5
-24453.325
+123.123000000
+1243.500000000
+24453.325000000
 
 -- !group10 --
 1
@@ -1200,9 +1200,9 @@ true	0.1
 1
 
 -- !group28 --
-123.123	246.246	1
-1243.5	2487	1
-24453.325	48906.65	1
+123.123	246.246000000	1
+1243.500	2487.000000000	1
+24453.325	48906.650000000	1
 
 -- !group29 --
 0	0	1
@@ -1245,9 +1245,9 @@ true	0.1
 -- !group40 --
 
 -- !group41 --
-123.123
-1243.5
-24453.325
+123.123000000
+1243.500000000
+24453.325000000
 
 -- !group42 --
 
@@ -1317,16 +1317,14 @@ true	0.1
 11
 12
 
--- !order16 --
-
 -- !orderBy_withNull_1 --
-11012025.123
-11013146.5
-11036358.325
+11012025.123000000
+11013146.500000000
+11036358.325000000
 
 -- !orderBy_withNull_2 --
 123.123	\N
-1243.5	\N
+1243.500	\N
 24453.325	\N
 
 -- !orderBy_withNull_3 --
@@ -1348,9 +1346,9 @@ true	0.1
 \N	15
 
 -- !orderBy_withNull_4 --
-11012025.123	1
-11013146.5	2
-11036358.325	3
+11012025.123000000	1
+11013146.500000000	2
+11036358.325000000	3
 
 -- !orderBy_withNull_5 --
 \N
@@ -1362,14 +1360,14 @@ true	0.1
 \N	3
 
 -- !orderBy_withNull_8 --
-11012025.123	\N
-11013146.5	\N
-11036358.325	\N
+11012025.123000000	\N
+11013146.500000000	\N
+11036358.325000000	\N
 
 -- !orderBy_withNull_9 --
-11012025.123
-11013146.5
-11036358.325
+11012025.123000000
+11013146.500000000
+11036358.325000000
 
 -- !orderBy_withNull_10 --
 \N	\N
@@ -1389,3 +1387,6 @@ true	0.1
 \N	14
 \N	15
 
+-- !group31 --
+1
+
diff --git a/regression-test/suites/query_p0/keyword/order_group.groovy b/regression-test/suites/query_p0/keyword/order_group.groovy
index e625abfe40..0f7775ddcf 100644
--- a/regression-test/suites/query_p0/keyword/order_group.groovy
+++ b/regression-test/suites/query_p0/keyword/order_group.groovy
@@ -205,4 +205,10 @@ suite("order_group", "query,p0") {
         sum(k2) over (partition by k5 + k6)\
         as ss from ${tableName2}  where k5 > 2000 )s order by k1,k2 "
     check2_doris(res7, res8)
+
+    sql 'set enable_vectorized_engine=true;'
+    sql 'set enable_nereids_planner=true'
+    sql 'set enable_fallback_to_original_planner=false'
+    qt_group31 "select count(*) from ${tableName1} where (k11='2015-03-13 12:36:38' or k11 = '2000-01-01 00:00:00')\
+		    and k5 is not null group by k1%2, k2%2, k3%3, k4%3, k11%2 order by count(*)"
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org