Search in sources :

Example 11 with TypeSignatureParameter

use of com.facebook.presto.spi.type.TypeSignatureParameter in project presto by prestodb.

the class ParquetReader method readStruct.

private Block readStruct(Type type, List<String> path, IntList elementOffsets) throws IOException {
    List<TypeSignatureParameter> parameters = type.getTypeSignature().getParameters();
    Block[] blocks = new Block[parameters.size()];
    for (int i = 0; i < parameters.size(); i++) {
        NamedTypeSignature namedTypeSignature = parameters.get(i).getNamedTypeSignature();
        Type fieldType = typeManager.getType(namedTypeSignature.getTypeSignature());
        String name = namedTypeSignature.getName();
        blocks[i] = readBlock(name, fieldType, path, new IntArrayList());
    }
    InterleavedBlock interleavedBlock = new InterleavedBlock(blocks);
    int blockSize = blocks[0].getPositionCount();
    int[] offsets = new int[blockSize + 1];
    for (int i = 1; i < offsets.length; i++) {
        elementOffsets.add(parameters.size());
        offsets[i] = i * parameters.size();
    }
    return new ArrayBlock(blockSize, new boolean[blockSize], offsets, interleavedBlock);
}
Also used : Type(com.facebook.presto.spi.type.Type) MessageType(parquet.schema.MessageType) ArrayBlock(com.facebook.presto.spi.block.ArrayBlock) TypeSignatureParameter(com.facebook.presto.spi.type.TypeSignatureParameter) Block(com.facebook.presto.spi.block.Block) RunLengthEncodedBlock(com.facebook.presto.spi.block.RunLengthEncodedBlock) ArrayBlock(com.facebook.presto.spi.block.ArrayBlock) InterleavedBlock(com.facebook.presto.spi.block.InterleavedBlock) NamedTypeSignature(com.facebook.presto.spi.type.NamedTypeSignature) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) InterleavedBlock(com.facebook.presto.spi.block.InterleavedBlock)

Example 12 with TypeSignatureParameter

use of com.facebook.presto.spi.type.TypeSignatureParameter in project presto by prestodb.

the class TypeRegistry method instantiateParametricType.

private Type instantiateParametricType(TypeSignature signature) {
    List<TypeParameter> parameters = new ArrayList<>();
    for (TypeSignatureParameter parameter : signature.getParameters()) {
        TypeParameter typeParameter = TypeParameter.of(parameter, this);
        if (typeParameter == null) {
            return null;
        }
        parameters.add(typeParameter);
    }
    ParametricType parametricType = parametricTypes.get(signature.getBase().toLowerCase(Locale.ENGLISH));
    if (parametricType == null) {
        return null;
    }
    try {
        Type instantiatedType = parametricType.createType(parameters);
        //checkState(instantiatedType.equalsSignature(signature), "Instantiated parametric type name (%s) does not match expected name (%s)", instantiatedType, signature);
        return instantiatedType;
    } catch (IllegalArgumentException e) {
        // TODO: check whether a type constructor actually exists rather than failing when it doesn't. This will be possible in the next version of the type system
        return null;
    }
}
Also used : TypeParameter(com.facebook.presto.spi.type.TypeParameter) CharType.createCharType(com.facebook.presto.spi.type.CharType.createCharType) DecimalType(com.facebook.presto.spi.type.DecimalType) VarcharType.createVarcharType(com.facebook.presto.spi.type.VarcharType.createVarcharType) DecimalType.createDecimalType(com.facebook.presto.spi.type.DecimalType.createDecimalType) Type(com.facebook.presto.spi.type.Type) ParametricType(com.facebook.presto.spi.type.ParametricType) CharType(com.facebook.presto.spi.type.CharType) VarcharType.createUnboundedVarcharType(com.facebook.presto.spi.type.VarcharType.createUnboundedVarcharType) VarcharType(com.facebook.presto.spi.type.VarcharType) TypeSignatureParameter(com.facebook.presto.spi.type.TypeSignatureParameter) ArrayList(java.util.ArrayList) ParametricType(com.facebook.presto.spi.type.ParametricType)

Aggregations

TypeSignatureParameter (com.facebook.presto.spi.type.TypeSignatureParameter)12 NamedTypeSignature (com.facebook.presto.spi.type.NamedTypeSignature)9 ImmutableList (com.google.common.collect.ImmutableList)7 Type (com.facebook.presto.spi.type.Type)6 TypeSignature (com.facebook.presto.spi.type.TypeSignature)6 PrestoException (com.facebook.presto.spi.PrestoException)4 VarcharType.createUnboundedVarcharType (com.facebook.presto.spi.type.VarcharType.createUnboundedVarcharType)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 CharType (com.facebook.presto.spi.type.CharType)2 CharType.createCharType (com.facebook.presto.spi.type.CharType.createCharType)2 DecimalType (com.facebook.presto.spi.type.DecimalType)2 DecimalType.createDecimalType (com.facebook.presto.spi.type.DecimalType.createDecimalType)2 VarcharType (com.facebook.presto.spi.type.VarcharType)2 VarcharType.createVarcharType (com.facebook.presto.spi.type.VarcharType.createVarcharType)2 Set (java.util.Set)2 TypeInfoUtils.getTypeInfoFromTypeString (org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils.getTypeInfoFromTypeString)2 OBJECT_ID (com.facebook.presto.mongodb.ObjectIdType.OBJECT_ID)1 OrcType (com.facebook.presto.orc.metadata.OrcType)1 ColumnHandle (com.facebook.presto.spi.ColumnHandle)1