Skip to content

Commit

Permalink
[fix](planner)output slot should be materialized as intermediate slot…
Browse files Browse the repository at this point in the history
… in agg node apache#27282 (apache#27285)
  • Loading branch information
starocean999 authored and gnehil committed Dec 4, 2023
1 parent fae836a commit e8d07aa
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,7 @@ public void materializeRequiredSlots(Analyzer analyzer, ExprSubstitutionMap smap
continue;
}

slotDesc.setIsMaterialized(true);
intermediateSlotDesc.setIsMaterialized(true);
exprs.add(functionCallExpr);
materializedSlots.add(i);
Expand Down
3 changes: 3 additions & 0 deletions regression-test/data/correctness_p0/test_agg_materialize.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
-- !select --
3

-- !select2 --
1
qycs
69 changes: 69 additions & 0 deletions regression-test/suites/correctness_p0/test_agg_materialize.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,73 @@ suite("test_agg_materialize") {
from tb1
where e1 = 1)tttt
; """
sql """drop table if exists c5749_bug_t;"""
sql """CREATE TABLE `c5749_bug_t` (
`org_code` varchar(255) NULL ,
`cash_amt` decimal(27, 9) NULL ,
) ENGINE=OLAP
DUPLICATE KEY(`org_code`)
DISTRIBUTED BY HASH(`org_code`) BUCKETS AUTO
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"in_memory" = "false",
"storage_format" = "V2",
"disable_auto_compaction" = "false"
);"""
sql """insert into c5749_bug_t values('1',1), ('1',2);"""
qt_select2 """with SPJ AS (
WITH TOTAL AS (
SELECT
t1.org_code,
round(ifnull(sum(t1.qty), 0) / 10000, 2) qty
FROM
(
SELECT
parentOrg.org_code,
SUM(parentOrg.cash_amt) qty
FROM
c5749_bug_t parentOrg
GROUP BY
parentOrg.org_code
UNION
ALL
SELECT
parentOrg.org_code,
SUM(parentOrg.cash_amt) qty
FROM
c5749_bug_t parentOrg
GROUP BY
parentOrg.org_code
) t1
GROUP BY
t1.org_code
),
AGG AS (
SELECT
TOTAL.org_code,
TOTAL.qty totalQty
FROM
TOTAL
UNION
ALL
SELECT
'qycs' org_code,
SUM(TOTAL.qty) totalQty
FROM
TOTAL
)
SELECT
AGG.org_code,
AGG.totalQty AS totalQty
FROM
AGG
)
SELECT
SPJ.org_code
FROM
SPJ
ORDER BY SPJ.org_code;
"""
sql """drop table if exists c5749_bug_t;"""
}

0 comments on commit e8d07aa

Please sign in to comment.