use of io.prestosql.spi.type.MapType in project hetu-core by openlookeng.
the class MapUnionAggregation method specialize.
@Override
public InternalAggregationFunction specialize(BoundVariables boundVariables, int arity, FunctionAndTypeManager functionAndTypeManager) {
Type keyType = boundVariables.getTypeVariable("K");
Type valueType = boundVariables.getTypeVariable("V");
MapType outputType = (MapType) functionAndTypeManager.getParameterizedType(StandardTypes.MAP, ImmutableList.of(TypeSignatureParameter.of(keyType.getTypeSignature()), TypeSignatureParameter.of(valueType.getTypeSignature())));
return generateAggregation(keyType, valueType, outputType);
}
use of io.prestosql.spi.type.MapType in project hetu-core by openlookeng.
the class StructuralTestUtil method mapBlockOf.
public static Block mapBlockOf(Type keyType, Type valueType, Object key, Object value) {
MapType mapType = mapType(keyType, valueType);
BlockBuilder blockBuilder = mapType.createBlockBuilder(null, 10);
BlockBuilder singleMapBlockWriter = blockBuilder.beginBlockEntry();
appendToBlockBuilder(keyType, key, singleMapBlockWriter);
appendToBlockBuilder(valueType, value, singleMapBlockWriter);
blockBuilder.closeEntry();
return mapType.getObject(blockBuilder, 0);
}
use of io.prestosql.spi.type.MapType in project boostkit-bigdata by kunpengcompute.
the class AbstractTestHive 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);
}
}
}
}
use of io.prestosql.spi.type.MapType in project boostkit-bigdata by kunpengcompute.
the class TestParquetPredicateUtils method testParquetTupleDomainMap.
@Test
public void testParquetTupleDomainMap() {
HiveColumnHandle columnHandle = new HiveColumnHandle("my_map", HiveType.valueOf("map<int,int>"), parseTypeSignature(StandardTypes.MAP), 0, REGULAR, Optional.empty());
MapType mapType = new MapType(INTEGER, INTEGER, methodHandle(TestParquetPredicateUtils.class, "throwUnsupportedOperationException"), methodHandle(TestParquetPredicateUtils.class, "throwUnsupportedOperationException"), methodHandle(TestParquetPredicateUtils.class, "throwUnsupportedOperationException"), methodHandle(TestParquetPredicateUtils.class, "throwUnsupportedOperationException"));
TupleDomain<HiveColumnHandle> domain = withColumnDomains(ImmutableMap.of(columnHandle, Domain.notNull(mapType)));
MessageType fileSchema = new MessageType("hive_schema", new GroupType(OPTIONAL, "my_map", new GroupType(REPEATED, "map", new PrimitiveType(REQUIRED, INT32, "key"), new PrimitiveType(OPTIONAL, INT32, "value"))));
Map<List<String>, RichColumnDescriptor> descriptorsByPath = getDescriptors(fileSchema, fileSchema);
TupleDomain<ColumnDescriptor> tupleDomain = ParquetPageSourceFactory.getParquetTupleDomain(descriptorsByPath, domain);
assertTrue(tupleDomain.getDomains().get().isEmpty());
}
use of io.prestosql.spi.type.MapType in project boostkit-bigdata by kunpengcompute.
the class ParquetColumnIOConverter method constructField.
public static Optional<Field> constructField(Type type, ColumnIO columnIO) {
if (columnIO == null) {
return Optional.empty();
}
boolean required = columnIO.getType().getRepetition() != OPTIONAL;
int repetitionLevel = columnRepetitionLevel(columnIO);
int definitionLevel = columnDefinitionLevel(columnIO);
if (ROW.equals(type.getTypeSignature().getBase())) {
GroupColumnIO groupColumnIO = (GroupColumnIO) columnIO;
List<Type> parameters = type.getTypeParameters();
ImmutableList.Builder<Optional<Field>> fieldsBuilder = ImmutableList.builder();
List<TypeSignatureParameter> fields = type.getTypeSignature().getParameters();
boolean structHasParameters = false;
for (int i = 0; i < fields.size(); i++) {
NamedTypeSignature namedTypeSignature = fields.get(i).getNamedTypeSignature();
String name = namedTypeSignature.getName().get().toLowerCase(Locale.ENGLISH);
Optional<Field> field = constructField(parameters.get(i), lookupColumnByName(groupColumnIO, name));
structHasParameters |= field.isPresent();
fieldsBuilder.add(field);
}
if (structHasParameters) {
return Optional.of(new GroupField(type, repetitionLevel, definitionLevel, required, fieldsBuilder.build()));
}
return Optional.empty();
}
if (MAP.equals(type.getTypeSignature().getBase())) {
GroupColumnIO groupColumnIO = (GroupColumnIO) columnIO;
MapType mapType = (MapType) type;
GroupColumnIO keyValueColumnIO = getMapKeyValueColumn(groupColumnIO);
if (keyValueColumnIO.getChildrenCount() != 2) {
return Optional.empty();
}
Optional<Field> keyField = constructField(mapType.getKeyType(), keyValueColumnIO.getChild(0));
Optional<Field> valueField = constructField(mapType.getValueType(), keyValueColumnIO.getChild(1));
return Optional.of(new GroupField(type, repetitionLevel, definitionLevel, required, ImmutableList.of(keyField, valueField)));
}
if (ARRAY.equals(type.getTypeSignature().getBase())) {
GroupColumnIO groupColumnIO = (GroupColumnIO) columnIO;
List<Type> types = type.getTypeParameters();
if (groupColumnIO.getChildrenCount() != 1) {
return Optional.empty();
}
Optional<Field> field = constructField(types.get(0), getArrayElementColumn(groupColumnIO.getChild(0)));
return Optional.of(new GroupField(type, repetitionLevel, definitionLevel, required, ImmutableList.of(field)));
}
PrimitiveColumnIO primitiveColumnIO = (PrimitiveColumnIO) columnIO;
RichColumnDescriptor column = new RichColumnDescriptor(primitiveColumnIO.getColumnDescriptor(), columnIO.getType().asPrimitiveType());
return Optional.of(new PrimitiveField(type, repetitionLevel, definitionLevel, required, column, primitiveColumnIO.getId()));
}
Aggregations