Skip to content

ESQL: Allow the data type of null in filters #118324

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

Merged
merged 12 commits into from
Jan 8, 2025

Conversation

kanoshiou
Copy link
Contributor

Allow filter null in ESQL.

Closes #116351

@elasticsearchmachine elasticsearchmachine added needs:triage Requires assignment of a team area label v9.0.0 external-contributor Pull request authored by a developer outside the Elasticsearch team labels Dec 10, 2024
@kanoshiou
Copy link
Contributor Author

I think I should write another test where the result is empty when where null is used, but I don't know which file to write it in.

@arteam arteam added the :Analytics/ES|QL AKA ESQL label Dec 10, 2024
@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Dec 10, 2024
@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine elasticsearchmachine removed the needs:triage Requires assignment of a team area label label Dec 10, 2024
@fang-xing-esql fang-xing-esql self-assigned this Dec 12, 2024
@fang-xing-esql
Copy link
Member

I think I should write another test where the result is empty when where null is used, but I don't know which file to write it in.

Thank you for contributing to Elasticsearch.

You may add more complicated queries in some of the csv-spec files under here to validate the query returns correct results. For example, the null.csv-spec could be a good place to add null related queries.

And you may also add more complicated queries to LogicalPlanOptimizerTests to validate the query plans sent from coordinator node to the data nodes are as expected.

As this change affects the behavior of the targeting queries on different Elasticsearch versions, backward compatibility should also be taken into account.

@kanoshiou
Copy link
Contributor Author

Thank you for your detailed guidance @fang-xing-esql !

I have added some tests, but I am not sure if they meet the requirements. Please let me know if any changes are needed.

@fang-xing-esql
Copy link
Member

Thank you for your detailed guidance @fang-xing-esql !

I have added some tests, but I am not sure if they meet the requirements. Please let me know if any changes are needed.

Thank you for adding more tests @kanoshiou! We have a couple of more suggestions and then this PR is in a good shape.

  • NULL is a DataType in ES|QL, and ES|QL also has other DataTypes that can contain NULL values. A predicate can be boolean type or null type, the other DataTypes are not supported. It will be great to have some negative test cases to cover more DataTypes with NULL values. Here is one example, and you may add more to cover more DataTypes like numeric, string, datetime etc. FROM t | where null::string. These negative tests can be added in VerifierTests.

  • Users can provided null directly under WHERE clause, and they can also provide null in EVAL. It will be great to have tests to cover scenarios like this - FROM t | EVAL x = null | WHERE x, and mixed with different DataTypes .

  • There are a couple of places in Verifier that check the predicate types. One is under checkFilterConditionType that you have fixed, the other is under checkInvalidNamedExpressionUsage, it will be great to refactor them into one place so that it is easier to maintain the consistency going forward.

@kanoshiou
Copy link
Contributor Author

Thank you for your guidance and support on the PR, @fang-xing-esql!

If my test cases have any omissions, please let me know. I'm happy to add them. 😊

Copy link
Member

@fang-xing-esql fang-xing-esql left a comment

Choose a reason for hiding this comment

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

Thank you @kanoshiou! I left a small comment, the rest looks good.

@kanoshiou
Copy link
Contributor Author

Thank you for reviewing, @fang-xing-esql !

I've updated the branch according to your comment.

@fang-xing-esql
Copy link
Member

buildkite test this

@kanoshiou
Copy link
Contributor Author

kanoshiou commented Jan 2, 2025

Hi @fang-xing-esql ,

I tried the command in buildkite to reproduce the failure on my local machine, but no exception was thrown. This is quite puzzling.

@fang-xing-esql
Copy link
Member

buildkite test this

@fang-xing-esql
Copy link
Member

buildkite test this

@kanoshiou
Copy link
Contributor Author

I believe the failed tests are unrelated to my code changes, @fang-xing-esql .

I’ve merged the latest code into my branch. The first failed test case has been muted by #119510, and I have tested the remaining two failed tests; they passed successfully.

Hope the tests pass this time. 🤞

@fang-xing-esql
Copy link
Member

buildkite test this

@fang-xing-esql
Copy link
Member

buildkite test this

Copy link
Member

@fang-xing-esql fang-xing-esql left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution to elasticsearch @kanoshiou! Looks good to me.

@kanoshiou
Copy link
Contributor Author

Thank you for approving this PR @fang-xing-esql! Just a gentle reminder in case you forget to click the merge button.

@fang-xing-esql fang-xing-esql merged commit deeeadc into elastic:main Jan 8, 2025
15 checks passed
nik9000 pushed a commit to nik9000/elasticsearch that referenced this pull request May 1, 2025
* Allow the data type of `null` in filters
nik9000 added a commit that referenced this pull request 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 external-contributor Pull request authored by a developer outside the Elasticsearch team Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ES|QL] where null throws VerificationException when it is not under an aggregation
4 participants