[
https://issues.apache.org/jira/browse/CALCITE-3721?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Shuo Cheng updated CALCITE-3721:
--------------------------------
Comment: was deleted
(was: Hi, Danny, actually, A and B have different groupSet:
{code:java}
LogicalAggregate(group=[{}], EXPR$0=[COUNT($0) FILTER $2], EXPR$1=[COUNT($2)
FILTER $3])
LogicalProject(COMM=[$0], SAL=[$2], $g_3=[AND(=($4, 3), IS TRUE($1))],
$g_12=[AND(=($4, 12), IS TRUE($3))])
LogicalAggregate(group=[{0, 1, 2, 3}], groups=[[{0, 1}, {2, 3}]],
$g=[GROUPING($0, $1, $2, $3)])
LogicalProject(COMM=[$6], $f1=[<($5, 10)], SAL=[$5], $f3=[>($6, 1000)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
{code})
> Filter of distinct aggregate call is lost after applying
> `AggregateExpandDistinctAggregatesRule`
> ------------------------------------------------------------------------------------------------
>
> Key: CALCITE-3721
> URL: https://issues.apache.org/jira/browse/CALCITE-3721
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.21.0
> Reporter: Shuo Cheng
> Assignee: Shuo Cheng
> Priority: Major
> Labels: pull-request-available
> Fix For: 1.22.0
>
> Time Spent: 40m
> Remaining Estimate: 0h
>
> In `AggregateExpandDistinctAggregatesRule`, when the distinct aggregate call
> is rewritten using
> groupingSets, the filter of the distinct aggregate call itself is lost
> unexpected.
> Currently, the plan of the following sql after applying
> `AggregateExpandDistinctAggregatesRule` is :
> {code:java}
> // SQL
> SELECT
> SUM(comm), COUNT(DISTINCT sal) FILTER (WHERE sal > 1000)
> FROM emp{code}
> {color:#de350b}current plan is:{color}
> {code:java}
> LogicalAggregate(group=[{}], EXPR$0=[MIN($2) FILTER $4], EXPR$1=[COUNT($0)
> FILTER $3])
> LogicalProject(SAL=[$0], $f2=[$1], EXPR$0=[$2], $g_0=[=($3, 0)],
> $g_3=[=($3, 3)])
> LogicalAggregate(group=[{1, 2}], groups=[[{1, 2}, {}]], EXPR$0=[SUM($0)],
> $g=[GROUPING($1, $2)])
> LogicalProject(COMM=[$6], SAL=[$5], $f2=[>($5, 1000)])
> LogicalTableScan(table=[[CATALOG, SALES, EMP]]){code}
> But actually, the {color:#4c9aff}expected or correct plan{color} is:
> {code:java}
> LogicalAggregate(group=[{}], EXPR$0=[MIN($2) FILTER $4], EXPR$1=[COUNT($0)
> FILTER $3])
> LogicalProject(SAL=[$0], $f2=[$1], EXPR$0=[$2], $g_0=[AND(=($3, 0), IS
> TRUE($1))], $g_3=[=($3, 3)])
> LogicalAggregate(group=[{1, 2}], groups=[[{1, 2}, {}]], EXPR$0=[SUM($0)],
> $g=[GROUPING($1, $2)])
> LogicalProject(COMM=[$6], SAL=[$5], $f2=[>($5, 1000)])
> LogicalTableScan(table=[[CATALOG, SALES, EMP]]){code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)