Search in sources :

Example 6 with CatalogSchemaName

use of io.prestosql.spi.connector.CatalogSchemaName in project hetu-core by openlookeng.

the class ExternalFunctionsParser method parseExternalFunction.

public static Optional<SqlInvokedFunction> parseExternalFunction(ExternalFunctionInfo externalFunctionInfo, CatalogSchemaName catalogSchemaName, RoutineCharacteristics.Language language) {
    Optional<String> functionName = externalFunctionInfo.getFunctionName();
    Optional<String> description = externalFunctionInfo.getDescription();
    List<String> inputArgs = externalFunctionInfo.getInputArgs();
    Optional<String> returnType = externalFunctionInfo.getReturnType();
    boolean deterministic = externalFunctionInfo.isDeterministic();
    boolean calledOnNullInput = externalFunctionInfo.isCalledOnNullInput();
    if (functionName.isPresent() && returnType.isPresent()) {
        QualifiedObjectName qualifiedObjectName = new QualifiedObjectName(catalogSchemaName.getCatalogName(), catalogSchemaName.getSchemaName(), functionName.get());
        List<Parameter> parameters = inputArgs.stream().map(str -> {
            checkState(SUPPORTED_TYPE.contains(str), format("external function do not supported type: %s", str));
            if (str.equals(StandardTypes.DECIMAL)) {
                return new Parameter(getRandomString((inputArgs.size() / ALPHABET.length() + 1), ALPHABET), parseTypeSignature(str + "(p, s)", ImmutableSet.of("p", "s")));
            } else if (str.equals(StandardTypes.CHAR) || str.equals(StandardTypes.VARCHAR)) {
                return new Parameter(getRandomString((inputArgs.size() / ALPHABET.length() + 1), ALPHABET), parseTypeSignature(str + "(x)", ImmutableSet.of("x")));
            } else {
                return new Parameter(getRandomString((inputArgs.size() / ALPHABET.length() + 1), ALPHABET), parseTypeSignature(str));
            }
        }).collect(toImmutableList());
        TypeSignature reType = parseTypeSignature(returnType.get());
        String deter = deterministic ? "DETERMINISTIC" : "NOT_DETERMINISTIC";
        String nullCallClause = calledOnNullInput ? "CALLED_ON_NULL_INPUT" : "RETURNS_NULL_ON_NULL_INPUT";
        RoutineCharacteristics routineCharacteristics = RoutineCharacteristics.builder().setLanguage(new RoutineCharacteristics.Language(language.getLanguage())).setDeterminism(RoutineCharacteristics.Determinism.valueOf(deter)).setNullCallClause(RoutineCharacteristics.NullCallClause.valueOf(nullCallClause)).build();
        SqlInvokedFunction sqlInvokedFunction = new SqlInvokedFunction(qualifiedObjectName, parameters, reType, description.orElse(""), routineCharacteristics, EXTERNAL_FUNCTION_BODY, ImmutableMap.of(), Optional.empty());
        return Optional.of(sqlInvokedFunction);
    }
    return Optional.empty();
}
Also used : RoutineCharacteristics(io.prestosql.spi.function.RoutineCharacteristics) ImmutableSet(com.google.common.collect.ImmutableSet) StandardTypes(io.prestosql.spi.type.StandardTypes) ImmutableMap(com.google.common.collect.ImmutableMap) Parameter(io.prestosql.spi.function.Parameter) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) ExternalFunctionInfo(io.prestosql.spi.function.ExternalFunctionInfo) SqlInvokedFunction(io.prestosql.spi.function.SqlInvokedFunction) String.format(java.lang.String.format) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) Preconditions.checkState(com.google.common.base.Preconditions.checkState) SecureRandom(java.security.SecureRandom) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) List(java.util.List) Optional(java.util.Optional) TypeSignature(io.prestosql.spi.type.TypeSignature) CatalogSchemaName(io.prestosql.spi.connector.CatalogSchemaName) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) TypeSignature(io.prestosql.spi.type.TypeSignature) RoutineCharacteristics(io.prestosql.spi.function.RoutineCharacteristics) SqlInvokedFunction(io.prestosql.spi.function.SqlInvokedFunction) Parameter(io.prestosql.spi.function.Parameter) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName)

Example 7 with CatalogSchemaName

use of io.prestosql.spi.connector.CatalogSchemaName in project hetu-core by openlookeng.

the class FunctionExtractor method extractExternalFunctions.

public static Set<SqlInvokedFunction> extractExternalFunctions(ExternalFunctionHub externalFunctionHub) {
    RoutineCharacteristics.Language language = externalFunctionHub.getExternalFunctionLanguage();
    Optional<CatalogSchemaName> catalogSchemaName = externalFunctionHub.getExternalFunctionCatalogSchemaName();
    if (!catalogSchemaName.isPresent()) {
        return Collections.emptySet();
    }
    ImmutableSet.Builder<SqlInvokedFunction> builder = new ImmutableSet.Builder<>();
    for (ExternalFunctionInfo externalFunctionInfo : externalFunctionHub.getExternalFunctions()) {
        Optional<SqlInvokedFunction> sqlInvokedFunctionOptional = ExternalFunctionsParser.parseExternalFunction(externalFunctionInfo, catalogSchemaName.get(), language);
        sqlInvokedFunctionOptional.ifPresent(builder::add);
    }
    return builder.build();
}
Also used : RoutineCharacteristics(io.prestosql.spi.function.RoutineCharacteristics) ImmutableSet(com.google.common.collect.ImmutableSet) CatalogSchemaName(io.prestosql.spi.connector.CatalogSchemaName) SqlInvokedFunction(io.prestosql.spi.function.SqlInvokedFunction) ExternalFunctionInfo(io.prestosql.spi.function.ExternalFunctionInfo)

Example 8 with CatalogSchemaName

use of io.prestosql.spi.connector.CatalogSchemaName in project hetu-core by openlookeng.

the class RenameSchemaTask method execute.

@Override
public ListenableFuture<?> execute(RenameSchema statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
    Session session = stateMachine.getSession();
    CatalogSchemaName source = createCatalogSchemaName(session, statement, Optional.of(statement.getSource()));
    CatalogSchemaName target = new CatalogSchemaName(source.getCatalogName(), statement.getTarget().getValue());
    if (!metadata.schemaExists(session, source)) {
        throw new SemanticException(MISSING_SCHEMA, statement, "Schema '%s' does not exist", source);
    }
    if (metadata.schemaExists(session, target)) {
        throw new SemanticException(SCHEMA_ALREADY_EXISTS, statement, "Target schema '%s' already exists", target);
    }
    accessControl.checkCanRenameSchema(session.getRequiredTransactionId(), session.getIdentity(), source, statement.getTarget().getValue());
    metadata.renameSchema(session, source, statement.getTarget().getValue());
    return immediateFuture(null);
}
Also used : MetadataUtil.createCatalogSchemaName(io.prestosql.metadata.MetadataUtil.createCatalogSchemaName) CatalogSchemaName(io.prestosql.spi.connector.CatalogSchemaName) Session(io.prestosql.Session) SemanticException(io.prestosql.sql.analyzer.SemanticException)

Example 9 with CatalogSchemaName

use of io.prestosql.spi.connector.CatalogSchemaName in project hetu-core by openlookeng.

the class DropSchemaTask method execute.

@Override
public ListenableFuture<?> execute(DropSchema statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
    if (statement.isCascade()) {
        throw new PrestoException(NOT_SUPPORTED, "CASCADE is not yet supported for DROP SCHEMA");
    }
    Session session = stateMachine.getSession();
    CatalogSchemaName schema = createCatalogSchemaName(session, statement, Optional.of(statement.getSchemaName()));
    if (!metadata.schemaExists(session, schema)) {
        if (!statement.isExists()) {
            throw new SemanticException(MISSING_SCHEMA, statement, "Schema '%s' does not exist", schema);
        }
        return immediateFuture(null);
    }
    accessControl.checkCanDropSchema(session.getRequiredTransactionId(), session.getIdentity(), schema);
    metadata.dropSchema(session, schema);
    return immediateFuture(null);
}
Also used : MetadataUtil.createCatalogSchemaName(io.prestosql.metadata.MetadataUtil.createCatalogSchemaName) CatalogSchemaName(io.prestosql.spi.connector.CatalogSchemaName) PrestoException(io.prestosql.spi.PrestoException) Session(io.prestosql.Session) SemanticException(io.prestosql.sql.analyzer.SemanticException)

Example 10 with CatalogSchemaName

use of io.prestosql.spi.connector.CatalogSchemaName in project hetu-core by openlookeng.

the class CreateSchemaTask method execute.

@Override
public ListenableFuture<?> execute(CreateSchema statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
    Session session = stateMachine.getSession();
    CatalogSchemaName schema = createCatalogSchemaName(session, statement, Optional.of(statement.getSchemaName()));
    // TODO: validate that catalog exists
    accessControl.checkCanCreateSchema(session.getRequiredTransactionId(), session.getIdentity(), schema);
    if (metadata.schemaExists(session, schema)) {
        if (!statement.isNotExists()) {
            throw new SemanticException(SCHEMA_ALREADY_EXISTS, statement, "Schema '%s' already exists", schema);
        }
        return immediateFuture(null);
    }
    CatalogName catalogName = metadata.getCatalogHandle(session, schema.getCatalogName()).orElseThrow(() -> new PrestoException(NOT_FOUND, "Catalog does not exist: " + schema.getCatalogName()));
    Map<String, Object> properties = metadata.getSchemaPropertyManager().getProperties(catalogName, schema.getCatalogName(), mapFromProperties(statement.getProperties()), session, metadata, parameters);
    metadata.createSchema(session, schema, properties);
    return immediateFuture(null);
}
Also used : MetadataUtil.createCatalogSchemaName(io.prestosql.metadata.MetadataUtil.createCatalogSchemaName) CatalogSchemaName(io.prestosql.spi.connector.CatalogSchemaName) CatalogName(io.prestosql.spi.connector.CatalogName) PrestoException(io.prestosql.spi.PrestoException) Session(io.prestosql.Session) SemanticException(io.prestosql.sql.analyzer.SemanticException)

Aggregations

CatalogSchemaName (io.prestosql.spi.connector.CatalogSchemaName)10 QualifiedObjectName (io.prestosql.spi.connector.QualifiedObjectName)5 SqlInvokedFunction (io.prestosql.spi.function.SqlInvokedFunction)5 PrestoException (io.prestosql.spi.PrestoException)4 Session (io.prestosql.Session)3 MetadataUtil.createCatalogSchemaName (io.prestosql.metadata.MetadataUtil.createCatalogSchemaName)3 Parameter (io.prestosql.spi.function.Parameter)3 SemanticException (io.prestosql.sql.analyzer.SemanticException)3 Test (org.testng.annotations.Test)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 ExternalFunctionInfo (io.prestosql.spi.function.ExternalFunctionInfo)2 FunctionMetadata (io.prestosql.spi.function.FunctionMetadata)2 RoutineCharacteristics (io.prestosql.spi.function.RoutineCharacteristics)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 InMemoryFunctionNamespaceManager (io.hetu.core.plugin.functionnamespace.memory.InMemoryFunctionNamespaceManager)1 CatalogName (io.prestosql.spi.connector.CatalogName)1 CatalogSchemaTableName (io.prestosql.spi.connector.CatalogSchemaTableName)1 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)1