use of com.facebook.presto.common.type.MapType in project presto by prestodb.
the class StorageTypeConverter method toStorageType.
public Type toStorageType(Type type) {
Type storageType;
if (type.equals(BOOLEAN) || type.equals(BIGINT) || type.equals(INTEGER) || type.equals(SMALLINT) || type.equals(TINYINT) || type.equals(DOUBLE) || type.equals(REAL) || type.equals(DATE) || isCharType(type) || isVarcharType(type) || isLongDecimal(type) || isShortDecimal(type) || type.equals(VARBINARY)) {
storageType = type;
} else // Check OrcType::toOrcType() for reference.
if (type.equals(TIME) || type.equals(TIMESTAMP)) {
storageType = BIGINT;
} else if (type instanceof ArrayType) {
storageType = new ArrayType(toStorageType(((ArrayType) type).getElementType()));
} else if (type instanceof MapType) {
storageType = mapType(toStorageType(((MapType) type).getKeyType()), toStorageType(((MapType) type).getValueType()));
} else {
throw new PrestoException(NOT_SUPPORTED, "Type not supported: " + type);
}
// We cannot write different java types because when Raptor calculates stats, it uses the column types rather than storage types.
// Need to make sure min/max are compliant with both storage and column types.
checkState(storageType.getJavaType().equals(type.getJavaType()));
return storageType;
}
use of com.facebook.presto.common.type.MapType in project presto by prestodb.
the class ParquetSchemaConverter method getMapType.
private org.apache.parquet.schema.Type getMapType(MapType type, String name, List<String> parent) {
parent = ImmutableList.<String>builder().addAll(parent).add(name).add("key_value").build();
Type keyType = type.getKeyType();
Type valueType = type.getValueType();
return Types.map(OPTIONAL).key(convert(keyType, "key", parent)).value(convert(valueType, "value", parent)).named(name);
}
use of com.facebook.presto.common.type.MapType in project presto by prestodb.
the class StructuralTestUtil method mapBlockOf.
public static Block mapBlockOf(Type keyType, Type valueType, Object[] keys, Object[] values) {
checkArgument(keys.length == values.length, "keys/values must have the same length");
MapType mapType = mapType(keyType, valueType);
BlockBuilder blockBuilder = mapType.createBlockBuilder(null, 10);
BlockBuilder singleMapBlockWriter = blockBuilder.beginBlockEntry();
for (int i = 0; i < keys.length; i++) {
Object key = keys[i];
Object value = values[i];
appendToBlockBuilder(keyType, key, singleMapBlockWriter);
appendToBlockBuilder(valueType, value, singleMapBlockWriter);
}
blockBuilder.closeEntry();
return mapType.getObject(blockBuilder, 0);
}
use of com.facebook.presto.common.type.MapType in project presto by prestodb.
the class TestObjectInputDecoders method testBlockObjectDecoders.
@Test
public void testBlockObjectDecoders() {
ObjectInputDecoder decoder;
decoder = createDecoder(new ArrayType(BIGINT), typeManager);
assertTrue(decoder instanceof ObjectInputDecoders.ArrayObjectInputDecoder);
assertEquals(((ArrayList) decoder.decode(createLongArrayBlock())).get(0), 2L);
decoder = createDecoder(new MapType(BIGINT, BIGINT, methodHandle(TestRowType.class, "throwUnsupportedOperation"), methodHandle(TestRowType.class, "throwUnsupportedOperation")), typeManager);
assertTrue(decoder instanceof ObjectInputDecoders.MapObjectInputDecoder);
HashMap map = (HashMap) decoder.decode(createLongArrayBlock());
assertEquals(map.get(2L), 1L);
}
use of com.facebook.presto.common.type.MapType in project presto by prestodb.
the class AbstractTestHiveClient method assertValueTypes.
private static void assertValueTypes(MaterializedRow row, List<ColumnMetadata> schema) {
for (int columnIndex = 0; columnIndex < schema.size(); columnIndex++) {
ColumnMetadata column = schema.get(columnIndex);
Object value = row.getField(columnIndex);
if (value != null) {
if (BOOLEAN.equals(column.getType())) {
assertInstanceOf(value, Boolean.class);
} else if (TINYINT.equals(column.getType())) {
assertInstanceOf(value, Byte.class);
} else if (SMALLINT.equals(column.getType())) {
assertInstanceOf(value, Short.class);
} else if (INTEGER.equals(column.getType())) {
assertInstanceOf(value, Integer.class);
} else if (BIGINT.equals(column.getType())) {
assertInstanceOf(value, Long.class);
} else if (DOUBLE.equals(column.getType())) {
assertInstanceOf(value, Double.class);
} else if (REAL.equals(column.getType())) {
assertInstanceOf(value, Float.class);
} else if (isVarcharType(column.getType())) {
assertInstanceOf(value, String.class);
} else if (isCharType(column.getType())) {
assertInstanceOf(value, String.class);
} else if (VARBINARY.equals(column.getType())) {
assertInstanceOf(value, SqlVarbinary.class);
} else if (TIMESTAMP.equals(column.getType())) {
assertInstanceOf(value, SqlTimestamp.class);
} else if (DATE.equals(column.getType())) {
assertInstanceOf(value, SqlDate.class);
} else if (column.getType() instanceof ArrayType || column.getType() instanceof RowType) {
assertInstanceOf(value, List.class);
} else if (column.getType() instanceof MapType) {
assertInstanceOf(value, Map.class);
} else {
fail("Unknown primitive type " + columnIndex);
}
}
}
}
Aggregations