[ 
https://issues.apache.org/jira/browse/CALCITE-1930?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16118728#comment-16118728
 ] 

MinJi Kim commented on CALCITE-1930:
------------------------------------

The assumption that the "distinct aggregate call" have only one argument was 
always there for converting the single distinct call, but never explicitly 
stated.  So I added it to make it clear.  I don't think it is inherently 
necessary, although will need some work to fix.  To understand this properly, 
if someone uses COUNT(distinct x, y, z), it would be counting distinct 
combination of x, y, z?  So, two rows with the following (x, y, z) values -- 
(1, 1, 1), (1, 1, 2) -- would be counted separately?  I can try to drop that 
assumption in the next patch.  Let me know if I have not understood the problem 
properly here.

I will also add some queries to agg.iq in the next patch.

> AggregateExpandDistinctAggregatesRule does not expand aggregates properly
> -------------------------------------------------------------------------
>
>                 Key: CALCITE-1930
>                 URL: https://issues.apache.org/jira/browse/CALCITE-1930
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>            Reporter: MinJi Kim
>            Assignee: Julian Hyde
>
> A query with two aggregate calls, sum(comm) and min(comm), it produces an 
> incorrect plan.  The main problem is that it fails to index the input of 
> sum(comm) and min(comm) properly.  This seems to only happen in the special 
> case where there is only one distinct aggregate call.
> {code}
> SELECT deptno, sum(comm), min(comm), SUM(DISTINCT sal) FROM emp GROUP BY 
> deptno
> {code}
> AggregateExpandDistinctAggregatesRule produces the following plan in this 
> case.
> {code}
> LogicalAggregate(group=[{0}], EXPR$1=[SUM($3)], EXPR$2=[MIN($3)], 
> EXPR$3=[SUM($1)])
>   LogicalAggregate(group=[{0, 2}], EXPR$1=[SUM($1)], EXPR$2=[MIN($1)])
>     LogicalProject(DEPTNO=[$7], COMM=[$6], SAL=[$5])
>       LogicalTableScan(table=[[CATALOG, SALES, EMP]])
> {code}
> In the above plan, the top LogicalAggregate EXPR$1=[SUM($3]] is incorrect, it 
> should be SUM($2).



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to