-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Closed
Labels
:Analytics/ES|QLAKA ESQLAKA ESQL>bugTeam:AnalyticsMeta label for analytical engine team (ESQL/Aggs/Geo)Meta label for analytical engine team (ESQL/Aggs/Geo)v8.15.3v9.0.0
Description
Elasticsearch Version
8.15.1
Installed Plugins
No response
Java Version
bundled
OS Version
Docker
Problem Description
Using a WHERE statement after a CASE clause gives very strange and unexpected behavior. It's somewhat hard to explain, but the steps to reproduce should explain the situation well.
Steps to Reproduce
- Bring up a fresh Docker cluster from scratch, running 8.15.1
- Ingest a few documents:
POST _bulk {"index":{"_index":"test"}} {"val": 1} {"index":{"_index":"test"}} {"val": 2} {"index":{"_index":"test"}} {"val": 3} {"index":{"_index":"test"}} {"val": 4} {"index":{"_index":"test"}} {} // This doc has no value for val - Run a query that includes a
NULLcheck in theCASEclause:POST /_query?format=txt { "query": """ FROM test | KEEP val | EVAL eval = CASE( val == 0, null, val % 2 == 0, "val is even", val % 2 != 0, "val is odd", val IS NULL, "val is null") | SORT val """ } - Observe that the output includes all documents and that the
evalcolumn has a value for all rows but the first:#! No limit defined, adding default limit of [1000] val | eval ---------------+--------------- 0 |null 1 |val is odd 2 |val is even 3 |val is odd 4 |val is even null |val is null - Add a
WHEREclause that operates on theevalcolumn to only include rows whereevalis notnull:POST /_query?format=txt { "query": """ FROM test | KEEP val | EVAL eval = CASE( val == 0, null, val % 2 == 0, "val is even", val % 2 != 0, "val is odd", val IS NULL, "val is null") | SORT val | WHERE eval IS NOT NULL """ } - Observe that the row where
valis0andevalisnullis correctly excluded, but that the row wherevalisnullandevalisval is nullis (incorrectly) missing:#! No limit defined, adding default limit of [1000] val | eval ---------------+--------------- 1 |val is odd 2 |val is even 3 |val is odd 4 |val is even - Change the
WHEREclause that operates on theevalcolumn to useLIKE:POST /_query?format=txt { "query": """ FROM test | KEEP val | EVAL eval = CASE( val == 0, null, val % 2 == 0, "val is even", val % 2 != 0, "val is odd", val IS NULL, "val is null") | SORT val | WHERE eval LIKE "*" """ } - Observe that the row for
evalwith the valueval is nullis still (incorrectly) missing:#! No limit defined, adding default limit of [1000] val | eval ---------------+--------------- 1 |val is odd 2 |val is even 3 |val is odd 4 |val is even - Change the
WHEREclause that operates on theevalcolumn to use a differentLIKEpattern:POST /_query?format=txt { "query": """ FROM test | KEEP val | EVAL eval = CASE( val == 0, null, val % 2 == 0, "val is even", val % 2 != 0, "val is odd", val IS NULL, "val is null") | SORT val | WHERE eval LIKE "value*" """ } - Observe that the row for
evalwith the valueval is nullnow shows correctly:#! No limit defined, adding default limit of [1000] val | eval ---------------+--------------- 1 |val is odd 2 |val is even 3 |val is odd 4 |val is even null |val is null - Revert back to the query used in step 5, but add a
LIMITstatement somewhere before theWHEREstatement:POST /_query?format=txt { "query": """ FROM test | KEEP val | EVAL eval = CASE( val == 0, null, val % 2 == 0, "val is even", val % 2 != 0, "val is odd", val IS NULL, "val is null") | SORT val | LIMIT 10 | WHERE eval IS NOT NULL """ } - Observe that the row for
evalwith the valueval is nullnow shows correctly (where it did not show in step 6):val | eval ---------------+--------------- 1 |val is odd 2 |val is even 3 |val is odd 4 |val is even null |val is null
Conclusion:
The best workaround seems to be to use a LIKE statement with some pattern other than "*" that matches all expected values (which is not always possible). Using the LIMIT fix will not work for large datasets.
Logs (if relevant)
No response
Metadata
Metadata
Assignees
Labels
:Analytics/ES|QLAKA ESQLAKA ESQL>bugTeam:AnalyticsMeta label for analytical engine team (ESQL/Aggs/Geo)Meta label for analytical engine team (ESQL/Aggs/Geo)v8.15.3v9.0.0