Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore usage of filtered SUM #17378

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

kgyrtkirk
Copy link
Member

Recent upgrade of calcite have brought a change which have fixed a minor correctness issue by not allowing the rewrite of SUM(CASE WHEN COND THEN C ELSE 0 END) to SUM(C) FILTER(COND)

This patch restores the old behaviour as the nested case_searched the above may retain in the plans could have serious performance impacts.

{
public DruidAggregateCaseToFilterRule()
{
super(operand(Aggregate.class, operand(Project.class, any())));

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
CalciteTestBase.makeColumnExpression
should be avoided because it has been deprecated.
{
public DruidAggregateCaseToFilterRule()
{
super(operand(Aggregate.class, operand(Project.class, any())));

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
CalciteTestBase.makeExpression
should be avoided because it has been deprecated.
{
public DruidAggregateCaseToFilterRule()
{
super(operand(Aggregate.class, operand(Project.class, any())));

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
CalciteTestBase.makeColumnExpression
should be avoided because it has been deprecated.
&& value.equals(((RexLiteral) rexNode).getValueAs(BigDecimal.class));
}

private static class RewriteShuttle extends RexShuttle

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
CalciteTestBase.makeColumnExpression
should be avoided because it has been deprecated.
* SUM(CASE WHEN COND THEN COL1 ELSE 0 END)
* without introducing an inner case this should be removed.
*/
public class DruidAggregateCaseToFilterRule extends RelOptRule implements SubstitutionRule
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this rule create a null-handling bug? I thought that was why we stopped doing the transformation. If so I wonder if there's some other way we can fix the performance regression.

import java.util.List;

/**
* Druid version of {@link AggregateCaseToFilterRule}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this rule completely cover the functionality of AggregateCaseToFilterRule? If so, can we stop running AggregateCaseToFilterRule? i.e., by removing CoreRules.AGGREGATE_CASE_TO_FILTER from CalciteRulesManager.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no - it just provides some extra logic
I think this should be removed when the upstream one could cover this case as well

{
public DruidAggregateCaseToFilterRule()
{
super(operand(Aggregate.class, operand(Project.class, any())));

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
RelOptRule.operand
should be avoided because it has been deprecated.
{
public DruidAggregateCaseToFilterRule()
{
super(operand(Aggregate.class, operand(Project.class, any())));

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
RelOptRule.operand
should be avoided because it has been deprecated.
{
public DruidAggregateCaseToFilterRule()
{
super(operand(Aggregate.class, operand(Project.class, any())));

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
RelOptRule.any
should be avoided because it has been deprecated.
{
public DruidAggregateCaseToFilterRule()
{
super(operand(Aggregate.class, operand(Project.class, any())));

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
CalciteTestBase.makeColumnExpression
should be avoided because it has been deprecated.
{
public DruidAggregateCaseToFilterRule()
{
super(operand(Aggregate.class, operand(Project.class, any())));

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
CalciteTestBase.makeColumnExpression
should be avoided because it has been deprecated.
{
public DruidAggregateCaseToFilterRule()
{
super(operand(Aggregate.class, operand(Project.class, any())));

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
CalciteTestBase.makeColumnExpression
should be avoided because it has been deprecated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants