Skip to content

Commit

Permalink
Avoid writing NaN and Infinity with json format table
Browse files Browse the repository at this point in the history
  • Loading branch information
sug-ghosh committed Jan 10, 2025
1 parent a401e37 commit 846c640
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.isFinite(value)) {
generator.writeNumber(value);
}
else {
throw new TrinoException(StandardErrorCode.INVALID_JSON_LITERAL, "Invalid value to Insert Real: " + value);
}
};
}
else if (DOUBLE.equals(type)) {
return (generator, block, position) -> generator.writeNumber(DOUBLE.getDouble(block, position));
return (generator, block, position) -> {
Double value = DOUBLE.getDouble(block, position);
if (Double.isFinite(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));
Expand Down

0 comments on commit 846c640

Please sign in to comment.