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 00b5fd041267af..b0ee988a683420 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.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; @@ -373,6 +374,16 @@ public Set computeInputSlotIds(Analyzer analyzer) throws NotImplementedE 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 slots = tupleDescriptor.getSlots(); + for (SlotDescriptor slot : slots) { + if (!slot.isMaterialized()) { + List 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 550b958d4d9da0..20135da100ad25 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 ecda0de5bd5c6e..c97b351f296dcc 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`;""" }