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;
}
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);
}
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;
}
Aggregations