protected List<MethodHandle> getMethodHandles(RowType type, FunctionRegistry functionRegistry, OperatorType operatorType) { ImmutableList.Builder<MethodHandle> argumentMethods = ImmutableList.builder(); for (Type parameterType : type.getTypeParameters()) { Signature signature = functionRegistry.resolveOperator(operatorType, ImmutableList.of(parameterType, parameterType)); argumentMethods.add(functionRegistry.getScalarFunctionImplementation(signature).getMethodHandle()); } return argumentMethods.build(); }
@Override public MethodHandle resolveOperator(OperatorType operatorType, List<? extends Type> argumentTypes) { requireNonNull(functionRegistry, "functionRegistry is null"); return functionRegistry.getScalarFunctionImplementation(functionRegistry.resolveOperator(operatorType, argumentTypes)).getMethodHandle(); }
private static MethodHandle resolveEqualOperator(Type type, FunctionRegistry functionRegistry) { Signature operator = functionRegistry.resolveOperator(EQUAL, ImmutableList.of(type, type)); ScalarFunctionImplementation implementation = functionRegistry.getScalarFunctionImplementation(operator); return implementation.getMethodHandle(); }
private DoubleStrategy(FunctionRegistry registry, Type type) { hashCodeHandle = registry.getScalarFunctionImplementation(registry.resolveOperator(HASH_CODE, ImmutableList.of(type))).getMethodHandle(); equalsHandle = registry.getScalarFunctionImplementation(registry.resolveOperator(EQUAL, ImmutableList.of(type, type))).getMethodHandle(); }
private LongStrategy(FunctionRegistry registry, Type type) { hashCodeHandle = registry.getScalarFunctionImplementation(registry.resolveOperator(HASH_CODE, ImmutableList.of(type))).getMethodHandle(); equalsHandle = registry.getScalarFunctionImplementation(registry.resolveOperator(EQUAL, ImmutableList.of(type, type))).getMethodHandle(); }
private static MethodHandle resolveEqualOperator(Type type, FunctionRegistry functionRegistry) { Signature operator = functionRegistry.resolveOperator(EQUAL, ImmutableList.of(type, type)); ScalarFunctionImplementation implementation = functionRegistry.getScalarFunctionImplementation(operator); return implementation.getMethodHandle(); }
protected List<MethodHandle> getMethodHandles(RowType type, FunctionRegistry functionRegistry, OperatorType operatorType) { ImmutableList.Builder<MethodHandle> argumentMethods = ImmutableList.builder(); for (Type parameterType : type.getTypeParameters()) { Signature signature = functionRegistry.resolveOperator(operatorType, ImmutableList.of(parameterType, parameterType)); argumentMethods.add(functionRegistry.getScalarFunctionImplementation(signature).getMethodHandle()); } return argumentMethods.build(); }
private DoubleStrategy(FunctionRegistry registry, Type type) { hashCodeHandle = registry.getScalarFunctionImplementation(registry.resolveOperator(HASH_CODE, ImmutableList.of(type))).getMethodHandle(); equalsHandle = registry.getScalarFunctionImplementation(registry.resolveOperator(EQUAL, ImmutableList.of(type, type))).getMethodHandle(); }
@Override public MethodHandle resolveOperator(OperatorType operatorType, List<? extends Type> argumentTypes) { requireNonNull(functionRegistry, "functionRegistry is null"); return functionRegistry.getScalarFunctionImplementation(functionRegistry.resolveOperator(operatorType, argumentTypes)).getMethodHandle(); }
private ObjectStrategy(FunctionRegistry registry, Type type) { hashCodeHandle = registry.getScalarFunctionImplementation(registry.resolveOperator(HASH_CODE, ImmutableList.of(type))) .getMethodHandle() .asType(MethodType.methodType(long.class, Object.class)); equalsHandle = registry.getScalarFunctionImplementation(registry.resolveOperator(EQUAL, ImmutableList.of(type, type))) .getMethodHandle() .asType(MethodType.methodType(Boolean.class, Object.class, Object.class)); }
@Override public Boolean visitCall(CallExpression call, Void context) { Signature signature = call.getSignature(); if (registry.isRegistered(signature) && !registry.getScalarFunctionImplementation(signature).isDeterministic()) { return false; } return call.getArguments().stream() .allMatch(expression -> expression.accept(this, context)); }
@Override public InternalAggregationFunction specialize(BoundVariables boundVariables, int arity, TypeManager typeManager, FunctionRegistry functionRegistry) { Type type = boundVariables.getTypeVariable("E"); MethodHandle compareMethodHandle = functionRegistry.getScalarFunctionImplementation(internalOperator(operatorType, BOOLEAN, ImmutableList.of(type, type))).getMethodHandle(); return generateAggregation(type, compareMethodHandle); }
@Override public Boolean visitCall(CallExpression call, Void context) { Signature signature = call.getSignature(); if (registry.isRegistered(signature) && !registry.getScalarFunctionImplementation(signature).isDeterministic()) { return false; } return call.getArguments().stream() .allMatch(expression -> expression.accept(this, context)); }
@Override public InternalAggregationFunction specialize(BoundVariables boundVariables, int arity, TypeManager typeManager, FunctionRegistry functionRegistry) { Type type = boundVariables.getTypeVariable("E"); MethodHandle compareMethodHandle = functionRegistry.getScalarFunctionImplementation(internalOperator(operatorType, BOOLEAN, ImmutableList.of(type, type))).getMethodHandle(); return generateAggregation(type, compareMethodHandle); }
@Override public MethodHandle resolve(BoundVariables boundVariables, TypeManager typeManager, FunctionRegistry functionRegistry) { Signature signature = applyBoundVariables(this.signature, boundVariables, this.signature.getArgumentTypes().size()); if (invocationConvention.isPresent()) { return functionRegistry.getFunctionInvokerProvider().createFunctionInvoker(signature, invocationConvention).methodHandle(); } else { return functionRegistry.getScalarFunctionImplementation(signature).getMethodHandle(); } }
@Override public MethodHandle resolve(BoundVariables boundVariables, TypeManager typeManager, FunctionRegistry functionRegistry) { Signature signature = applyBoundVariables(this.signature, boundVariables, this.signature.getArgumentTypes().size()); if (invocationConvention.isPresent()) { return functionRegistry.getFunctionInvokerProvider().createFunctionInvoker(signature, invocationConvention).methodHandle(); } else { return functionRegistry.getScalarFunctionImplementation(signature).getMethodHandle(); } }
@Override public BytecodeNode generateExpression(Signature signature, BytecodeGeneratorContext generatorContext, Type returnType, List<RowExpression> arguments) { RowExpression argument = arguments.get(0); Signature function = generatorContext .getRegistry() .getCoercion(argument.getType(), returnType); return generatorContext.generateCall(function.getName(), generatorContext.getRegistry().getScalarFunctionImplementation(function), ImmutableList.of(generatorContext.generate(argument))); } }
public FunctionInvoker createFunctionInvoker(Signature signature, Optional<InvocationConvention> invocationConvention) { ScalarFunctionImplementation scalarFunctionImplementation = functionRegistry.getScalarFunctionImplementation(signature); for (ScalarImplementationChoice choice : scalarFunctionImplementation.getAllChoices()) { if (checkChoice(choice.getArgumentProperties(), choice.isNullable(), choice.hasSession(), invocationConvention)) { return new FunctionInvoker(choice.getMethodHandle()); } } checkState(invocationConvention.isPresent()); throw new PrestoException(FUNCTION_NOT_FOUND, format("Dependent function implementation (%s) with convention (%s) is not available", signature, invocationConvention.toString())); }
public static MethodHandle distinctFromOperator(Type type) { Signature signature = FUNCTION_REGISTRY.resolveOperator(IS_DISTINCT_FROM, ImmutableList.of(type, type)); return FUNCTION_REGISTRY.getScalarFunctionImplementation(signature).getMethodHandle(); }
public FunctionInvoker createFunctionInvoker(Signature signature, Optional<InvocationConvention> invocationConvention) { ScalarFunctionImplementation scalarFunctionImplementation = functionRegistry.getScalarFunctionImplementation(signature); for (ScalarImplementationChoice choice : scalarFunctionImplementation.getAllChoices()) { if (checkChoice(choice.getArgumentProperties(), choice.isNullable(), choice.hasSession(), invocationConvention)) { return new FunctionInvoker(choice.getMethodHandle()); } } checkState(invocationConvention.isPresent()); throw new PrestoException(FUNCTION_NOT_FOUND, format("Dependent function implementation (%s) with convention (%s) is not available", signature, invocationConvention.toString())); }