Search in sources :

Example 1 with AlterFunction

use of com.facebook.presto.sql.tree.AlterFunction 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 AlterFunction

use of com.facebook.presto.sql.tree.AlterFunction in project presto by prestodb.

the class TestSqlParser method testAlterFunction.

@Test
public void testAlterFunction() {
    QualifiedName functionName = QualifiedName.of("testing", "default", "tan");
    assertStatement("ALTER FUNCTION testing.default.tan\n" + "CALLED ON NULL INPUT", new AlterFunction(functionName, Optional.empty(), new AlterRoutineCharacteristics(Optional.of(CALLED_ON_NULL_INPUT))));
    assertStatement("ALTER FUNCTION testing.default.tan(double)\n" + "RETURNS NULL ON NULL INPUT", new AlterFunction(functionName, Optional.of(ImmutableList.of("double")), new AlterRoutineCharacteristics(Optional.of(RETURNS_NULL_ON_NULL_INPUT))));
    assertInvalidStatement("ALTER FUNCTION testing.default.tan", "No alter routine characteristics specified");
    assertInvalidStatement("ALTER FUNCTION testing.default.tan\n" + "RETURNS NULL ON NULL INPUT\n" + "RETURNS NULL ON NULL INPUT", "Duplicate null-call clause: RETURNSNULLONNULLINPUT");
}
Also used : AlterRoutineCharacteristics(com.facebook.presto.sql.tree.AlterRoutineCharacteristics) QualifiedName(com.facebook.presto.sql.tree.QualifiedName) AlterFunction(com.facebook.presto.sql.tree.AlterFunction) Test(org.testng.annotations.Test)

Aggregations

AlterFunction (com.facebook.presto.sql.tree.AlterFunction)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 AlterRoutineCharacteristics (com.facebook.presto.spi.function.AlterRoutineCharacteristics)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 AlterRoutineCharacteristics (com.facebook.presto.sql.tree.AlterRoutineCharacteristics)1 Expression (com.facebook.presto.sql.tree.Expression)1 QualifiedName (com.facebook.presto.sql.tree.QualifiedName)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 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 List (java.util.List)1