Search in sources :

Example 1 with AlterRoutineCharacteristics

use of com.facebook.presto.spi.function.AlterRoutineCharacteristics in project presto by prestodb.

the class AlterFunctionTask method execute.

@Override
public ListenableFuture<?> execute(AlterFunction statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, Session session, List<Expression> parameters, WarningCollector warningCollector) {
    Analyzer analyzer = new Analyzer(session, metadata, sqlParser, accessControl, Optional.empty(), parameters, warningCollector);
    analyzer.analyze(statement);
    QualifiedObjectName functionName = qualifyObjectName(statement.getFunctionName());
    AlterRoutineCharacteristics alterRoutineCharacteristics = new AlterRoutineCharacteristics(statement.getCharacteristics().getNullCallClause().map(com.facebook.presto.sql.tree.RoutineCharacteristics.NullCallClause::name).map(NullCallClause::valueOf));
    metadata.getFunctionAndTypeManager().alterFunction(functionName, statement.getParameterTypes().map(types -> types.stream().map(TypeSignature::parseTypeSignature).collect(toImmutableList())), alterRoutineCharacteristics);
    return immediateFuture(null);
}
Also used : WarningCollector(com.facebook.presto.spi.WarningCollector) Futures.immediateFuture(com.google.common.util.concurrent.Futures.immediateFuture) Analyzer(com.facebook.presto.sql.analyzer.Analyzer) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Session(com.facebook.presto.Session) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) NullCallClause(com.facebook.presto.spi.function.RoutineCharacteristics.NullCallClause) TypeSignature(com.facebook.presto.common.type.TypeSignature) SqlParser(com.facebook.presto.sql.parser.SqlParser) Inject(javax.inject.Inject) List(java.util.List) Expression(com.facebook.presto.sql.tree.Expression) AlterFunction(com.facebook.presto.sql.tree.AlterFunction) Objects.requireNonNull(java.util.Objects.requireNonNull) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) Optional(java.util.Optional) AlterRoutineCharacteristics(com.facebook.presto.spi.function.AlterRoutineCharacteristics) TransactionManager(com.facebook.presto.transaction.TransactionManager) FunctionAndTypeManager.qualifyObjectName(com.facebook.presto.metadata.FunctionAndTypeManager.qualifyObjectName) Metadata(com.facebook.presto.metadata.Metadata) AccessControl(com.facebook.presto.security.AccessControl) AlterRoutineCharacteristics(com.facebook.presto.spi.function.AlterRoutineCharacteristics) NullCallClause(com.facebook.presto.spi.function.RoutineCharacteristics.NullCallClause) Analyzer(com.facebook.presto.sql.analyzer.Analyzer) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName)

Example 2 with AlterRoutineCharacteristics

use of com.facebook.presto.spi.function.AlterRoutineCharacteristics in project presto by prestodb.

the class TestMySqlFunctionNamespaceManager method testAlterFunction.

@Test
public void testAlterFunction() {
    createFunction(FUNCTION_POWER_TOWER_DOUBLE, false);
    createFunction(FUNCTION_POWER_TOWER_INT, false);
    createFunction(FUNCTION_TANGENT, false);
    // Alter a specific function by name and parameter types
    alterFunction(POWER_TOWER, Optional.of(ImmutableList.of(parseTypeSignature(DOUBLE))), new AlterRoutineCharacteristics(Optional.of(RETURNS_NULL_ON_NULL_INPUT)));
    assertGetFunctions(POWER_TOWER, FUNCTION_POWER_TOWER_INT.withVersion("1"), new SqlInvokedFunction(POWER_TOWER, ImmutableList.of(new Parameter("x", parseTypeSignature(DOUBLE))), parseTypeSignature(DOUBLE), "power tower", RoutineCharacteristics.builder().setDeterminism(DETERMINISTIC).setNullCallClause(RETURNS_NULL_ON_NULL_INPUT).build(), "RETURN pow(x, x)", withVersion("2")));
    // Drop function and alter function by name
    dropFunction(POWER_TOWER, Optional.of(ImmutableList.of(parseTypeSignature(DOUBLE))), false);
    alterFunction(POWER_TOWER, Optional.empty(), new AlterRoutineCharacteristics(Optional.of(CALLED_ON_NULL_INPUT)));
    // Alter function by name
    alterFunction(TANGENT, Optional.empty(), new AlterRoutineCharacteristics(Optional.of(CALLED_ON_NULL_INPUT)));
    SqlInvokedFunction tangentV2 = new SqlInvokedFunction(TANGENT, FUNCTION_TANGENT.getParameters(), FUNCTION_TANGENT.getSignature().getReturnType(), FUNCTION_TANGENT.getDescription(), RoutineCharacteristics.builder().setDeterminism(DETERMINISTIC).build(), FUNCTION_TANGENT.getBody(), withVersion("2"));
    assertGetFunctions(TANGENT, tangentV2);
    // Alter function with no change
    alterFunction(TANGENT, Optional.empty(), new AlterRoutineCharacteristics(Optional.of(CALLED_ON_NULL_INPUT)));
    assertGetFunctions(TANGENT, tangentV2);
}
Also used : AlterRoutineCharacteristics(com.facebook.presto.spi.function.AlterRoutineCharacteristics) SqlInvokedFunction(com.facebook.presto.spi.function.SqlInvokedFunction) Parameter(com.facebook.presto.spi.function.Parameter) Test(org.testng.annotations.Test)

