Skip to content
Merged
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 @@ -27,6 +27,7 @@
import io.trino.spi.type.ArrayType;
import io.trino.spi.type.DecimalType;
import io.trino.spi.type.Decimals;
import io.trino.spi.type.Int128;
import io.trino.spi.type.LongTimestampWithTimeZone;
import io.trino.spi.type.RowType;
import io.trino.spi.type.Type;
Expand Down Expand Up @@ -190,6 +191,9 @@ else if (type.equals(TIME_MICROS)) {
else if (javaType == double.class) {
type.writeDouble(output, ((Number) value).doubleValue());
}
else if (type.getJavaType() == Int128.class) {
writeObject(output, type, value);
}
else if (javaType == Slice.class) {
writeSlice(output, type, value);
}
Expand Down Expand Up @@ -217,12 +221,6 @@ private static void writeSlice(BlockBuilder output, Type type, Object value)
if (type instanceof VarcharType) {
type.writeSlice(output, utf8Slice(((Utf8) value).toString()));
}
else if (type instanceof DecimalType) {
verify(isLongDecimal(type), "The type should be long decimal");
DecimalType decimalType = (DecimalType) type;
BigDecimal decimal = DECIMAL_CONVERTER.convert(decimalType.getPrecision(), decimalType.getScale(), value);
type.writeObject(output, Decimals.encodeScaledValue(decimal, decimalType.getScale()));
}
else if (type instanceof VarbinaryType) {
if (value instanceof ByteBuffer) {
type.writeSlice(output, Slices.wrappedBuffer((ByteBuffer) value));
Expand All @@ -236,6 +234,19 @@ else if (type instanceof VarbinaryType) {
}
}

private static void writeObject(BlockBuilder output, Type type, Object value)
{
if (type instanceof DecimalType) {
verify(isLongDecimal(type), "The type should be long decimal");
DecimalType decimalType = (DecimalType) type;
BigDecimal decimal = DECIMAL_CONVERTER.convert(decimalType.getPrecision(), decimalType.getScale(), value);
type.writeObject(output, Decimals.encodeScaledValue(decimal, decimalType.getScale()));
}
else {
throw new TrinoException(GENERIC_INTERNAL_ERROR, "Unhandled type for Object: " + type.getTypeSignature());
}
}

private void writeBlock(BlockBuilder output, Type type, Object value)
{
if (type instanceof ArrayType && value instanceof List<?>) {
Expand Down