use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class ScalarFromAnnotationsParser method parseParametricScalar.
private static SqlScalarFunction parseParametricScalar(ScalarHeaderAndMethods scalar, Optional<Constructor<?>> constructor) {
ScalarImplementationHeader header = scalar.getHeader();
Map<SpecializedSignature, ParametricScalarImplementation.Builder> signatures = new HashMap<>();
for (Method method : scalar.getMethods()) {
ParametricScalarImplementation implementation = ParametricScalarImplementation.Parser.parseImplementation(header, method, constructor);
if (!signatures.containsKey(implementation.getSpecializedSignature())) {
ParametricScalarImplementation.Builder builder = new ParametricScalarImplementation.Builder(implementation.getSignature(), implementation.getArgumentNativeContainerTypes(), implementation.getSpecializedTypeParameters(), implementation.getReturnNativeContainerType());
signatures.put(implementation.getSpecializedSignature(), builder);
builder.addChoices(implementation);
} else {
ParametricScalarImplementation.Builder builder = signatures.get(implementation.getSpecializedSignature());
builder.addChoices(implementation);
}
}
ParametricImplementationsGroup.Builder<ParametricScalarImplementation> implementationsBuilder = ParametricImplementationsGroup.builder();
for (ParametricScalarImplementation.Builder implementation : signatures.values()) {
implementationsBuilder.addImplementation(implementation.build());
}
ParametricImplementationsGroup<ParametricScalarImplementation> implementations = implementationsBuilder.build();
Signature scalarSignature = implementations.getSignature();
header.getOperatorType().ifPresent(operatorType -> validateOperator(operatorType, scalarSignature.getReturnType(), scalarSignature.getArgumentTypes()));
return new ParametricScalar(scalarSignature, header.getHeader(), implementations);
}
use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class WindowAnnotationsParser method parse.
private static SqlWindowFunction parse(Class<? extends WindowFunction> clazz, WindowFunctionSignature window) {
List<TypeVariableConstraint> typeVariables = ImmutableList.of();
if (!window.typeVariable().isEmpty()) {
typeVariables = ImmutableList.of(typeVariable(window.typeVariable()));
}
List<TypeSignature> argumentTypes = Stream.of(window.argumentTypes()).map(TypeSignature::parseTypeSignature).collect(toImmutableList());
Signature signature = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, window.name()), WINDOW, typeVariables, ImmutableList.of(), parseTypeSignature(window.returnType()), argumentTypes, false);
return new SqlWindowFunction(new ReflectionWindowFunctionSupplier<>(signature, clazz));
}
use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class HiveScalarFunction method createHiveScalarFunction.
public static HiveScalarFunction createHiveScalarFunction(Class<?> cls, QualifiedObjectName name, List<TypeSignature> argumentTypes, TypeManager typeManager) {
HiveScalarFunctionInvoker invoker = createFunctionInvoker(cls, name, argumentTypes, typeManager);
MethodHandle methodHandle = ScalarMethodHandles.generateUnbound(invoker.getSignature(), typeManager).bindTo(invoker);
Signature signature = invoker.getSignature();
FunctionMetadata functionMetadata = new FunctionMetadata(name, signature.getArgumentTypes(), signature.getReturnType(), SCALAR, FunctionImplementationType.JAVA, true, true);
InvocationConvention invocationConvention = new InvocationConvention(signature.getArgumentTypes().stream().map(t -> BOXED_NULLABLE).collect(toImmutableList()), InvocationConvention.InvocationReturnConvention.NULLABLE_RETURN, false);
JavaScalarFunctionImplementation implementation = new HiveScalarFunctionImplementation(methodHandle, invocationConvention);
return new HiveScalarFunction(functionMetadata, signature, name.getObjectName(), implementation);
}
use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class HiveFunctionNamespaceManager method createDummyHiveScalarFunction.
private HiveFunction createDummyHiveScalarFunction(String functionName) {
QualifiedObjectName hiveFunctionName = QualifiedObjectName.valueOf(catalogName, "default", functionName);
Signature signature = new Signature(hiveFunctionName, SCALAR, TypeSignature.parseTypeSignature("T"));
return new DummyHiveScalarFunction(signature);
}
use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class PolymorphicScalarFunction method applyExtraParameters.
private MethodHandle applyExtraParameters(Method matchingMethod, List<Object> extraParameters, List<ArgumentProperty> argumentProperties) {
Signature signature = getSignature();
int expectedArgumentsCount = signature.getArgumentTypes().size() + getNullFlagsCount(argumentProperties) + getBlockPositionCount(argumentProperties) + extraParameters.size();
int matchingMethodArgumentCount = matchingMethod.getParameterCount();
checkState(matchingMethodArgumentCount == expectedArgumentsCount, "method %s has invalid number of arguments: %s (should have %s)", matchingMethod.getName(), matchingMethodArgumentCount, expectedArgumentsCount);
MethodHandle matchingMethodHandle = Reflection.methodHandle(matchingMethod);
matchingMethodHandle = MethodHandles.insertArguments(matchingMethodHandle, matchingMethodArgumentCount - extraParameters.size(), extraParameters.toArray());
return matchingMethodHandle;
}
Aggregations