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

ESQL: Do not fold in Range.foldable #119766

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

alex-spies
Copy link
Contributor

The upper and lower bounds can be incompatible, in which case the range is foldable to FALSE independently of the foldability of the field.

But we shouldn't try and fold the bounds to find out. Calling foldable really shouldn't already perform folding.

Instead, only perform the check for the invalid bounds if the bounds are already literals. This means that folding will still take place, but it requires the range's child expressions to be folded first.

That being said, Range is not used until the physical optimizer stage, anyway.

The upper and lower bounds can be incompatible, in which case the range
is foldable to FALSE independently of the foldability of the field.

But we shouldn't try and fold the bounds to find out. Calling
`foldable` really shouldn't already perform folding.

Instead, only perform the check for the invalid bounds if the bounds are
already literals. This means that folding will still take place, but it
requires the range's child expressions to be folded first.

That being said, Range is not used until the physical optimizer stage,
anyway.
@alex-spies alex-spies added auto-backport Automatically create backport pull requests when merged >tech debt :Analytics/ES|QL AKA ESQL v9.0.0 v8.18.0 labels Jan 8, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Jan 8, 2025
@elasticsearchmachine
Copy link
Collaborator

Hi @alex-spies, I've created a changelog YAML for you.

/**
* In case that the boundaries are not yet folded, but turn out to be invalid after folding, this will still return {@code false}.
* That's because we shouldn't perform folding when trying to determine foldability.
*/
@Override
public boolean foldable() {
Copy link
Member

Choose a reason for hiding this comment

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

If ES|QL coordinator/logicalplanner will not see Range, it is only visible at data node, I wonder if it is a good idea to just return false or an exception if the foldable() or fold() on Range is called?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was contemplating just ripping out Range-related code that is currently dead. There's also code in the PropagateEquals optimizer rule that uses Ranges that we know is actually dead because Ranges are only created in the physical optimizer stage.

I think returning false here would be wrong (as we'd break the Expression contract); throwing UnsupportedOperationException would be okay in theory, but I'm hesitant about it since we could still be making calls to foldable/fold in the physical optimizer stage, where ranges are being used. Maybe we don't! But determining this requires careful analysis.

For this reason, I'm leaning towards implementing Range's methods correctly, even though they may be unused.

What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/ES|QL AKA ESQL auto-backport Automatically create backport pull requests when merged Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) >tech debt v8.18.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants