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

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


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new f5650d1f540 [fix](planner) remove input slot for aggregate slot which 
is not materialized (#32092) (#32133)
f5650d1f540 is described below

commit f5650d1f5404f9f9a5e7bf22f3314c74c20f67bb
Author: xueweizhang <[email protected]>
AuthorDate: Tue Mar 12 19:54:11 2024 +0800

    [fix](planner) remove input slot for aggregate slot which is not 
materialized (#32092) (#32133)
    
    cherry-pick from master #27096
    
    introduced by #26886
    
    run this sql:
    SELECT
            caseId
        FROM
            (
                SELECT
                    caseId,
                    count(judgementDateId)
                FROM
                    (
                        SELECT
                            abs(caseId) AS caseId,
                            id as judgementDateId
                        FROM
                            dr_user_test_t2
                    ) AGG_RESULT
                GROUP BY
                    caseId
            ) TOTAL
            order by 1;
    
    
    will get:
    
    ERROR 1105 (HY000): errCode = 2, detailMessage = 
(172.17.0.1)[INTERNAL_ERROR]couldn't resolve slot descriptor 1, desc: tuples:
    Tuple(id=5 slots=[Slot(id=10 type=DOUBLE col=-1, colname=, nullable=1), 
Slot(id=11 type=VARCHAR col=-1, colname=id, nullable=1)] has_varlen_slots=1)
    Tuple(id=4 slots=[Slot(id=8 type=DOUBLE col=-1, colname=, nullable=1)] 
has_varlen_slots=0)
    Tuple(id=2 slots=[Slot(id=4 type=DOUBLE col=-1, colname=caseId, 
nullable=1)] has_varlen_slots=0)
    Tuple(id=0 slots=[Slot(id=0 type=VARCHAR col=-1, colname=caseId, nu
---
 .../org/apache/doris/planner/AggregationNode.java  | 11 ++++++
 .../test_inlineview_with_project.out               | 10 +++++
 .../test_inlineview_with_project.groovy            | 44 ++++++++++++++++++++++
 3 files changed, 65 insertions(+)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/planner/AggregationNode.java 
b/fe/fe-core/src/main/java/org/apache/doris/planner/AggregationNode.java
index a842507673f..b0a4fcf2db3 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/AggregationNode.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/AggregationNode.java
@@ -24,6 +24,7 @@ import org.apache.doris.analysis.AggregateInfo;
 import org.apache.doris.analysis.Analyzer;
 import org.apache.doris.analysis.Expr;
 import org.apache.doris.analysis.FunctionCallExpr;
+import org.apache.doris.analysis.SlotDescriptor;
 import org.apache.doris.analysis.SlotId;
 import org.apache.doris.analysis.TupleDescriptor;
 import org.apache.doris.common.NotImplementedException;
@@ -363,6 +364,16 @@ public class AggregationNode extends PlanNode {
                 result.add(tupleDesc.getMaterializedSlots().get(0).getId());
             }
         }
+        // if some input slot for aggregate slot which is not materialized, we 
need to remove it from the result
+        TupleDescriptor tupleDescriptor = aggInfo.getOutputTupleDesc();
+        ArrayList<SlotDescriptor>  slots = tupleDescriptor.getSlots();
+        for (SlotDescriptor slot : slots) {
+            if (!slot.isMaterialized()) {
+                List<SlotId> unRequestIds = Lists.newArrayList();
+                Expr.getIds(slot.getSourceExprs(), null, unRequestIds);
+                unRequestIds.forEach(result::remove);
+            }
+        }
         return result;
     }
 
diff --git 
a/regression-test/data/correctness_p0/test_inlineview_with_project.out 
b/regression-test/data/correctness_p0/test_inlineview_with_project.out
index 550b958d4d9..20135da100a 100644
--- a/regression-test/data/correctness_p0/test_inlineview_with_project.out
+++ b/regression-test/data/correctness_p0/test_inlineview_with_project.out
@@ -13,3 +13,13 @@
 -- !select5 --
 3
 
+-- !select5 --
+1
+2
+3
+
+-- !select5 --
+1
+2
+3
+
diff --git 
a/regression-test/suites/correctness_p0/test_inlineview_with_project.groovy 
b/regression-test/suites/correctness_p0/test_inlineview_with_project.groovy
index be5dd9dddfd..8a70fb9e751 100644
--- a/regression-test/suites/correctness_p0/test_inlineview_with_project.groovy
+++ b/regression-test/suites/correctness_p0/test_inlineview_with_project.groovy
@@ -518,6 +518,50 @@ suite("test_inlineview_with_project") {
                                 FROM test_01 ) TOTAL;
     """
 
+    qt_select5 """
+    SELECT
+        caseId
+    FROM
+        (
+            SELECT
+                caseId,
+                count(judgementDateId)
+            FROM
+                (
+                    SELECT
+                        abs(caseId) AS caseId,
+                        id as judgementDateId
+                    FROM
+                        dr_user_test_t2
+                ) AGG_RESULT
+            GROUP BY
+                caseId
+        ) TOTAL
+        order by 1;
+    """
+
+    qt_select5 """
+    SELECT
+        caseId
+    FROM
+        (
+            SELECT
+                caseId,
+                count(judgementDateId)
+            FROM
+                (
+                    SELECT
+                        caseId AS caseId,
+                        abs(id) as judgementDateId
+                    FROM
+                        dr_user_test_t2
+                ) AGG_RESULT
+            GROUP BY
+                caseId
+        ) TOTAL
+        order by 1;
+    """
+
     sql """DROP TABLE IF EXISTS `dr_user_test_t1`;"""
     sql """DROP TABLE IF EXISTS `dr_user_test_t2`;"""
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to