Search in sources :

Example 1 with TypeParameter

use of io.prestosql.spi.type.TypeParameter in project hetu-core by openlookeng.

the class BuiltInTypeRegistry method instantiateParametricType.

private Type instantiateParametricType(TypeManager typeManager, TypeSignature signature) {
    List<TypeParameter> parameters = new ArrayList<>();
    for (TypeSignatureParameter parameter : signature.getParameters()) {
        TypeParameter typeParameter = TypeParameter.of(parameter, typeManager);
        parameters.add(typeParameter);
    }
    ParametricType parametricType = parametricTypes.get(signature.getBase().toLowerCase(Locale.ENGLISH));
    if (parametricType == null) {
        throw new TypeNotFoundException(signature);
    }
    Type instantiatedType;
    try {
        instantiatedType = parametricType.createType(typeManager, parameters);
    } catch (IllegalArgumentException e) {
        throw new TypeNotFoundException(signature, e);
    }
    // TODO: reimplement this check? Currently "varchar(Integer.MAX_VALUE)" fails with "varchar"
    return instantiatedType;
}
Also used : TypeParameter(io.prestosql.spi.type.TypeParameter) Re2JRegexpType(io.prestosql.type.Re2JRegexpType) DecimalType(io.prestosql.spi.type.DecimalType) ColorType(io.prestosql.type.ColorType) ParametricType(io.prestosql.spi.type.ParametricType) RowType(io.prestosql.spi.type.RowType) Type(io.prestosql.spi.type.Type) DecimalType.createDecimalType(io.prestosql.spi.type.DecimalType.createDecimalType) LikePatternType(io.prestosql.spi.type.LikePatternType) ArrayType(io.prestosql.spi.type.ArrayType) CharType.createCharType(io.prestosql.spi.type.CharType.createCharType) VarcharType.createVarcharType(io.prestosql.spi.type.VarcharType.createVarcharType) VarcharType.createUnboundedVarcharType(io.prestosql.spi.type.VarcharType.createUnboundedVarcharType) CharParametricType(io.prestosql.spi.type.CharParametricType) VarcharParametricType(io.prestosql.spi.type.VarcharParametricType) UnknownType(io.prestosql.spi.type.UnknownType) CharType(io.prestosql.spi.type.CharType) JoniRegexpType(io.prestosql.type.JoniRegexpType) CodePointsType(io.prestosql.type.CodePointsType) MapType(io.prestosql.spi.type.MapType) JsonPathType(io.prestosql.type.JsonPathType) SetDigestType(io.prestosql.type.setdigest.SetDigestType) DecimalParametricType(io.prestosql.spi.type.DecimalParametricType) VarcharType(io.prestosql.spi.type.VarcharType) TypeSignatureParameter(io.prestosql.spi.type.TypeSignatureParameter) TypeNotFoundException(io.prestosql.spi.type.TypeNotFoundException) ArrayList(java.util.ArrayList) ParametricType(io.prestosql.spi.type.ParametricType) CharParametricType(io.prestosql.spi.type.CharParametricType) VarcharParametricType(io.prestosql.spi.type.VarcharParametricType) DecimalParametricType(io.prestosql.spi.type.DecimalParametricType)

Example 2 with TypeParameter

use of io.prestosql.spi.type.TypeParameter in project hetu-core by openlookeng.

the class TestRowParametricType method testTypeSignatureRoundTrip.

