-
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
Avoid writing NaN and Infinity with json format table #24558
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ | |
import io.trino.hive.formats.line.Column; | ||
import io.trino.hive.formats.line.LineSerializer; | ||
import io.trino.spi.Page; | ||
import io.trino.spi.StandardErrorCode; | ||
import io.trino.spi.TrinoException; | ||
import io.trino.spi.block.Block; | ||
import io.trino.spi.block.SqlMap; | ||
import io.trino.spi.block.SqlRow; | ||
|
@@ -120,10 +122,26 @@ else if (type instanceof DecimalType decimalType) { | |
}; | ||
} | ||
else if (REAL.equals(type)) { | ||
return (generator, block, position) -> generator.writeNumber(REAL.getFloat(block, position)); | ||
return (generator, block, position) -> { | ||
float value = REAL.getFloat(block, position); | ||
if (!Float.isNaN(value) && !Float.isInfinite(value)) { | ||
generator.writeNumber(value); | ||
} | ||
Comment on lines
+127
to
+129
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Same apply to |
||
else { | ||
throw new TrinoException(StandardErrorCode.INVALID_JSON_LITERAL, "Invalid value to Insert Real " + value); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would prefer to add |
||
} | ||
}; | ||
} | ||
else if (DOUBLE.equals(type)) { | ||
return (generator, block, position) -> generator.writeNumber(DOUBLE.getDouble(block, position)); | ||
return (generator, block, position) -> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about REAL type? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'NaN' and 'Infinity' getting casted as Double it seems. It goes through double datatype. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. Please try There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay |
||
Double value = DOUBLE.getDouble(block, position); | ||
if (!Double.isNaN(value) && !Double.isInfinite(value)) { | ||
generator.writeNumber(value); | ||
} | ||
else { | ||
throw new TrinoException(StandardErrorCode.INVALID_JSON_LITERAL, "Invalid value to Insert " + value); | ||
} | ||
}; | ||
} | ||
else if (DATE.equals(type)) { | ||
return (generator, block, position) -> generator.writeString(HiveFormatUtils.formatHiveDate(block, position)); | ||
|
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.
Similar logic is also in
createMapKeyFunction(Type type)
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.
even though they will not break as these, but still worth discussing on how those values supposed to be read back especially considering cases like duplicate map keys of NaN etc., or just leave them as is and that the downstream consumer decide
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.
In other cases, we've preferred to emulate the Hive SerDe behavior. What happens in Hive if you serialize maps with
NaN
/Infinite
/-Infinite
keys there, @sug-ghosh ?