You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Yingyu (Jira)" <ji...@apache.org> on 2021/06/03 17:39:00 UTC

[jira] [Updated] (CALCITE-4634) Improve AggregateProjectPullUpConstantsRule to remove all constant keys

     [ https://issues.apache.org/jira/browse/CALCITE-4634?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Yingyu updated CALCITE-4634:
----------------------------
    Description: 
*AggregateProjectPullUpConstantsRule* removes constant keys from an Aggregate. However, this rules never removes the last column, because Aggregate([]) returns 1 row even if its input is empty. 

The problem is if the remaining last column is a constant, it will fail on *SQL Server* with this error:
 "Each GROUP BY expression must contain at least one column that is not an outer reference."
  
 To improve on this we can improve the AggregateProjectPullUpConstantsRule to:
 - Remove all constant keys from an Aggregate
 - When no GROUP BY column is left, add a filter to the Aggregate([]) so that it returns empty dataset if its input is empty. 
  
 E.g. 
 select 'abc' from table_name group by ('abc')
 will be translated to:
 select 'abc' from table_name group by () having count(*) > 0

  was:
AggregateProjectPullUpConstantsRule removes constant keys from an Aggregate. However, this rules never removes the last column, because Aggregate([]) returns 1 row even if its input is empty. 

The problem is if the remaining last column is a constant, it will fail on SQL Server with this error:
"Each GROUP BY expression must contain at least one column that is not an outer reference."
 
To improve on this we can improve the AggregateProjectPullUpConstantsRule to:
- Remove all constant keys from an Aggregate
- When no GROUP BY column is left, add a filter to the Aggregate([]) so that it returns empty dataset if its input is empty. 
 
E.g. 
select 'abc' from table_name group by ('abc')
will be translated to:
select 'abc' from table_name group by () having count(*) > 0


> Improve AggregateProjectPullUpConstantsRule to remove all constant keys
> -----------------------------------------------------------------------
>
>                 Key: CALCITE-4634
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4634
>             Project: Calcite
>          Issue Type: Improvement
>          Components: core
>    Affects Versions: 1.16.0
>            Reporter: Yingyu
>            Priority: Major
>
> *AggregateProjectPullUpConstantsRule* removes constant keys from an Aggregate. However, this rules never removes the last column, because Aggregate([]) returns 1 row even if its input is empty. 
> The problem is if the remaining last column is a constant, it will fail on *SQL Server* with this error:
>  "Each GROUP BY expression must contain at least one column that is not an outer reference."
>   
>  To improve on this we can improve the AggregateProjectPullUpConstantsRule to:
>  - Remove all constant keys from an Aggregate
>  - When no GROUP BY column is left, add a filter to the Aggregate([]) so that it returns empty dataset if its input is empty. 
>   
>  E.g. 
>  select 'abc' from table_name group by ('abc')
>  will be translated to:
>  select 'abc' from table_name group by () having count(*) > 0



--
This message was sent by Atlassian Jira
(v8.3.4#803005)