-
Notifications
You must be signed in to change notification settings - Fork 153
[BUG] Poor handling of boolean expressions in WHERE clauses #3266
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
Comments
Another parsing exception happens if you compare non-constants with POST _plugins/_sql
{
"query": "SELECT * FROM opensearch_dashboards_sample_data_ecommerce WHERE (total_quantity > 1) = NOT(products.base_price > 10.0)"
} Result: {
"error": {
"reason": "Invalid SQL query",
"details": "No enum constant org.opensearch.sql.legacy.domain.Where.CONN.=",
"type": "IllegalArgumentException"
},
"status": 400
} |
It's annoying to have tests repeatedly output the same issues. An example bug that was found after adding the disableConfigExprs option: opensearch-project/sql#3266 (comment) Signed-off-by: Simeon Widdis <[email protected]>
Ended up disabling |
Another one: if you create an index with a boolean field, then |
What is the bug?
This is a bug for three related issues around booleans in WHERE clauses. I suspect without proof that they all have a similar root cause. All examples here use the ecommerce dataset as an example index, but should be reproducible with any index.
How can one reproduce the bug?
WHERE FALSE
matches all records.Query:
Result:
WHERE NOT(x)
causes an error for any constant boolean.Query:
Result:
The same happens with
WHERE NOT(TRUE)
,WHERE NOT(NOT(FALSE))
,WHERE NOT(FALSE OR TRUE)
, and similar.NOT(NULL)
.Query:
Result:
NOT(NULL)
is equivalent toNULL
, so this whole expression should be equivalent toWHERE NULL
and return no records1.What is the expected behavior?
These expressions should be correctly evaluated and applied. They're somewhat weird examples for human-written queries, but automatic query builders may produce queries like this, especially for
WHERE FALSE
.What is your host/environment?
Do you have any screenshots?
N/A
Do you have any additional context?
Found by the WIP distributed-testing suite. See: #3220
Footnotes
It's worth noting that SQL really uses ternary logic: NULL lives among the typical boolean values and the 3 values generate their own truth tables. This is (for better or for worse) pretty fundamental to SQL's operation and is the principle that TLP is built on. As such, in boolean handling, we should really treat NULL as a bona fide boolean. ↩
The text was updated successfully, but these errors were encountered: