Search in sources :

Example 6 with SqlFunctionId

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

the class ThriftSqlFunctionExecutor method executeFunction.

@Override
public CompletableFuture<SqlFunctionResult> executeFunction(String source, RemoteScalarFunctionImplementation functionImplementation, Page input, List<Integer> channels, List<Type> argumentTypes, Type returnType) {
    ThriftUdfPage page = buildThriftPage(functionImplementation, input, channels, argumentTypes);
    SqlFunctionHandle functionHandle = functionImplementation.getFunctionHandle();
    SqlFunctionId functionId = functionHandle.getFunctionId();
    ThriftFunctionHandle thriftFunctionHandle = new ThriftFunctionHandle(functionId.getFunctionName().toString(), functionId.getArgumentTypes().stream().map(TypeSignature::toString).collect(toImmutableList()), returnType.toString(), functionHandle.getVersion());
    ThriftUdfService thriftUdfService = thriftUdfClient.get(Optional.of(functionImplementation.getLanguage().getLanguage()));
    return invokeUdfWithRetry(thriftUdfService, new ThriftUdfRequest(source, thriftFunctionHandle, page)).thenApply(thriftResult -> toSqlFunctionResult(thriftResult, returnType));
}
Also used : TypeSignature(com.facebook.presto.common.type.TypeSignature) SqlFunctionId(com.facebook.presto.spi.function.SqlFunctionId) ThriftFunctionHandle(com.facebook.presto.thrift.api.udf.ThriftFunctionHandle) ThriftUdfRequest(com.facebook.presto.thrift.api.udf.ThriftUdfRequest) SqlFunctionHandle(com.facebook.presto.spi.function.SqlFunctionHandle) ThriftUdfPage(com.facebook.presto.thrift.api.udf.ThriftUdfPage) ThriftUdfService(com.facebook.presto.thrift.api.udf.ThriftUdfService)

Example 7 with SqlFunctionId

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

the class TestMySqlFunctionNamespaceManager method getLatestFunctionHandle.

private FunctionHandle getLatestFunctionHandle(SqlFunctionId functionId) {
    FunctionNamespaceTransactionHandle transactionHandle = functionNamespaceManager.beginTransaction();
    Optional<SqlInvokedFunction> function = functionNamespaceManager.getFunctions(Optional.of(transactionHandle), functionId.getFunctionName()).stream().filter(candidate -> candidate.getFunctionId().equals(functionId)).max(comparing(SqlInvokedFunction::getRequiredVersion));
    assertTrue(function.isPresent());
    functionNamespaceManager.commit(transactionHandle);
    return function.get().getRequiredFunctionHandle();
}
Also used : FunctionNamespaceTransactionHandle(com.facebook.presto.spi.function.FunctionNamespaceTransactionHandle) Parameter(com.facebook.presto.spi.function.Parameter) Arrays(java.util.Arrays) TestingMySqlServer(com.facebook.presto.testing.mysql.TestingMySqlServer) Throwables.throwIfUnchecked(com.google.common.base.Throwables.throwIfUnchecked) Test(org.testng.annotations.Test) SqlInvokedFunction(com.facebook.presto.spi.function.SqlInvokedFunction) AfterMethod(org.testng.annotations.AfterMethod) TypeSignature(com.facebook.presto.common.type.TypeSignature) POWER_TOWER(com.facebook.presto.functionNamespace.testing.SqlInvokedFunctionTestUtils.POWER_TOWER) DriftNettyClientModule(com.facebook.drift.transport.netty.client.DriftNettyClientModule) Handle(org.jdbi.v3.core.Handle) Map(java.util.Map) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) FUNCTION_POWER_TOWER_DOUBLE_UPDATED(com.facebook.presto.functionNamespace.testing.SqlInvokedFunctionTestUtils.FUNCTION_POWER_TOWER_DOUBLE_UPDATED) FunctionVersion.withVersion(com.facebook.presto.spi.function.FunctionVersion.withVersion) SqlFunctionHandle(com.facebook.presto.spi.function.SqlFunctionHandle) Assert.assertFalse(org.testng.Assert.assertFalse) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Collections.nCopies(java.util.Collections.nCopies) BeforeClass(org.testng.annotations.BeforeClass) BeforeMethod(org.testng.annotations.BeforeMethod) DETERMINISTIC(com.facebook.presto.spi.function.RoutineCharacteristics.Determinism.DETERMINISTIC) TANGENT(com.facebook.presto.functionNamespace.testing.SqlInvokedFunctionTestUtils.TANGENT) SCALAR(com.facebook.presto.spi.function.FunctionKind.SCALAR) String.format(java.lang.String.format) FunctionMetadata(com.facebook.presto.spi.function.FunctionMetadata) List(java.util.List) RETURNS_NULL_ON_NULL_INPUT(com.facebook.presto.spi.function.RoutineCharacteristics.NullCallClause.RETURNS_NULL_ON_NULL_INPUT) Optional(java.util.Optional) ErrorCodeSupplier(com.facebook.presto.spi.ErrorCodeSupplier) FUNCTION_POWER_TOWER_INT(com.facebook.presto.functionNamespace.testing.SqlInvokedFunctionTestUtils.FUNCTION_POWER_TOWER_INT) AlterRoutineCharacteristics(com.facebook.presto.spi.function.AlterRoutineCharacteristics) Joiner(com.google.common.base.Joiner) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) Assert.assertEquals(org.testng.Assert.assertEquals) LifeCycleManager(com.facebook.airlift.bootstrap.LifeCycleManager) FUNCTION_POWER_TOWER_DOUBLE(com.facebook.presto.functionNamespace.testing.SqlInvokedFunctionTestUtils.FUNCTION_POWER_TOWER_DOUBLE) PrestoException(com.facebook.presto.spi.PrestoException) ImmutableList(com.google.common.collect.ImmutableList) ALREADY_EXISTS(com.facebook.presto.spi.StandardErrorCode.ALREADY_EXISTS) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) TEST_SCHEMA(com.facebook.presto.functionNamespace.testing.SqlInvokedFunctionTestUtils.TEST_SCHEMA) Comparator.comparing(java.util.Comparator.comparing) RoutineCharacteristics(com.facebook.presto.spi.function.RoutineCharacteristics) CALLED_ON_NULL_INPUT(com.facebook.presto.spi.function.RoutineCharacteristics.NullCallClause.CALLED_ON_NULL_INPUT) Jdbi(org.jdbi.v3.core.Jdbi) AfterClass(org.testng.annotations.AfterClass) TEST_CATALOG(com.facebook.presto.functionNamespace.testing.SqlInvokedFunctionTestUtils.TEST_CATALOG) Assert.fail(org.testng.Assert.fail) Closeables.closeQuietly(com.facebook.airlift.testing.Closeables.closeQuietly) Injector(com.google.inject.Injector) DOUBLE(com.facebook.presto.common.type.StandardTypes.DOUBLE) FUNCTION_TANGENT(com.facebook.presto.functionNamespace.testing.SqlInvokedFunctionTestUtils.FUNCTION_TANGENT) SqlFunctionId(com.facebook.presto.spi.function.SqlFunctionId) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) FunctionVersion.notVersioned(com.facebook.presto.spi.function.FunctionVersion.notVersioned) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle) Assert.assertTrue(org.testng.Assert.assertTrue) SimpleAddressSqlFunctionExecutorsModule(com.facebook.presto.functionNamespace.execution.SimpleAddressSqlFunctionExecutorsModule) FunctionNamespaceTransactionHandle(com.facebook.presto.spi.function.FunctionNamespaceTransactionHandle) SqlInvokedFunction(com.facebook.presto.spi.function.SqlInvokedFunction)

Example 8 with SqlFunctionId

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

the class InMemoryFunctionNamespaceManager method createFunction.

