Skip to content

[CALCITE-5506] RelToSqlConverter should retain the aggregation logic #3052

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

Merged
merged 1 commit into from
May 5, 2023

Conversation

JiajunBernoulli
Copy link
Contributor

@JiajunBernoulli JiajunBernoulli commented Jan 29, 2023

RelToSqlConverter should retain the aggregation logic when Project without RexInputRef on the Aggregate.

LogicalProject(L_COST=[$0])
  LogicalJoin(condition=[=($1, $2)], joinType=[inner])
    LogicalValues(tuples=[[{ 0, 1 }]])
    LogicalProject(K=[1]) 
      LogicalAggregate(group=[{}], DUMMY=[COUNT()])
        LogicalUnion(all=[false])
          LogicalValues(tuples=[[{ 1 }]])
          LogicalValues(tuples=[[{ 2 }]])

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@JiajunBernoulli JiajunBernoulli changed the title [CALCITE-5506] RelToSqlConverter get error result because RelFieldTri… [CALCITE-5506] RelToSqlConverter should retain the aggregation logic May 3, 2023
@JiajunBernoulli JiajunBernoulli force-pushed the CALCITE-5506 branch 2 times, most recently from d535a5f to 73a241f Compare May 3, 2023 03:59
…when Project without RexInputRef on the Aggregate
@sonarqubecloud
Copy link

sonarqubecloud bot commented May 3, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

.stream()
.anyMatch(rex -> RexUtil.containsInputRef(rex));
final boolean hasAggregate =
input instanceof Aggregate && input.getRowType().getFieldCount() > 0;
Copy link
Member

Choose a reason for hiding this comment

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

Do you need to add input.getRowType().getFieldCount() > 0? (I even doubt that we will produce RelNode which has 0 fields)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, here is the RelNode which has 0 field.

image

Copy link
Member

Choose a reason for hiding this comment

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

But the aggregate in your test actually has 1 column, will it still pass without this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it failed.

java.lang.AssertionError: 
Expected: is "SELECT 42 AS \"C\"\nFROM \"foodmart\".\"product\"\nGROUP BY ()"
     but: was "SELECT 42 AS \"C\"\nFROM (SELECT\nFROM \"foodmart\".\"product\"\nGROUP BY ()) AS \"t\""

Copy link
Member

Choose a reason for hiding this comment

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

Sorry that I misunderstood the attention of this condition. Now I think I get your point, and it looks correct (although it may be a little coarse grained, it's ok to me because we have hasInputRef to narrow down the impact)

Copy link
Member

@libenchao libenchao left a comment

Choose a reason for hiding this comment

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

+1

.stream()
.anyMatch(rex -> RexUtil.containsInputRef(rex));
final boolean hasAggregate =
input instanceof Aggregate && input.getRowType().getFieldCount() > 0;
Copy link
Member

Choose a reason for hiding this comment

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

Sorry that I misunderstood the attention of this condition. Now I think I get your point, and it looks correct (although it may be a little coarse grained, it's ok to me because we have hasInputRef to narrow down the impact)

@libenchao libenchao merged commit 6f10c13 into apache:main May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants