Skip to content

ESQL: Fix LIMIT NPE with null value#130914

Merged
ivancea merged 8 commits intoelastic:mainfrom
ivancea:fix-limit-npe
Jul 10, 2025
Merged

ESQL: Fix LIMIT NPE with null value#130914
ivancea merged 8 commits intoelastic:mainfrom
ivancea:fix-limit-npe

Conversation

@ivancea
Copy link
Contributor

@ivancea ivancea commented Jul 9, 2025

Fixes #130908

@ivancea ivancea requested a review from luigidellaquila July 9, 2025 12:28
@ivancea ivancea added >bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) auto-backport Automatically create backport pull requests when merged :Analytics/ES|QL AKA ESQL v9.2.0 v9.1.1 v8.19.1 labels Jul 9, 2025
@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine
Copy link
Collaborator

Hi @ivancea, I've created a changelog YAML for you.

Copy link
Contributor

@luigidellaquila luigidellaquila left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @ivancea !

@ivancea ivancea enabled auto-merge (squash) July 9, 2025 12:35
Copy link
Contributor

@astefan astefan left a comment

Choose a reason for hiding this comment

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

Nice catch!
I have a suggested a slightly different approach with the error message. The difference is that LIMIT NuLL and LIMIT null and LIMIT nuLL will each have a different error message which uses the exact text that was used in the query.

The PR in its current form will always create an error message Invalid value for LIMIT [null] no matter if the query used null, NuLL or nuLL.

Comment on lines 401 to 402
} else if (val == null) {
throw new ParsingException(source, "Invalid value for LIMIT [null], expecting a non negative integer");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
} else if (val == null) {
throw new ParsingException(source, "Invalid value for LIMIT [null], expecting a non negative integer");
} else {
String valueAsString;
if (val == null) {
valueAsString = ctx.constant().getText();
} else {
valueAsString = BytesRefs.toString(val)
+ ": "
+ (expression(ctx.constant()).dataType() == KEYWORD ? "String" : val.getClass().getSimpleName());
}
throw new ParsingException(source, "Invalid value for LIMIT [" + valueAsString + "], expecting a non negative integer");
}
@ivancea ivancea disabled auto-merge July 9, 2025 13:12
Copy link
Contributor

@astefan astefan left a comment

Choose a reason for hiding this comment

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

Much better and thank you for the additional tests 👍.
LGTM

@ivancea ivancea enabled auto-merge (squash) July 10, 2025 09:08
ivancea and others added 2 commits July 10, 2025 11:12
# Conflicts:
#	x-pack/plugin/build.gradle
#	x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/ParsingTests.java
@ivancea ivancea merged commit 1196ccb into elastic:main Jul 10, 2025
34 checks passed
@ivancea ivancea deleted the fix-limit-npe branch July 10, 2025 15:41
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
9.1 Commit could not be cherrypicked due to conflicts
8.19 Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 130914

ivancea added a commit to ivancea/elasticsearch that referenced this pull request Jul 10, 2025
ivancea added a commit to ivancea/elasticsearch that referenced this pull request Jul 10, 2025
ivancea added a commit that referenced this pull request Jul 11, 2025
ivancea added a commit that referenced this pull request Jul 11, 2025
mridula-s109 pushed a commit to mridula-s109/elasticsearch that referenced this pull request Jul 17, 2025
mridula-s109 pushed a commit to mridula-s109/elasticsearch that referenced this pull request Jul 17, 2025
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 >bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v8.19.1 v9.1.1 v9.2.0

5 participants