Search in sources :

Example 36 with Signature

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);
}
Also used : SpecializedSignature(com.facebook.presto.operator.scalar.annotations.ParametricScalarImplementation.SpecializedSignature) HashMap(java.util.HashMap) ParametricImplementationsGroup(com.facebook.presto.operator.ParametricImplementationsGroup) Method(java.lang.reflect.Method) SpecializedSignature(com.facebook.presto.operator.scalar.annotations.ParametricScalarImplementation.SpecializedSignature) Signature(com.facebook.presto.spi.function.Signature) ParametricScalar(com.facebook.presto.operator.scalar.ParametricScalar)

Example 37 with Signature

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));
}
Also used : TypeSignature(com.facebook.presto.common.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) WindowFunctionSignature(com.facebook.presto.spi.function.WindowFunctionSignature) TypeSignature(com.facebook.presto.common.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) Signature(com.facebook.presto.spi.function.Signature) TypeVariableConstraint(com.facebook.presto.spi.function.TypeVariableConstraint)

Example 38 with Signature

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);
}
Also used : FunctionMetadata(com.facebook.presto.spi.function.FunctionMetadata) JavaScalarFunctionImplementation(com.facebook.presto.spi.function.JavaScalarFunctionImplementation) TypeSignature(com.facebook.presto.common.type.TypeSignature) Signature(com.facebook.presto.spi.function.Signature) InvocationConvention(com.facebook.presto.spi.function.InvocationConvention) MethodHandle(java.lang.invoke.MethodHandle)

Example 39 with Signature

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);
}
Also used : TypeSignature(com.facebook.presto.common.type.TypeSignature) Signature(com.facebook.presto.spi.function.Signature) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName)

Example 40 with 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;
}
Also used : Signature(com.facebook.presto.spi.function.Signature) MethodHandle(java.lang.invoke.MethodHandle)

Aggregations

Signature (com.facebook.presto.spi.function.Signature)90 TypeSignature.parseTypeSignature (com.facebook.presto.common.type.TypeSignature.parseTypeSignature)79 TypeSignature (com.facebook.presto.common.type.TypeSignature)73 Test (org.testng.annotations.Test)64 SqlScalarFunction (com.facebook.presto.metadata.SqlScalarFunction)16 ParametricAggregation (com.facebook.presto.operator.aggregation.ParametricAggregation)14 ImmutableList (com.google.common.collect.ImmutableList)14 AggregationImplementation (com.facebook.presto.operator.aggregation.AggregationImplementation)13 AggregationMetadata (com.facebook.presto.operator.aggregation.AggregationMetadata)13 StandardTypes (com.facebook.presto.common.type.StandardTypes)12 InternalAggregationFunction (com.facebook.presto.operator.aggregation.InternalAggregationFunction)12 ParametricScalar (com.facebook.presto.operator.scalar.ParametricScalar)12 PrestoException (com.facebook.presto.spi.PrestoException)12 SCALAR (com.facebook.presto.spi.function.FunctionKind.SCALAR)12 ImmutableSet (com.google.common.collect.ImmutableSet)12 Slice (io.airlift.slice.Slice)12 BuiltInScalarFunctionImplementation (com.facebook.presto.operator.scalar.BuiltInScalarFunctionImplementation)11 ADD (com.facebook.presto.common.function.OperatorType.ADD)10 FunctionAndTypeManager.createTestFunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager)10 Math.toIntExact (java.lang.Math.toIntExact)10