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

[CALCITE-6746] Optimization rule ProjectWindowTranspose is unsound #4113

Merged
merged 1 commit into from
Dec 27, 2024

Conversation

mihaibudiu
Copy link
Contributor

@mihaibudiu mihaibudiu commented Dec 27, 2024

The visitor that keep track of the used fields did not account for the window bounds.

Comment on lines 220 to 222
List<RexNode> analyze = new ArrayList<>();
if (group.lowerBound.getOffset() != null) {
analyze.add(group.lowerBound.getOffset());
}
if (group.upperBound.getOffset() != null) {
analyze.add(group.upperBound.getOffset());
}
referenceFinder.apply(analyze);

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not simply:

      group.lowerBound.accept(referenceFinder);
      group.upperBound.accept(referenceFinder);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't work, since the RexWindowBound does not derive from RexNode.

Copy link
Contributor

Choose a reason for hiding this comment

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

RexWindowBound accepts RexVisitor. In your case, if its a bounded window bound, it should take care of visiting the offset (also offset is not nullable). See this: https://github.com/apache/calcite/blob/main/core/src/main/java/org/apache/calcite/rex/RexWindowBounds.java#L181

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seems to work in this case.

The style of visitors I am used to requires always the entry point to be a visitor apply function, and not an accept function of the visited object. This is because the visitor may setup and teardown some data structures on apply.

A quick look through the codebase shows lots of accept calls, so I will use your suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because this is such a small change I have updated my previous commit instead of creating a new one.

Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
Copy link
Contributor

@a-rafay a-rafay left a comment

Choose a reason for hiding this comment

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

Can you also add a 1 liner description as well? The rest LGTM.

@mihaibudiu
Copy link
Contributor Author

Where should I add the description? In the change or in the test?

@mihaibudiu mihaibudiu added the LGTM-will-merge-soon Overall PR looks OK. Only minor things left. label Dec 27, 2024
@a-rafay
Copy link
Contributor

a-rafay commented Dec 27, 2024

Where should I add the description? In the change or in the test?

You can update the description from github. Scroll to the top and you'll see:
image

@mihaibudiu mihaibudiu merged commit 4c70fc7 into apache:main Dec 27, 2024
23 of 36 checks passed
@mihaibudiu mihaibudiu deleted the issue6746 branch December 27, 2024 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LGTM-will-merge-soon Overall PR looks OK. Only minor things left.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants