-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Validate literals in expression analyzer #10720
Validate literals in expression analyzer #10720
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please cover also:
GenericLiteral
with typeJSON
,IntervalLiteral
In fact, you could use LiteralInterpreter
for the validation.
I thought about that, i chose not to, because i already have resolved coercion at hand, so |
4ee442d
to
d3670d8
Compare
switched over to LiteralInterpreter, as otherwise JSON verification would be cumbersome
added |
// json | ||
assertFails("SELECT JSON ''") | ||
.hasErrorCode(INVALID_LITERAL); | ||
// TODO https://github.com/trinodb/trino/issues/10724 these should fail |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d3670d8
to
bc3af3f
Compare
// TODO (https://github.com/trinodb/trino/issues/10732) the expressions here may fail or not, depending whether they are wrapped | ||
// should deterministically fail with NUMERIC_VALUE_OUT_OF_RANGE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bc3af3f
to
bc0899b
Compare
@@ -5440,7 +5440,7 @@ public void testTry() | |||
assertQuery("SELECT apply(5 + RANDOM(1), x -> x + TRY(1 / 0))", "SELECT NULL"); | |||
|
|||
// test try with invalid JSON | |||
assertQuery("SELECT JSON_FORMAT(TRY(JSON 'INVALID'))", "SELECT NULL"); | |||
assertQueryFails("SELECT JSON_FORMAT(TRY(JSON 'INVALID'))", "line 1:24: 'INVALID' is not a valid json literal"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a behavioral change, but IMO justified.
@@ -5455,7 +5455,7 @@ public void testTry() | |||
assertQuery("SELECT COALESCE(TRY(CAST(CONCAT('a', CAST(123 AS VARCHAR)) AS BIGINT)), 0)", "SELECT 0L"); | |||
assertQuery("SELECT 123 + TRY(ABS(-9223372036854775807 - 1))", "SELECT NULL"); | |||
assertQuery("SELECT JSON_FORMAT(TRY(JSON '[]')) || '123'", "SELECT '[]123'"); | |||
assertQuery("SELECT JSON_FORMAT(TRY(JSON 'INVALID')) || '123'", "SELECT NULL"); | |||
assertQueryFails("SELECT JSON_FORMAT(TRY(JSON 'INVALID')) || '123'", "line 1:24: 'INVALID' is not a valid json literal"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a behavioral change -- see above.
rebased to resolve conflict with #10737 |
0a7d720
to
26dbcac
Compare
To be rebased after #10783 is merged. |
26dbcac
to
4d65d6c
Compare
rebased after #10783 merged (no changes yet) |
As a result, optimizer can safely assume a `Literal` to represent a value of given type. Also, queries with invalid literal values should be guaranteed to fail, regardless of expression pruning.
4d65d6c
to
d4dc855
Compare
As a result, optimizer can safely assume a
Literal
to represent avalue of given type. Also, queries with invalid literal values should be
guaranteed to fail, regardless of expression pruning.
Fixes #10719
Fixes #10755