Skip to content
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

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
import io.trino.spi.ErrorType;

import static io.trino.spi.ErrorType.EXTERNAL;
import static io.trino.spi.ErrorType.USER_ERROR;

// these error codes must match the error codes in HiveErrorCode
public enum HiveFormatsErrorCode
implements ErrorCodeSupplier
{
HIVE_INVALID_METADATA(12, EXTERNAL),
HIVE_UNSERIALIZABLE_JSON_VALUE(44, USER_ERROR),
/**/;

private final ErrorCode errorCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
import com.fasterxml.jackson.core.io.SerializedString;
import io.airlift.slice.SliceOutput;
import io.trino.hive.formats.HiveFormatUtils;
import io.trino.hive.formats.HiveFormatsErrorCode;
import io.trino.hive.formats.line.Column;
import io.trino.hive.formats.line.LineSerializer;
import io.trino.spi.Page;
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)) {
sug-ghosh marked this conversation as resolved.
Show resolved Hide resolved
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(HiveFormatsErrorCode.HIVE_UNSERIALIZABLE_JSON_VALUE, "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) -> {
sug-ghosh marked this conversation as resolved.
Show resolved Hide resolved
Double value = DOUBLE.getDouble(block, position);
if (Double.isFinite(value)) {
generator.writeNumber(value);
}
else {
throw new TrinoException(HiveFormatsErrorCode.HIVE_UNSERIALIZABLE_JSON_VALUE, "Invalid value to Insert: " + value);
}
};
}
else if (DATE.equals(type)) {
return (generator, block, position) -> generator.writeString(HiveFormatUtils.formatHiveDate(block, position));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public enum HiveErrorCode
HIVE_VIEW_TRANSLATION_ERROR(41, EXTERNAL),
HIVE_PARTITION_NOT_FOUND(42, USER_ERROR),
HIVE_INVALID_TIMESTAMP_COERCION(43, EXTERNAL),
HIVE_UNSERIALIZABLE_JSON_VALUE(44, USER_ERROR),
sug-ghosh marked this conversation as resolved.
Show resolved Hide resolved
/**/;

private final ErrorCode errorCode;
Expand Down
Loading