[
https://issues.apache.org/jira/browse/CALCITE-7086?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
weihua zhang updated CALCITE-7086:
----------------------------------
Description:
Many databases do not support the form of filtered aggregates. It would be
helpful if we could implement a rule to convert the plan into a form that most
databases can understand.
in CALCITE-6893:
{code:sql}
select * from emp where deptno = 10
intersect
select * from emp where deptno = 20
intersect
select * from emp where deptno = 30
{code}
{noformat}
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4],
SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[AND(>($9, 0), >($10, 0), >($11, 0))])
LogicalAggregate(group=[{0, 1, 2, 3, 4, 5, 6, 7, 8}], count_i0=[COUNT()
FILTER $9], count_i1=[COUNT() FILTER $10], count_i2=[COUNT() FILTER $11]) //
<---here
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4],
SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], $f10=[=($9, 0)], $f11=[=($9,
1)], $f12=[=($9, 2)])
LogicalUnion(all=[true])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3],
HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], i=[0])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3],
HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 10)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3],
HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], i=[1])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3],
HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 20)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3],
HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], i=[2])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3],
HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
LogicalFilter(condition=[=($7, 30)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
{noformat}
was:
Many databases do not support the form of filtered aggregates. It would be
helpful if we could implement a rule to convert the plan into a form that most
databases can understand.
in CALCITE-6893:
{code:java}
/*
* <pre>{@code
* SELECT job FROM "scott".emp WHERE deptno = 10
* INTERSECT
* SELECT job FROM "scott".emp WHERE deptno = 20
* }</pre>
*
* <p>Query after conversion:
* <pre>{@code
* SELECT job
* FROM (
* SELECT job, 0 AS i FROM "scott".emp WHERE deptno = 10
* UNION ALL
* SELECT job, 1 AS i FROM "scott".emp WHERE deptno = 20
* )
* GROUP BY job
* HAVING COUNT(*) FILTER (WHERE i = 0) > 0
* AND COUNT(*) FILTER (WHERE i = 1) > 0
* }</pre>
*/
{code}
> Implement a rule that performs the inverse operation of
> AggregateCaseToFilterRule
> ---------------------------------------------------------------------------------
>
> Key: CALCITE-7086
> URL: https://issues.apache.org/jira/browse/CALCITE-7086
> Project: Calcite
> Issue Type: New Feature
> Reporter: weihua zhang
> Priority: Major
>
> Many databases do not support the form of filtered aggregates. It would be
> helpful if we could implement a rule to convert the plan into a form that
> most databases can understand.
> in CALCITE-6893:
> {code:sql}
> select * from emp where deptno = 10
> intersect
> select * from emp where deptno = 20
> intersect
> select * from emp where deptno = 30
> {code}
> {noformat}
> LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4],
> SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
> LogicalFilter(condition=[AND(>($9, 0), >($10, 0), >($11, 0))])
> LogicalAggregate(group=[{0, 1, 2, 3, 4, 5, 6, 7, 8}], count_i0=[COUNT()
> FILTER $9], count_i1=[COUNT() FILTER $10], count_i2=[COUNT() FILTER $11])
> // <---here
> LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3],
> HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], $f10=[=($9,
> 0)], $f11=[=($9, 1)], $f12=[=($9, 2)])
> LogicalUnion(all=[true])
> LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3],
> HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], i=[0])
> LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3],
> HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
> LogicalFilter(condition=[=($7, 10)])
> LogicalTableScan(table=[[CATALOG, SALES, EMP]])
> LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3],
> HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], i=[1])
> LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3],
> HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
> LogicalFilter(condition=[=($7, 20)])
> LogicalTableScan(table=[[CATALOG, SALES, EMP]])
> LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3],
> HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], i=[2])
> LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3],
> HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8])
> LogicalFilter(condition=[=($7, 30)])
> LogicalTableScan(table=[[CATALOG, SALES, EMP]])
> {noformat}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)