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

JingDas commented on CALCITE-5846:
----------------------------------

In Calcite, I run test as following:

SQL
{code:java}
SELECT deptno, SUM(sal) FILTER (WHERE sal > 1000), SUM(sal) WITHIN DISTINCT 
(job)
FROM emp
GROUP BY deptno;{code}
After AggregateExpandWithinDistinctRule#onMatch the relNode is as following:
{code:java}
LogicalProject(DEPTNO=[$0], EXPR$1=[CASE(=($2, 0), null:INTEGER, $1)], 
EXPR$2=[$3])
  LogicalProject(DEPTNO=[$0], $f1=[CAST($1):INTEGER NOT NULL], 
$f2=[CAST($2):BIGINT NOT NULL], $f3=[$3])
    LogicalAggregate(group=[{0}], agg#0=[MIN($1) FILTER $4], agg#1=[MIN($2) 
FILTER $4], agg#2=[$SUM0($3) FILTER $5])
      LogicalProject(DEPTNO=[$0], $f2=[$2], $f3=[$3], $f4=[$4], $f6=[=($5, 1)], 
$f7=[=($5, 0)])
        LogicalAggregate(group=[{0, 3}], groups=[[{0, 3}, {0}]], 
agg#0=[$SUM0($1)], agg#1=[COUNT()], agg#2=[MIN($1)], agg#3=[GROUPING($0, $3)])
          LogicalProject(DEPTNO=[$7], SAL=[$5], $f2=[>($5, 1000)], JOB=[$2])
            LogicalTableScan(table=[[CATALOG, SALES, EMP]]){code}
The 'sal > 1000' filter in query seems lost.

 

 

> AggregateExpandWithinDistinctRule drops filters on non-distinct aggCalls
> ------------------------------------------------------------------------
>
>                 Key: CALCITE-5846
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5846
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Steven Talbot
>            Priority: Major
>
> This line 
> [https://github.com/apache/calcite/blob/2dba40e7a0a5651eac5a30d9e0a72f178bd9bff2/core/src/main/java/org/apache/calcite/rel/rules/AggregateExpandWithinDistinctRule.java#L346-L348]
>  drops any such filterArg.
> Related to  CALCITE-4726. When the rule was first introduced any such 
> aggregates were blocked, but that change lets them through.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to