@Override
public synchronized void createFunction(SqlInvokedFunction function, boolean replace) {
    checkFunctionLanguageSupported(function);
    SqlFunctionId functionId = function.getFunctionId();
    if (!replace && latestFunctions.containsKey(function.getFunctionId())) {
        throw new PrestoException(GENERIC_USER_ERROR, format("Function '%s' already exists", functionId.getId()));
    }
    SqlInvokedFunction replacedFunction = latestFunctions.get(functionId);
    long version = 1;
    if (replacedFunction != null) {
        version = parseLong(replacedFunction.getRequiredVersion()) + 1;
    }
    latestFunctions.put(functionId, function.withVersion(String.valueOf(version)));
}
Also used : SqlFunctionId(com.facebook.presto.spi.function.SqlFunctionId) SqlInvokedFunction(com.facebook.presto.spi.function.SqlInvokedFunction) PrestoException(com.facebook.presto.spi.PrestoException)

Example 9 with SqlFunctionId

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

the class AbstractSqlInvokedFunctionNamespaceManager method getFunctionHandle.

@Override
public final FunctionHandle getFunctionHandle(Optional<? extends FunctionNamespaceTransactionHandle> transactionHandle, Signature signature) {
    checkCatalog(signature.getName());
    // This is the only assumption in this class that we're dealing with sql-invoked regular function.
    SqlFunctionId functionId = new SqlFunctionId(signature.getName(), signature.getArgumentTypes());
    if (transactionHandle.isPresent()) {
        return transactions.get(transactionHandle.get()).getFunctionHandle(functionId);
    }
    FunctionCollection collection = new FunctionCollection();
    collection.loadAndGetFunctionsTransactional(signature.getName());
    return collection.getFunctionHandle(functionId);
}
Also used : SqlFunctionId(com.facebook.presto.spi.function.SqlFunctionId)

Example 10 with SqlFunctionId

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

the class MySqlFunctionNamespaceManager method getSqlFunctions.

private List<SqlInvokedFunction> getSqlFunctions(FunctionNamespaceDao functionNamespaceDao, QualifiedObjectName functionName, Optional<List<TypeSignature>> parameterTypes) {
    List<SqlInvokedFunctionRecord> records = new ArrayList<>();
    if (parameterTypes.isPresent()) {
        SqlFunctionId functionId = new SqlFunctionId(functionName, parameterTypes.get());
        functionNamespaceDao.getLatestRecordForUpdate(hash(functionId), functionId).ifPresent(records::add);
    } else {
        records = functionNamespaceDao.getLatestRecordsForUpdate(functionName.getCatalogName(), functionName.getSchemaName(), functionName.getObjectName());
    }
    return records.stream().filter(record -> !record.isDeleted()).map(SqlInvokedFunctionRecord::getFunction).collect(toImmutableList());
}
Also used : SqlFunctionId(com.facebook.presto.spi.function.SqlFunctionId) ArrayList(java.util.ArrayList)

Aggregations

SqlFunctionId (com.facebook.presto.spi.function.SqlFunctionId)17 SqlInvokedFunction (com.facebook.presto.spi.function.SqlInvokedFunction)11 Map (java.util.Map)7 PrestoException (com.facebook.presto.spi.PrestoException)6 List (java.util.List)6 ImmutableList (com.google.common.collect.ImmutableList)5 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 PRIVATE (com.facebook.presto.bytecode.Access.PRIVATE)4 PUBLIC (com.facebook.presto.bytecode.Access.PUBLIC)4 Access.a (com.facebook.presto.bytecode.Access.a)4 BytecodeBlock (com.facebook.presto.bytecode.BytecodeBlock)4 BytecodeNode (com.facebook.presto.bytecode.BytecodeNode)4 CallSiteBinder (com.facebook.presto.bytecode.CallSiteBinder)4 ClassDefinition (com.facebook.presto.bytecode.ClassDefinition)4 FieldDefinition (com.facebook.presto.bytecode.FieldDefinition)4 MethodDefinition (com.facebook.presto.bytecode.MethodDefinition)4 Parameter (com.facebook.presto.bytecode.Parameter)4 Parameter.arg (com.facebook.presto.bytecode.Parameter.arg)4 ParameterizedType (com.facebook.presto.bytecode.ParameterizedType)4