use of io.trino.spi.type.TinyintType in project trino by trinodb.
the class TestHiveBucketing method toNativeContainerValue.
private static Object toNativeContainerValue(Type type, Object hiveValue) {
if (hiveValue == null) {
return null;
}
if (type instanceof ArrayType) {
BlockBuilder blockBuilder = type.createBlockBuilder(null, 1);
BlockBuilder subBlockBuilder = blockBuilder.beginBlockEntry();
for (Object subElement : (Iterable<?>) hiveValue) {
appendToBlockBuilder(type.getTypeParameters().get(0), subElement, subBlockBuilder);
}
blockBuilder.closeEntry();
return type.getObject(blockBuilder, 0);
}
if (type instanceof RowType) {
BlockBuilder blockBuilder = type.createBlockBuilder(null, 1);
BlockBuilder subBlockBuilder = blockBuilder.beginBlockEntry();
int field = 0;
for (Object subElement : (Iterable<?>) hiveValue) {
appendToBlockBuilder(type.getTypeParameters().get(field), subElement, subBlockBuilder);
field++;
}
blockBuilder.closeEntry();
return type.getObject(blockBuilder, 0);
}
if (type instanceof MapType) {
BlockBuilder blockBuilder = type.createBlockBuilder(null, 1);
BlockBuilder subBlockBuilder = blockBuilder.beginBlockEntry();
for (Entry<?, ?> entry : ((Map<?, ?>) hiveValue).entrySet()) {
appendToBlockBuilder(type.getTypeParameters().get(0), entry.getKey(), subBlockBuilder);
appendToBlockBuilder(type.getTypeParameters().get(1), entry.getValue(), subBlockBuilder);
}
blockBuilder.closeEntry();
return type.getObject(blockBuilder, 0);
}
if (type instanceof BooleanType) {
return hiveValue;
}
if (type instanceof TinyintType) {
return (long) (byte) hiveValue;
}
if (type instanceof SmallintType) {
return (long) (short) hiveValue;
}
if (type instanceof IntegerType) {
return (long) (int) hiveValue;
}
if (type instanceof BigintType) {
return hiveValue;
}
if (type instanceof RealType) {
return (long) Float.floatToRawIntBits((float) hiveValue);
}
if (type instanceof DoubleType) {
return hiveValue;
}
if (type instanceof VarcharType) {
return Slices.utf8Slice(hiveValue.toString());
}
if (type instanceof DateType) {
return (long) ((Date) hiveValue).toEpochDay();
}
throw new IllegalArgumentException("Unsupported bucketing type: " + type);
}
Aggregations