Skip to content

Commit

Permalink
[fix](planner) remove and retain input slot for aggregate slot which …
Browse files Browse the repository at this point in the history
…is not materialized

Signed-off-by: nextdreamblue <[email protected]>
  • Loading branch information
nextdreamblue committed Mar 29, 2024
1 parent 86e99f9 commit 379db69
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -373,16 +373,25 @@ public Set<SlotId> computeInputSlotIds(Analyzer analyzer) throws NotImplementedE
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@
2
3

-- !select5 --
3

Original file line number Diff line number Diff line change
Expand Up @@ -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`;"""
}

0 comments on commit 379db69

Please sign in to comment.