use of com.facebook.presto.spi.function.OperatorType in project presto by prestodb.
the class TestFunctionRegistry method testExactMatchBeforeCoercion.
@Test
public void testExactMatchBeforeCoercion() {
TypeRegistry typeManager = new TypeRegistry();
FunctionRegistry registry = new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig());
boolean foundOperator = false;
for (SqlFunction function : registry.listOperators()) {
OperatorType operatorType = unmangleOperator(function.getSignature().getName());
if (operatorType == OperatorType.CAST || operatorType == OperatorType.SATURATED_FLOOR_CAST) {
continue;
}
if (!function.getSignature().getTypeVariableConstraints().isEmpty()) {
continue;
}
if (function.getSignature().getArgumentTypes().stream().anyMatch(TypeSignature::isCalculated)) {
continue;
}
Signature exactOperator = registry.resolveOperator(operatorType, resolveTypes(function.getSignature().getArgumentTypes(), typeManager));
assertEquals(exactOperator, function.getSignature());
foundOperator = true;
}
assertTrue(foundOperator);
}
use of com.facebook.presto.spi.function.OperatorType in project presto by prestodb.
the class AbstractMinMaxAggregationFunction method specialize.
@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);
}
use of com.facebook.presto.spi.function.OperatorType in project presto by prestodb.
the class AbstractMinMaxBy method generateAggregation.
private InternalAggregationFunction generateAggregation(Type valueType, Type keyType, FunctionRegistry functionRegistry) {
Class<?> stateClazz = getStateClass(keyType.getJavaType(), valueType.getJavaType());
Map<String, Type> stateFieldTypes = ImmutableMap.of("First", keyType, "Second", valueType);
DynamicClassLoader classLoader = new DynamicClassLoader(getClass().getClassLoader());
AccumulatorStateFactory<?> stateFactory = StateCompiler.generateStateFactory(stateClazz, stateFieldTypes, classLoader);
AccumulatorStateSerializer<?> stateSerializer = StateCompiler.generateStateSerializer(stateClazz, stateFieldTypes, classLoader);
Type intermediateType = stateSerializer.getSerializedType();
List<Type> inputTypes = ImmutableList.of(valueType, keyType);
CallSiteBinder binder = new CallSiteBinder();
OperatorType operator = min ? LESS_THAN : GREATER_THAN;
MethodHandle compareMethod = functionRegistry.getScalarFunctionImplementation(functionRegistry.resolveOperator(operator, ImmutableList.of(keyType, keyType))).getMethodHandle();
ClassDefinition definition = new ClassDefinition(a(PUBLIC, FINAL), makeClassName("processMaxOrMinBy"), type(Object.class));
definition.declareDefaultConstructor(a(PRIVATE));
generateInputMethod(definition, binder, compareMethod, keyType, valueType, stateClazz);
generateCombineMethod(definition, binder, compareMethod, keyType, valueType, stateClazz);
generateOutputMethod(definition, binder, valueType, stateClazz);
Class<?> generatedClass = defineClass(definition, Object.class, binder.getBindings(), classLoader);
MethodHandle inputMethod = methodHandle(generatedClass, "input", stateClazz, Block.class, Block.class, int.class);
MethodHandle combineMethod = methodHandle(generatedClass, "combine", stateClazz, stateClazz);
MethodHandle outputMethod = methodHandle(generatedClass, "output", stateClazz, BlockBuilder.class);
AggregationMetadata metadata = new AggregationMetadata(generateAggregationName(getSignature().getName(), valueType.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), createInputParameterMetadata(valueType, keyType), inputMethod, combineMethod, outputMethod, stateClazz, stateSerializer, stateFactory, valueType);
GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader);
return new InternalAggregationFunction(getSignature().getName(), inputTypes, intermediateType, valueType, true, factory);
}
use of com.facebook.presto.spi.function.OperatorType in project presto by prestodb.
the class RowComparisonOperator method getMethodHandles.
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();
}
use of com.facebook.presto.spi.function.OperatorType in project presto by prestodb.
the class AbstractGreatestLeast method specialize.
@Override
public ScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, TypeManager typeManager, FunctionRegistry functionRegistry) {
Type type = boundVariables.getTypeVariable("E");
checkArgument(type.isOrderable(), "Type must be orderable");
MethodHandle compareMethod = functionRegistry.getScalarFunctionImplementation(internalOperator(operatorType, BOOLEAN, ImmutableList.of(type, type))).getMethodHandle();
List<Class<?>> javaTypes = IntStream.range(0, arity).mapToObj(i -> type.getJavaType()).collect(toImmutableList());
Class<?> clazz = generate(javaTypes, type, compareMethod);
MethodHandle methodHandle = methodHandle(clazz, getSignature().getName(), javaTypes.toArray(new Class<?>[javaTypes.size()]));
List<Boolean> nullableParameters = ImmutableList.copyOf(Collections.nCopies(javaTypes.size(), false));
return new ScalarFunctionImplementation(false, nullableParameters, methodHandle, isDeterministic());
}
Aggregations