use of com.facebook.presto.spi.function.AggregationFunction in project presto by prestodb.
the class AggregationCompiler method generateBindableAggregationFunctions.
public static List<BindableAggregationFunction> generateBindableAggregationFunctions(Class<?> aggregationDefinition) {
AggregationFunction aggregationAnnotation = aggregationDefinition.getAnnotation(AggregationFunction.class);
requireNonNull(aggregationAnnotation, "aggregationAnnotation is null");
DynamicClassLoader classLoader = new DynamicClassLoader(aggregationDefinition.getClassLoader());
ImmutableList.Builder<BindableAggregationFunction> builder = ImmutableList.builder();
for (Class<?> stateClass : getStateClasses(aggregationDefinition)) {
AccumulatorStateSerializer<?> stateSerializer = StateCompiler.generateStateSerializer(stateClass, classLoader);
for (Method outputFunction : getOutputFunctions(aggregationDefinition, stateClass)) {
for (Method inputFunction : getInputFunctions(aggregationDefinition, stateClass)) {
List<LongVariableConstraint> longVariableConstraints = parseLongVariableConstraints(inputFunction);
for (String name : getNames(outputFunction, aggregationAnnotation)) {
List<TypeSignature> inputTypes = getInputTypesSignatures(inputFunction);
TypeSignature outputType = TypeSignature.parseTypeSignature(outputFunction.getAnnotation(OutputFunction.class).value());
builder.add(new BindableAggregationFunction(new Signature(name, FunctionKind.AGGREGATE, // TODO parse constrains from annotations
ImmutableList.of(), longVariableConstraints, outputType, inputTypes, false), getDescription(aggregationDefinition, outputFunction), aggregationAnnotation.decomposable(), aggregationDefinition, stateClass, inputFunction, outputFunction));
}
}
}
}
return builder.build();
}
use of com.facebook.presto.spi.function.AggregationFunction in project presto by prestodb.
the class AggregationFromAnnotationsParser method parseFunctionDefinitions.
public static List<ParametricAggregation> parseFunctionDefinitions(Class<?> aggregationDefinition) {
AggregationFunction aggregationAnnotation = aggregationDefinition.getAnnotation(AggregationFunction.class);
requireNonNull(aggregationAnnotation, "aggregationAnnotation is null");
ImmutableList.Builder<ParametricAggregation> builder = ImmutableList.builder();
for (Class<?> stateClass : getStateClasses(aggregationDefinition)) {
Method combineFunction = getCombineFunction(aggregationDefinition, stateClass);
Optional<Method> aggregationStateSerializerFactory = getAggregationStateSerializerFactory(aggregationDefinition, stateClass);
for (Method outputFunction : getOutputFunctions(aggregationDefinition, stateClass)) {
for (Method inputFunction : getInputFunctions(aggregationDefinition, stateClass)) {
for (AggregationHeader header : parseHeaders(aggregationDefinition, outputFunction)) {
AggregationImplementation onlyImplementation = parseImplementation(aggregationDefinition, header, stateClass, inputFunction, outputFunction, combineFunction, aggregationStateSerializerFactory);
ParametricImplementationsGroup<AggregationImplementation> implementations = ParametricImplementationsGroup.of(onlyImplementation);
builder.add(new ParametricAggregation(implementations.getSignature(), header, implementations));
}
}
}
}
return builder.build();
}
use of com.facebook.presto.spi.function.AggregationFunction in project presto by prestodb.
the class AggregationFromAnnotationsParser method parseHeader.
private static AggregationHeader parseHeader(AnnotatedElement aggregationDefinition) {
AggregationFunction aggregationAnnotation = aggregationDefinition.getAnnotation(AggregationFunction.class);
requireNonNull(aggregationAnnotation, "aggregationAnnotation is null");
return new AggregationHeader(aggregationAnnotation.value(), parseDescription(aggregationDefinition), aggregationAnnotation.decomposable(), aggregationAnnotation.isOrderSensitive(), aggregationAnnotation.visibility());
}
use of com.facebook.presto.spi.function.AggregationFunction in project presto by prestodb.
the class BindableAggregationFunction method specialize.
@Override
public InternalAggregationFunction specialize(BoundVariables variables, int arity, TypeManager typeManager, FunctionRegistry functionRegistry) {
// bind variables
Signature boundSignature = applyBoundVariables(getSignature(), variables, arity);
List<Type> inputTypes = boundSignature.getArgumentTypes().stream().map(x -> typeManager.getType(x)).collect(toImmutableList());
Type outputType = typeManager.getType(boundSignature.getReturnType());
AggregationFunction aggregationAnnotation = definitionClass.getAnnotation(AggregationFunction.class);
requireNonNull(aggregationAnnotation, "aggregationAnnotation is null");
DynamicClassLoader classLoader = new DynamicClassLoader(definitionClass.getClassLoader(), getClass().getClassLoader());
AggregationMetadata metadata;
AccumulatorStateSerializer<?> stateSerializer = StateCompiler.generateStateSerializer(stateClass, classLoader);
Type intermediateType = stateSerializer.getSerializedType();
Method combineFunction = AggregationCompiler.getCombineFunction(definitionClass, stateClass);
AccumulatorStateFactory<?> stateFactory = StateCompiler.generateStateFactory(stateClass, classLoader);
try {
MethodHandle inputHandle = lookup().unreflect(inputFunction);
MethodHandle combineHandle = lookup().unreflect(combineFunction);
MethodHandle outputHandle = outputFunction == null ? null : lookup().unreflect(outputFunction);
metadata = new AggregationMetadata(generateAggregationName(getSignature().getName(), outputType.getTypeSignature(), signaturesFromTypes(inputTypes)), getParameterMetadata(inputFunction, inputTypes), inputHandle, combineHandle, outputHandle, stateClass, stateSerializer, stateFactory, outputType);
} catch (IllegalAccessException e) {
throw Throwables.propagate(e);
}
AccumulatorFactoryBinder factory = new LazyAccumulatorFactoryBinder(metadata, classLoader);
return new InternalAggregationFunction(getSignature().getName(), inputTypes, intermediateType, outputType, decomposable, factory);
}
use of com.facebook.presto.spi.function.AggregationFunction in project presto by prestodb.
the class AggregationCompiler method getNames.
private static List<String> getNames(@Nullable Method outputFunction, AggregationFunction aggregationAnnotation) {
List<String> defaultNames = ImmutableList.<String>builder().add(aggregationAnnotation.value()).addAll(Arrays.asList(aggregationAnnotation.alias())).build();
if (outputFunction == null) {
return defaultNames;
}
AggregationFunction annotation = outputFunction.getAnnotation(AggregationFunction.class);
if (annotation == null) {
return defaultNames;
} else {
return ImmutableList.<String>builder().add(annotation.value()).addAll(Arrays.asList(annotation.alias())).build();
}
}
Aggregations