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

Silun Dong commented on CALCITE-7091:
-------------------------------------

Hi [~julianhyde] , about:
 # When converting CASE-style to true filter aggregate, if the aggregate is 
distinct, only COUNT can be converted.
 # When generating a true filter aggregate, the {{{}distinct{}}}, 
{{{}approximate{}}}, and {{ignoreNulls}} are fixed artificially, which may be 
inconsistent with the original CASE-style aggregate.

I reviewed your jira ticket CALCITE-3144 and related links, and I didn't find 
any information related to the above two points. I think the second point looks 
like a bug. But I am not sure about the first point, whether we can relax the 
restrictions and convert whether it is a distinct aggregate or not. I can't 
think of a scenario that will lead to inconsistent results. What do you think?

> Approximate of AggregateCall changes after applying AggregateCaseToFilterRule
> -----------------------------------------------------------------------------
>
>                 Key: CALCITE-7091
>                 URL: https://issues.apache.org/jira/browse/CALCITE-7091
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.40.0
>            Reporter: Silun Dong
>            Priority: Minor
>
> When AggregateCaseToFilterRule converts a CASE-style filter aggregate into a 
> true filter aggregate, the approximate of the generated true filter aggregate 
> is always false.
> {code:java}
> select APPROX_COUNT_DISTINCT(case when job = 'CLERK' then deptno else null 
> end) as count_distinct_clerk from emp
> // init plan
> LogicalAggregate(group=[{}], COUNT_DISTINCT_CLERK=[COUNT(APPROXIMATE DISTINCT 
> $0)])
>   LogicalProject($f0=[CASE(=($2, 'CLERK'), $7, null:INTEGER)])
>     LogicalTableScan(table=[[CATALOG, SALES, EMP]])
> // after
> LogicalAggregate(group=[{}], COUNT_DISTINCT_CLERK=[COUNT(DISTINCT $0) FILTER 
> $1])
>   LogicalProject(DEPTNO=[$7], $f2=[=($2, 'CLERK')])
>     LogicalTableScan(table=[[CATALOG, SALES, EMP]]){code}
> This looks like a bug.



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

Reply via email to