@Test
public void testTypeSignatureRoundTrip() {
    TypeManager typeManager = new InternalTypeManager(createTestMetadataManager().getFunctionAndTypeManager());
    TypeSignature typeSignature = new TypeSignature(ROW, TypeSignatureParameter.of(new NamedTypeSignature(Optional.of(new RowFieldName("col1", false)), new TypeSignature(BIGINT))), TypeSignatureParameter.of(new NamedTypeSignature(Optional.of(new RowFieldName("col2", true)), new TypeSignature(DOUBLE))));
    List<TypeParameter> parameters = typeSignature.getParameters().stream().map(parameter -> TypeParameter.of(parameter, typeManager)).collect(Collectors.toList());
    Type rowType = RowParametricType.ROW.createType(typeManager, parameters);
    assertEquals(rowType.getTypeSignature(), typeSignature);
}
Also used : DOUBLE(io.prestosql.spi.type.StandardTypes.DOUBLE) MetadataManager.createTestMetadataManager(io.prestosql.metadata.MetadataManager.createTestMetadataManager) TypeManager(io.prestosql.spi.type.TypeManager) Assert.assertEquals(org.testng.Assert.assertEquals) TypeSignatureParameter(io.prestosql.spi.type.TypeSignatureParameter) Test(org.testng.annotations.Test) Collectors(java.util.stream.Collectors) RowParametricType(io.prestosql.spi.type.RowParametricType) NamedTypeSignature(io.prestosql.spi.type.NamedTypeSignature) List(java.util.List) TypeParameter(io.prestosql.spi.type.TypeParameter) Optional(java.util.Optional) RowFieldName(io.prestosql.spi.type.RowFieldName) Type(io.prestosql.spi.type.Type) TypeSignature(io.prestosql.spi.type.TypeSignature) ROW(io.prestosql.spi.type.StandardTypes.ROW) BIGINT(io.prestosql.spi.type.StandardTypes.BIGINT) NamedTypeSignature(io.prestosql.spi.type.NamedTypeSignature) TypeSignature(io.prestosql.spi.type.TypeSignature) TypeParameter(io.prestosql.spi.type.TypeParameter) RowParametricType(io.prestosql.spi.type.RowParametricType) Type(io.prestosql.spi.type.Type) RowFieldName(io.prestosql.spi.type.RowFieldName) TypeManager(io.prestosql.spi.type.TypeManager) NamedTypeSignature(io.prestosql.spi.type.NamedTypeSignature) Test(org.testng.annotations.Test)

Example 3 with TypeParameter

use of io.prestosql.spi.type.TypeParameter in project hetu-core by openlookeng.

the class TypeUtil method parametricType.

private static Type parametricType(TypeManager typeManager, TypeSignature typeSignature) {
    String typeName = typeSignature.getBase().toLowerCase(Locale.ENGLISH);
    ParametricType parametricType = PARAMETRIC_TYPE_MAP.get(typeName);
    if (parametricType != null) {
        List<TypeParameter> parameters = new ArrayList<>();
        for (TypeSignatureParameter parameter : typeSignature.getParameters()) {
            TypeParameter typeParameter = TypeParameter.of(parameter, typeManager);
            parameters.add(typeParameter);
        }
        return parametricType.createType(typeManager, parameters);
    }
    return null;
}
Also used : TypeParameter(io.prestosql.spi.type.TypeParameter) TypeSignatureParameter(io.prestosql.spi.type.TypeSignatureParameter) ArrayList(java.util.ArrayList) ParametricType(io.prestosql.spi.type.ParametricType)

Aggregations

TypeParameter (io.prestosql.spi.type.TypeParameter)3 TypeSignatureParameter (io.prestosql.spi.type.TypeSignatureParameter)3 ParametricType (io.prestosql.spi.type.ParametricType)2 Type (io.prestosql.spi.type.Type)2 ArrayList (java.util.ArrayList)2 MetadataManager.createTestMetadataManager (io.prestosql.metadata.MetadataManager.createTestMetadataManager)1 ArrayType (io.prestosql.spi.type.ArrayType)1 CharParametricType (io.prestosql.spi.type.CharParametricType)1 CharType (io.prestosql.spi.type.CharType)1 CharType.createCharType (io.prestosql.spi.type.CharType.createCharType)1 DecimalParametricType (io.prestosql.spi.type.DecimalParametricType)1 DecimalType (io.prestosql.spi.type.DecimalType)1 DecimalType.createDecimalType (io.prestosql.spi.type.DecimalType.createDecimalType)1 LikePatternType (io.prestosql.spi.type.LikePatternType)1 MapType (io.prestosql.spi.type.MapType)1 NamedTypeSignature (io.prestosql.spi.type.NamedTypeSignature)1 RowFieldName (io.prestosql.spi.type.RowFieldName)1 RowParametricType (io.prestosql.spi.type.RowParametricType)1 RowType (io.prestosql.spi.type.RowType)1 BIGINT (io.prestosql.spi.type.StandardTypes.BIGINT)1