[fix](planner) remove and retain input slot for aggregate slot which is not materialized (#33033)

Signed-off-by: nextdreamblue <zxw520blue1@163.com>
This commit is contained in:
xueweizhang
2024-03-29 18:54:54 +08:00
committed by yiguolei
parent 5b162a80f2
commit c5ab7ca573
3 changed files with 62 additions and 9 deletions

View File

@ -373,16 +373,25 @@ public class AggregationNode extends PlanNode {
if (!tupleDesc.getMaterializedSlots().isEmpty()) {
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);
} else {
// 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();
Set<SlotId> allUnRequestIds = Sets.newHashSet();
Set<SlotId> allRequestIds = Sets.newHashSet();
for (SlotDescriptor slot : slots) {
if (!slot.isMaterialized()) {
List<SlotId> unRequestIds = Lists.newArrayList();
Expr.getIds(slot.getSourceExprs(), null, unRequestIds);
allUnRequestIds.addAll(unRequestIds);
} else {
List<SlotId> requestIds = Lists.newArrayList();
Expr.getIds(slot.getSourceExprs(), null, requestIds);
allRequestIds.addAll(requestIds);
}
}
allRequestIds.forEach(allUnRequestIds::remove);
allUnRequestIds.forEach(result::remove);
}
return result;
}

View File

@ -23,3 +23,6 @@
2
3
-- !select5 --
3

View File

@ -562,6 +562,47 @@ suite("test_inlineview_with_project") {
order by 1;
"""
qt_select5 """
select
count(*)
from
(
select
random(),
group_concat(cast(ga.column3 as varchar)) as column111
from
(
select
t1.id as id,
upper(t1.caseId) as column1,
t1.content as column3
from
(
select
id,
caseId,
content
from
dr_user_test_t2
limit
10
) t1
left join (
select
id,
caseId,
content
from
dr_user_test_t2
limit
10
) t2 on t1.id = t2.id
) as ga
group by
lower(ga.column3)
) as a;
"""
sql """DROP TABLE IF EXISTS `dr_user_test_t1`;"""
sql """DROP TABLE IF EXISTS `dr_user_test_t2`;"""
}