Search in sources :

Example 1 with UserDefinedType

use of com.facebook.presto.common.type.UserDefinedType in project presto by prestodb.

the class FunctionAndTypeManager method getUserDefinedType.

private Type getUserDefinedType(TypeSignature signature) {
    Optional<FunctionNamespaceManager<?>> functionNamespaceManager = getServingFunctionNamespaceManager(signature.getTypeSignatureBase());
    checkArgument(functionNamespaceManager.isPresent(), "Cannot find function namespace for type '%s'", signature.getBase());
    UserDefinedType userDefinedType = functionNamespaceManager.get().getUserDefinedType(signature.getTypeSignatureBase().getTypeName()).orElseThrow(() -> new IllegalArgumentException("Unknown type " + signature));
    checkArgument(userDefinedType.getPhysicalTypeSignature().getTypeSignatureBase().hasStandardType(), "A UserDefinedType must be based on static types.");
    return getType(userDefinedType);
}
Also used : FunctionNamespaceManager(com.facebook.presto.spi.function.FunctionNamespaceManager) UserDefinedType(com.facebook.presto.common.type.UserDefinedType)

Example 2 with UserDefinedType

use of com.facebook.presto.common.type.UserDefinedType in project presto by prestodb.

the class CreateTypeTask method execute.

@Override
public ListenableFuture<?> execute(CreateType statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, Session session, List<Expression> parameters, WarningCollector warningCollector) {
    TypeSignature signature;
    if (statement.getDistinctType().isPresent()) {
        signature = new TypeSignature(statement.getDistinctType().get());
    } else {
        List<TypeSignatureParameter> typeParameters = Streams.zip(statement.getParameterNames().stream(), statement.getParameterTypes().stream(), (name, type) -> TypeSignatureParameter.of(new NamedTypeSignature(Optional.of(new RowFieldName(name, false)), parseTypeSignature(type)))).collect(toImmutableList());
        signature = new TypeSignature(ROW, typeParameters);
    }
    UserDefinedType userDefinedType = new UserDefinedType(QualifiedObjectName.valueOf(statement.getTypeName().toString()), signature);
    metadata.getFunctionAndTypeManager().addUserDefinedType(userDefinedType);
    return immediateFuture(null);
}
Also used : WarningCollector(com.facebook.presto.spi.WarningCollector) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) TypeSignatureParameter(com.facebook.presto.common.type.TypeSignatureParameter) ROW(com.facebook.presto.common.type.StandardTypes.ROW) TypeSignature(com.facebook.presto.common.type.TypeSignature) Inject(javax.inject.Inject) Objects.requireNonNull(java.util.Objects.requireNonNull) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) UserDefinedType(com.facebook.presto.common.type.UserDefinedType) TransactionManager(com.facebook.presto.transaction.TransactionManager) NamedTypeSignature(com.facebook.presto.common.type.NamedTypeSignature) Futures.immediateFuture(com.google.common.util.concurrent.Futures.immediateFuture) Session(com.facebook.presto.Session) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) CreateType(com.facebook.presto.sql.tree.CreateType) Streams(com.google.common.collect.Streams) String.format(java.lang.String.format) SqlParser(com.facebook.presto.sql.parser.SqlParser) List(java.util.List) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) Expression(com.facebook.presto.sql.tree.Expression) Optional(java.util.Optional) RowFieldName(com.facebook.presto.common.type.RowFieldName) Metadata(com.facebook.presto.metadata.Metadata) AccessControl(com.facebook.presto.security.AccessControl) TypeSignature(com.facebook.presto.common.type.TypeSignature) NamedTypeSignature(com.facebook.presto.common.type.NamedTypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) TypeSignatureParameter(com.facebook.presto.common.type.TypeSignatureParameter) RowFieldName(com.facebook.presto.common.type.RowFieldName) NamedTypeSignature(com.facebook.presto.common.type.NamedTypeSignature) UserDefinedType(com.facebook.presto.common.type.UserDefinedType)

Example 3 with UserDefinedType

use of com.facebook.presto.common.type.UserDefinedType in project presto by prestodb.

the class UserDefinedTypeRowMapper method map.

@Override
public UserDefinedType map(ResultSet rs, StatementContext ctx) throws SQLException {
    QualifiedObjectName typeName = QualifiedObjectName.valueOf(rs.getString("catalog_name"), rs.getString("schema_name"), rs.getString("type_name"));
    String physicalType = rs.getString("physical_type");
    TypeSignature typeSignature = parseTypeSignature(physicalType);
    return new UserDefinedType(typeName, typeSignature);
}
Also used : TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) TypeSignature(com.facebook.presto.common.type.TypeSignature) UserDefinedType(com.facebook.presto.common.type.UserDefinedType) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName)

Aggregations

UserDefinedType (com.facebook.presto.common.type.UserDefinedType)3 QualifiedObjectName (com.facebook.presto.common.QualifiedObjectName)2 TypeSignature (com.facebook.presto.common.type.TypeSignature)2 TypeSignature.parseTypeSignature (com.facebook.presto.common.type.TypeSignature.parseTypeSignature)2 Session (com.facebook.presto.Session)1 NamedTypeSignature (com.facebook.presto.common.type.NamedTypeSignature)1 RowFieldName (com.facebook.presto.common.type.RowFieldName)1 ROW (com.facebook.presto.common.type.StandardTypes.ROW)1 TypeSignatureParameter (com.facebook.presto.common.type.TypeSignatureParameter)1 Metadata (com.facebook.presto.metadata.Metadata)1 AccessControl (com.facebook.presto.security.AccessControl)1 WarningCollector (com.facebook.presto.spi.WarningCollector)1 FunctionNamespaceManager (com.facebook.presto.spi.function.FunctionNamespaceManager)1 SqlParser (com.facebook.presto.sql.parser.SqlParser)1 CreateType (com.facebook.presto.sql.tree.CreateType)1 Expression (com.facebook.presto.sql.tree.Expression)1 TransactionManager (com.facebook.presto.transaction.TransactionManager)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 Streams (com.google.common.collect.Streams)1 Futures.immediateFuture (com.google.common.util.concurrent.Futures.immediateFuture)1