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

yiguolei 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 25b427d0c6 [Bugfix](inpredicate) fix in predicate in group by clause 
may cause NPE (#11886)
25b427d0c6 is described below

commit 25b427d0c659144f86d1417036393fe6b8887903
Author: Zhengguo Yang <yangz...@gmail.com>
AuthorDate: Sun Aug 21 10:03:30 2022 +0800

    [Bugfix](inpredicate) fix in predicate in group by clause may cause NPE 
(#11886)
    
    * [bug](inpredicate) fix in predicate in group by clause may cause NPE
---
 .../doris/rewrite/RewriteInPredicateRule.java      |  8 +++++--
 .../data/query_p0/aggregate/aggregate.out          | 13 +++++++++++
 .../suites/query_p0/aggregate/aggregate.groovy     | 25 ++++++++++++++++++++++
 3 files changed, 44 insertions(+), 2 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/rewrite/RewriteInPredicateRule.java 
b/fe/fe-core/src/main/java/org/apache/doris/rewrite/RewriteInPredicateRule.java
index f6f6b9bc3f..6a1a3a059b 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/rewrite/RewriteInPredicateRule.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/rewrite/RewriteInPredicateRule.java
@@ -55,8 +55,12 @@ public class RewriteInPredicateRule implements 
ExprRewriteRule {
         }
         InPredicate inPredicate = (InPredicate) expr;
         SlotRef slotRef;
-        if (inPredicate.contains(Subquery.class) || 
!inPredicate.isLiteralChildren() || inPredicate.isNotIn()
-                || !(inPredicate.getChild(0).unwrapExpr(false) instanceof 
SlotRef)
+        // When the select stmt contains group by, we use oriGroupingExprs to 
store the original group by statement
+        // and reset it with the rewritten groupingExpr. Therefore, 
origroupingexprs cannot be analyzed.
+        // However, in #4197, oriGroupingExprs is rewritten to fix the problem 
of constant fold.
+        // The newly added InPredicteRewriteRule requires that expr must be 
analyzed before being rewritten
+        if (!inPredicate.isAnalyzed() || inPredicate.contains(Subquery.class) 
|| !inPredicate.isLiteralChildren()
+                || inPredicate.isNotIn() || 
!(inPredicate.getChild(0).unwrapExpr(false) instanceof SlotRef)
                 || (slotRef = inPredicate.getChild(0).getSrcSlotRef()) == null 
|| slotRef.getColumn() == null) {
             return expr;
         }
diff --git a/regression-test/data/query_p0/aggregate/aggregate.out 
b/regression-test/data/query_p0/aggregate/aggregate.out
index 8116f6ae15..c23317e7e9 100644
--- a/regression-test/data/query_p0/aggregate/aggregate.out
+++ b/regression-test/data/query_p0/aggregate/aggregate.out
@@ -110,6 +110,19 @@ TESTING    AGAIN
 18000
 26988
 
+-- !aggregate --
+\N     other   98.52
+12     other   12.25
+25     other   55.52
+100    again   99.8777
+100    other   11.668833333333334
+964    again   0.245
+5000   other   67.87
+5252   sample  12.25
+5748   sample  67.87
+6000   other   \N
+8996   other   98.8777
+
 -- !aggregate1 --
 \N     \N
 -32767 2147484649
diff --git a/regression-test/suites/query_p0/aggregate/aggregate.groovy 
b/regression-test/suites/query_p0/aggregate/aggregate.groovy
index 61bcd3f4bd..8053479c1c 100644
--- a/regression-test/suites/query_p0/aggregate/aggregate.groovy
+++ b/regression-test/suites/query_p0/aggregate/aggregate.groovy
@@ -110,6 +110,31 @@ suite("aggregate") {
     qt_aggregate """ select variance(c_bigint), variance(distinct c_double) 
from ${tableName}  """
     qt_aggregate """ select 1 k1, 2 k2, c_bigint k3, sum(c_double) from 
${tableName} group by 1, k2, k3 order by k1, k2, k3 """
     qt_aggregate """ select (k1 + k2) * k3 k4 from (select 1 k1, 2 k2, 
c_bigint k3, sum(c_double) from ${tableName} group by 1, k2, k3) t order by k4 
"""
+    qt_aggregate """
+                SELECT c_bigint,  
+                    CASE
+                    WHEN c_string IN ('sample', 'Sample') THEN
+                    'sample'
+                    WHEN c_string IN ('Again', 'AGAIN') THEN
+                    'again'
+                    ELSE 'other' end, avg(c_double)
+                FROM ${tableName}
+                GROUP BY  c_bigint,
+                    CASE
+                    WHEN c_string IN ('sample', 'Sample') THEN
+                    'sample'
+                    WHEN c_string IN ('Again', 'AGAIN') THEN
+                    'again'
+                    ELSE 'other'
+                    END
+                ORDER BY  c_bigint,
+                    CASE
+                    WHEN c_string IN ('sample', 'Sample') THEN
+                    'sample'
+                    WHEN c_string IN ('Again', 'AGAIN') THEN
+                    'again'
+                    ELSE 'other' end
+                 """
 
     sql "use test_query_db"
     List<String> fields = ["k1", "k2", "k3", "k4", "k5", "k6", "k10", "k11", 
"k7", "k8", "k9"]


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

Reply via email to