Example 3 with AlterRoutineCharacteristics

use of com.facebook.presto.spi.function.AlterRoutineCharacteristics in project presto by prestodb.

the class MySqlFunctionNamespaceManager method alterFunction.

@Override
public void alterFunction(QualifiedObjectName functionName, Optional<List<TypeSignature>> parameterTypes, AlterRoutineCharacteristics alterRoutineCharacteristics) {
    checkCatalog(functionName);
    jdbi.useTransaction(handle -> {
        FunctionNamespaceDao transactionDao = handle.attach(functionNamespaceDaoClass);
        List<SqlInvokedFunction> functions = getSqlFunctions(transactionDao, functionName, parameterTypes);
        checkUnique(functions, functionName);
        checkExists(functions, functionName, parameterTypes);
        SqlInvokedFunction latest = functions.get(0);
        RoutineCharacteristics.Builder routineCharacteristics = RoutineCharacteristics.builder(latest.getRoutineCharacteristics());
        alterRoutineCharacteristics.getNullCallClause().ifPresent(routineCharacteristics::setNullCallClause);
        SqlInvokedFunction altered = new SqlInvokedFunction(latest.getFunctionId().getFunctionName(), latest.getParameters(), latest.getSignature().getReturnType(), latest.getDescription(), routineCharacteristics.build(), latest.getBody(), notVersioned());
        if (!altered.hasSameDefinitionAs(latest)) {
            checkState(latest.hasVersion(), "Function version missing: %s", latest.getFunctionId());
            insertSqlInvokedFunction(transactionDao, altered, getLongVersion(latest) + 1);
        }
    });
    refreshFunctionsCache(functionName);
}
Also used : RoutineCharacteristics(com.facebook.presto.spi.function.RoutineCharacteristics) AlterRoutineCharacteristics(com.facebook.presto.spi.function.AlterRoutineCharacteristics) SqlInvokedFunction(com.facebook.presto.spi.function.SqlInvokedFunction)

Example 4 with AlterRoutineCharacteristics

use of com.facebook.presto.spi.function.AlterRoutineCharacteristics in project presto by prestodb.

the class TestMySqlFunctionNamespaceManager method testAlterFunctionNotFound.

@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = "Function not found: unittest\\.memory\\.power_tower\\(\\)")
public void testAlterFunctionNotFound() {
    createFunction(FUNCTION_POWER_TOWER_DOUBLE, false);
    createFunction(FUNCTION_POWER_TOWER_INT, false);
    alterFunction(POWER_TOWER, Optional.of(ImmutableList.of()), new AlterRoutineCharacteristics(Optional.of(RETURNS_NULL_ON_NULL_INPUT)));
}
Also used : AlterRoutineCharacteristics(com.facebook.presto.spi.function.AlterRoutineCharacteristics) Test(org.testng.annotations.Test)

Example 5 with AlterRoutineCharacteristics

use of com.facebook.presto.spi.function.AlterRoutineCharacteristics in project presto by prestodb.

the class TestMySqlFunctionNamespaceManager method testAlterFunctionAmbiguous.

@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = "Function 'unittest\\.memory\\.power_tower' has multiple signatures: unittest\\.memory\\.power_tower(\\(integer\\):integer|\\(double\\):double); unittest\\.memory\\.power_tower(\\(double\\):double|\\(integer\\):integer)\\. Please specify parameter types\\.")
public void testAlterFunctionAmbiguous() {
    createFunction(FUNCTION_POWER_TOWER_DOUBLE, false);
    createFunction(FUNCTION_POWER_TOWER_INT, false);
    alterFunction(POWER_TOWER, Optional.empty(), new AlterRoutineCharacteristics(Optional.of(RETURNS_NULL_ON_NULL_INPUT)));
}
Also used : AlterRoutineCharacteristics(com.facebook.presto.spi.function.AlterRoutineCharacteristics) Test(org.testng.annotations.Test)

Aggregations

AlterRoutineCharacteristics (com.facebook.presto.spi.function.AlterRoutineCharacteristics)5 Test (org.testng.annotations.Test)3 SqlInvokedFunction (com.facebook.presto.spi.function.SqlInvokedFunction)2 Session (com.facebook.presto.Session)1 QualifiedObjectName (com.facebook.presto.common.QualifiedObjectName)1 TypeSignature (com.facebook.presto.common.type.TypeSignature)1 FunctionAndTypeManager.qualifyObjectName (com.facebook.presto.metadata.FunctionAndTypeManager.qualifyObjectName)1 Metadata (com.facebook.presto.metadata.Metadata)1 AccessControl (com.facebook.presto.security.AccessControl)1 WarningCollector (com.facebook.presto.spi.WarningCollector)1 Parameter (com.facebook.presto.spi.function.Parameter)1 RoutineCharacteristics (com.facebook.presto.spi.function.RoutineCharacteristics)1 NullCallClause (com.facebook.presto.spi.function.RoutineCharacteristics.NullCallClause)1 Analyzer (com.facebook.presto.sql.analyzer.Analyzer)1 SqlParser (com.facebook.presto.sql.parser.SqlParser)1 AlterFunction (com.facebook.presto.sql.tree.AlterFunction)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 Futures.immediateFuture (com.google.common.util.concurrent.Futures.immediateFuture)1