-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Handle edge cases when converting double from JSON to Trino types #24030
base: master
Are you sure you want to change the base?
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
Currently, we are unable to optimise tables when they contain infinity/NaN values in fields of type "DOUBLE" because the conversion fails when we try to cast a string containing "Infinity", "-Infinity" or "NaN" into a double. Instead, we try to check if the JSON value contains a string, and convert it appropriately.
11f405a
to
bf16c90
Compare
Tagging @ebyhr as the original author and @findepi as the original commentor of this prescient review comment 😄 |
Note that this is mostly a first draft for inputs & review, we'll need to add tests, but I wanted to first check that you agree with the approach and check if you had a better way to do it. |
@Pluies This approach looks good to me. Could you please start adding tests? |
if (jsonValue instanceof String) { | ||
switch ((String) jsonValue) { |
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.
if (jsonValue instanceof String) { | |
switch ((String) jsonValue) { | |
if (jsonValue instanceof String stringValue) { | |
switch (stringValue) { |
case "-Infinity" -> { | ||
return Double.NEGATIVE_INFINITY; | ||
} | ||
case "NaN" -> { |
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.
can it be nan
or NAN
?
@@ -127,6 +127,20 @@ public static Object jsonValueToTrinoValue(Type type, @Nullable Object jsonValue | |||
return (long) floatToRawIntBits((float) (double) jsonValue); | |||
} | |||
if (type == DOUBLE) { | |||
if (jsonValue instanceof String) { | |||
switch ((String) jsonValue) { | |||
case "Infinity" -> { |
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.
can it be inf
(besides case differences)?
Description
Currently, we are unable to optimise tables when they contain infinity/NaN values in fields of type "DOUBLE" because the conversion fails when we try to cast a string containing "Infinity", "-Infinity" or "NaN" into a double.
Instead, we try to check if the JSON value contains a string, and convert it appropriately.
Additional context and related issues
Fixes #24029
Release notes
( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
(x) Release notes are required, with the following suggested text: