Skip to content

ESQL: Fix LIMIT NPE with null value - #130914

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

ivancea merged 8 commits into
elastic:mainfrom
ivancea:fix-limit-npe

Conversation

@ivancea

@ivancea ivancea commented Jul 9, 2025

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Collaborator

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

@elasticsearchmachine

Copy link
Copy Markdown
Collaborator

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

@luigidellaquila luigidellaquila left a comment

Copy link
Copy Markdown
Member

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

@astefan astefan left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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

@astefan astefan left a comment •

Copy link
Copy Markdown
Contributor

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
@ivancea
ivancea deleted the fix-limit-npe branch July 10, 2025 15:41
@elasticsearchmachine

Copy link
Copy Markdown
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
verawu pushed a commit to verawu/elasticsearch that referenced this pull request Jul 21, 2026
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NPE in ESQL LIMIT with parameter

5 participants