Search in sources :

Example 66 with MapType

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);
}
Also used : MapType(io.prestosql.spi.type.MapType) Type(io.prestosql.spi.type.Type) MapType(io.prestosql.spi.type.MapType)

Example 67 with MapType

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);
}
Also used : MapType(io.prestosql.spi.type.MapType) BlockBuilder(io.prestosql.spi.block.BlockBuilder) StructuralTestUtil.appendToBlockBuilder(io.prestosql.util.StructuralTestUtil.appendToBlockBuilder)

Example 68 with MapType

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);
            }
        }
    }
}
Also used : ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) SqlVarbinary(io.prestosql.spi.type.SqlVarbinary) RowType(io.prestosql.spi.type.RowType) OptionalDouble(java.util.OptionalDouble) Constraint(io.prestosql.spi.connector.Constraint) MapType(io.prestosql.spi.type.MapType) ArrayType(io.prestosql.spi.type.ArrayType) SqlDate(io.prestosql.spi.type.SqlDate) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 69 with MapType

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());
}
Also used : GroupType(org.apache.parquet.schema.GroupType) RichColumnDescriptor(io.prestosql.parquet.RichColumnDescriptor) RichColumnDescriptor(io.prestosql.parquet.RichColumnDescriptor) ColumnDescriptor(org.apache.parquet.column.ColumnDescriptor) PrimitiveType(org.apache.parquet.schema.PrimitiveType) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) HiveColumnHandle(io.prestosql.plugin.hive.HiveColumnHandle) MapType(io.prestosql.spi.type.MapType) MessageType(org.apache.parquet.schema.MessageType) Test(org.testng.annotations.Test)

Example 70 with MapType

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()));
}
Also used : Optional(java.util.Optional) ImmutableList(com.google.common.collect.ImmutableList) GroupField(io.prestosql.parquet.GroupField) RichColumnDescriptor(io.prestosql.parquet.RichColumnDescriptor) NamedTypeSignature(io.prestosql.spi.type.NamedTypeSignature) MapType(io.prestosql.spi.type.MapType) PrimitiveColumnIO(org.apache.parquet.io.PrimitiveColumnIO) GroupField(io.prestosql.parquet.GroupField) PrimitiveField(io.prestosql.parquet.PrimitiveField) Field(io.prestosql.parquet.Field) MapType(io.prestosql.spi.type.MapType) Type(io.prestosql.spi.type.Type) GroupColumnIO(org.apache.parquet.io.GroupColumnIO) TypeSignatureParameter(io.prestosql.spi.type.TypeSignatureParameter) PrimitiveField(io.prestosql.parquet.PrimitiveField)

Aggregations

MapType (io.prestosql.spi.type.MapType)70 Type (io.prestosql.spi.type.Type)29 Test (org.testng.annotations.Test)27 ArrayType (io.prestosql.spi.type.ArrayType)21 BlockBuilder (io.prestosql.spi.block.BlockBuilder)17 RowType (io.prestosql.spi.type.RowType)17 Signature (io.prestosql.spi.function.Signature)14 Block (io.prestosql.spi.block.Block)11 TypeSignature.parseTypeSignature (io.prestosql.spi.type.TypeSignature.parseTypeSignature)10 ImmutableList (com.google.common.collect.ImmutableList)7 PrestoException (io.prestosql.spi.PrestoException)7 List (java.util.List)7 Map (java.util.Map)7 ImmutableMap (com.google.common.collect.ImmutableMap)6 BuiltInScalarFunctionImplementation (io.prestosql.spi.function.BuiltInScalarFunctionImplementation)5 VarcharType (io.prestosql.spi.type.VarcharType)4 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3 TypedSet (io.prestosql.operator.aggregation.TypedSet)3 RichColumnDescriptor (io.prestosql.parquet.RichColumnDescriptor)3 SqlType (io.prestosql.spi.function.SqlType)3