Skip to content

ESQL: NPE when converting NULL in IN clause #119950

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

Closed
bpintea opened this issue Jan 10, 2025 · 1 comment · Fixed by #125832
Closed

ESQL: NPE when converting NULL in IN clause #119950

bpintea opened this issue Jan 10, 2025 · 1 comment · Fixed by #125832
Labels
:Analytics/ES|QL AKA ESQL >bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo)

Comments

@bpintea
Copy link
Contributor

bpintea commented Jan 10, 2025

Description

A corner case.

This works:

ROW x = NULL | EVAL x::INT

Also this:

FROM employees | WHERE emp_no IN (10001, NULL)

But this:

FROM employees | WHERE emp_no IN (10001, NULL::INT)

fails with a query_shard_exception NPE:

Caused by: java.lang.NullPointerException: Cannot invoke \"Object.toString()\" because \"value\" is null
	at [email protected]/org.elasticsearch.index.mapper.NumberFieldMapper$NumberType.objectToDouble(NumberFieldMapper.java:1493)
	at [email protected]/org.elasticsearch.index.mapper.NumberFieldMapper$NumberType$6.parse(NumberFieldMapper.java:1035)
	at [email protected]/org.elasticsearch.index.mapper.NumberFieldMapper$NumberType$6.termsQuery(NumberFieldMapper.java:1090)
	at [email protected]/org.elasticsearch.index.mapper.NumberFieldMapper$NumberFieldType.termsQuery(NumberFieldMapper.java:1733)
	at [email protected]/org.elasticsearch.index.query.TermsQueryBuilder.doToQuery(TermsQueryBuilder.java:347)
	at [email protected]/org.elasticsearch.index.query.AbstractQueryBuilder.toQuery(AbstractQueryBuilder.java:119)
	at org.elasticsearch.xpack.esql.querydsl.query.SingleValueQuery$Builder.doToQuery(SingleValueQuery.java:187)
	at [email protected]/org.elasticsearch.index.query.AbstractQueryBuilder.toQuery(AbstractQueryBuilder.java:119)
	at [email protected]/org.elasticsearch.index.query.SearchExecutionContext.toQuery(SearchExecutionContext.java:559)
	... 123 more
@bpintea bpintea changed the title ESQL: NPE when converting NULL to DATETIMEsin IN clause ESQL: NPE when converting NULL to DATETIME in IN clause Jan 10, 2025
@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Jan 10, 2025
@elasticsearchmachine
Copy link
Collaborator

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

@bpintea bpintea changed the title ESQL: NPE when converting NULL to DATETIME in IN clause ESQL: NPE when converting NULL in IN clause Jan 10, 2025
@elastic elastic deleted a comment from DHRUV6029 Mar 31, 2025
nik9000 pushed a commit to nik9000/elasticsearch that referenced this issue May 1, 2025
This PR fixes elastic#119950 where an `IN` query includes `NULL` values with non-NULL `DataType` appearing within the query range. An expression is considered `NULL` when its `DataType` is `NULL` or it is a `Literal` with a value of `null`.
nik9000 added a commit that referenced this issue May 1, 2025
* ESQL: Allow the data type of `null` in filters (#118324)

* Allow the data type of `null` in filters

* ESQL: Fix `NULL` handling in `IN` clause (#125832)

This PR fixes #119950 where an `IN` query includes `NULL` values with non-NULL `DataType` appearing within the query range. An expression is considered `NULL` when its `DataType` is `NULL` or it is a `Literal` with a value of `null`.

* Revert formatting

---------

Co-authored-by: kanoshiou <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/ES|QL AKA ESQL >bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants