use of com.facebook.presto.spi.function.FunctionMetadata in project presto by prestodb.
the class SpatialJoinUtils method getFlippedFunctionHandle.
public static FunctionHandle getFlippedFunctionHandle(CallExpression callExpression, FunctionAndTypeManager functionAndTypeManager) {
FunctionMetadata callExpressionMetadata = functionAndTypeManager.getFunctionMetadata(callExpression.getFunctionHandle());
checkArgument(callExpressionMetadata.getOperatorType().isPresent());
OperatorType operatorType = flip(callExpressionMetadata.getOperatorType().get());
List<TypeSignatureProvider> typeProviderList = fromTypes(callExpression.getArguments().stream().map(RowExpression::getType).collect(toImmutableList()));
checkArgument(typeProviderList.size() == 2, "Expected there to be only two arguments in type provider");
return functionAndTypeManager.resolveOperator(operatorType, ImmutableList.of(typeProviderList.get(1), typeProviderList.get(0)));
}
use of com.facebook.presto.spi.function.FunctionMetadata in project presto by prestodb.
the class RowExpressionVerifier method visitArithmeticBinary.
@Override
protected Boolean visitArithmeticBinary(ArithmeticBinaryExpression expected, RowExpression actual) {
if (actual instanceof CallExpression) {
FunctionMetadata functionMetadata = metadata.getFunctionAndTypeManager().getFunctionMetadata(((CallExpression) actual).getFunctionHandle());
if (!functionMetadata.getOperatorType().isPresent() || !functionMetadata.getOperatorType().get().isArithmeticOperator()) {
return false;
}
OperatorType actualOperatorType = functionMetadata.getOperatorType().get();
OperatorType expectedOperatorType = getOperatorType(expected.getOperator());
if (expectedOperatorType.equals(actualOperatorType)) {
return process(expected.getLeft(), ((CallExpression) actual).getArguments().get(0)) && process(expected.getRight(), ((CallExpression) actual).getArguments().get(1));
}
}
return false;
}
use of com.facebook.presto.spi.function.FunctionMetadata in project presto by prestodb.
the class TranslatorAnnotationParser method methodToFunctionMetadata.
private static FunctionMetadata methodToFunctionMetadata(ScalarTranslationHeader header, Method method) {
requireNonNull(header, "header is null");
// return type
SqlType annotatedReturnType = method.getAnnotation(SqlType.class);
checkArgument(annotatedReturnType != null, format("Method [%s] is missing @SqlType annotation", method));
TypeSignature returnType = parseTypeSignature(annotatedReturnType.value(), ImmutableSet.of());
// argument type
ImmutableList.Builder<TypeSignature> argumentTypes = new ImmutableList.Builder<>();
for (Parameter parameter : method.getParameters()) {
Annotation[] annotations = parameter.getAnnotations();
SqlType type = Stream.of(annotations).filter(SqlType.class::isInstance).map(SqlType.class::cast).findFirst().orElseThrow(() -> new IllegalArgumentException(format("Method [%s] is missing @SqlType annotation for parameter", method)));
TypeSignature typeSignature = parseTypeSignature(type.value(), ImmutableSet.of());
argumentTypes.add(typeSignature);
}
if (header.getOperatorType().isPresent()) {
return new FunctionMetadata(header.getOperatorType().get(), argumentTypes.build(), returnType, SCALAR, JAVA, header.isDeterministic(), header.isCalledOnNullInput());
}
return new FunctionMetadata(header.getName(), argumentTypes.build(), returnType, SCALAR, JAVA, header.isDeterministic(), header.isCalledOnNullInput());
}
use of com.facebook.presto.spi.function.FunctionMetadata in project presto by prestodb.
the class TestSqlInvokedFunctionNamespaceManager method testCaching.
@Test
public void testCaching() {
InMemoryFunctionNamespaceManager functionNamespaceManager = createFunctionNamespaceManager();
functionNamespaceManager.createFunction(FUNCTION_POWER_TOWER_DOUBLE, false);
// fetchFunctionsDirect does not produce the same function reference
SqlInvokedFunction function1 = getOnlyElement(functionNamespaceManager.fetchFunctionsDirect(POWER_TOWER));
SqlInvokedFunction function2 = getOnlyElement(functionNamespaceManager.fetchFunctionsDirect(POWER_TOWER));
assertEquals(function1, function2);
assertNotSame(function1, function2);
// fetchFunctionMetadataDirect does not produce the same metadata reference
FunctionMetadata metadata1 = functionNamespaceManager.fetchFunctionMetadataDirect(function1.getRequiredFunctionHandle());
FunctionMetadata metadata2 = functionNamespaceManager.fetchFunctionMetadataDirect(function2.getRequiredFunctionHandle());
assertEquals(metadata1, metadata2);
assertNotSame(metadata1, metadata2);
// getFunctionMetadata produces the same metadata reference
metadata1 = functionNamespaceManager.getFunctionMetadata(function1.getRequiredFunctionHandle());
metadata2 = functionNamespaceManager.getFunctionMetadata(function2.getRequiredFunctionHandle());
assertSame(metadata1, metadata2);
// getFunctions produces the same function collection reference
functionNamespaceManager.createFunction(FUNCTION_POWER_TOWER_INT, false);
FunctionNamespaceTransactionHandle transaction1 = functionNamespaceManager.beginTransaction();
FunctionNamespaceTransactionHandle transaction2 = functionNamespaceManager.beginTransaction();
Collection<SqlInvokedFunction> functions1 = functionNamespaceManager.getFunctions(Optional.of(transaction1), POWER_TOWER);
Collection<SqlInvokedFunction> functions2 = functionNamespaceManager.getFunctions(Optional.of(transaction2), POWER_TOWER);
assertEquals(functions1.size(), 2);
assertSame(functions1, functions2);
}
use of com.facebook.presto.spi.function.FunctionMetadata in project presto by prestodb.
the class TestMySqlFunctionNamespaceManager method assertGetFunctionMetadata.
private void assertGetFunctionMetadata(FunctionHandle functionHandle, SqlInvokedFunction expectFunction) {
FunctionMetadata functionMetadata = functionNamespaceManager.getFunctionMetadata(functionHandle);
assertEquals(functionMetadata.getName(), expectFunction.getSignature().getName());
assertFalse(functionMetadata.getOperatorType().isPresent());
assertEquals(functionMetadata.getArgumentTypes(), expectFunction.getSignature().getArgumentTypes());
assertEquals(functionMetadata.getReturnType(), expectFunction.getSignature().getReturnType());
assertEquals(functionMetadata.getFunctionKind(), SCALAR);
assertEquals(functionMetadata.isDeterministic(), expectFunction.isDeterministic());
assertEquals(functionMetadata.isCalledOnNullInput(), expectFunction.isCalledOnNullInput());
}
Aggregations