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));
}
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();
}
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)));
}
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);
}
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());
}
Aggregations