use of io.prestosql.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor in project hetu-core by openlookeng.
the class ParametricAggregation method specialize.
@Override
public InternalAggregationFunction specialize(BoundVariables variables, int arity, FunctionAndTypeManager functionAndTypeManager) {
// Bind variables
Signature boundSignature = applyBoundVariables(getSignature(), variables, arity);
// Find implementation matching arguments
AggregationImplementation concreteImplementation = findMatchingImplementation(boundSignature, variables, functionAndTypeManager);
// Build argument and return Types from signatures
List<Type> inputTypes = boundSignature.getArgumentTypes().stream().map(functionAndTypeManager::getType).collect(toImmutableList());
Type outputType = functionAndTypeManager.getType(boundSignature.getReturnType());
// Create classloader for additional aggregation dependencies
Class<?> definitionClass = concreteImplementation.getDefinitionClass();
DynamicClassLoader classLoader = new DynamicClassLoader(definitionClass.getClassLoader(), getClass().getClassLoader());
// Build state factory and serializer
Class<?> stateClass = concreteImplementation.getStateClass();
AccumulatorStateSerializer<?> stateSerializer = getAccumulatorStateSerializer(concreteImplementation, variables, functionAndTypeManager, stateClass, classLoader);
AccumulatorStateFactory<?> stateFactory = StateCompiler.generateStateFactory(stateClass, classLoader);
// Bind provided dependencies to aggregation method handlers
MethodHandle inputHandle = bindDependencies(concreteImplementation.getInputFunction(), concreteImplementation.getInputDependencies(), variables, functionAndTypeManager);
MethodHandle combineHandle = bindDependencies(concreteImplementation.getCombineFunction(), concreteImplementation.getCombineDependencies(), variables, functionAndTypeManager);
MethodHandle outputHandle = bindDependencies(concreteImplementation.getOutputFunction(), concreteImplementation.getOutputDependencies(), variables, functionAndTypeManager);
// Build metadata of input parameters
List<ParameterMetadata> parametersMetadata = buildParameterMetadata(concreteImplementation.getInputParameterMetadataTypes(), inputTypes);
// Generate Aggregation name
String aggregationName = generateAggregationName(getSignature().getNameSuffix(), outputType.getTypeSignature(), signaturesFromTypes(inputTypes));
// Collect all collected data in Metadata
AggregationMetadata aggregationMetadata = new AggregationMetadata(aggregationName, parametersMetadata, inputHandle, combineHandle, outputHandle, ImmutableList.of(new AccumulatorStateDescriptor(stateClass, stateSerializer, stateFactory)), outputType);
// Create specialized InternalAggregregationFunction for Presto
return new InternalAggregationFunction(getSignature().getNameSuffix(), inputTypes, ImmutableList.of(stateSerializer.getSerializedType()), outputType, details.isDecomposable(), details.isOrderSensitive(), new LazyAccumulatorFactoryBinder(aggregationMetadata, classLoader));
}
use of io.prestosql.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor in project hetu-core by openlookeng.
the class QuantileDigestAggregationFunction method generateAggregation.
private static InternalAggregationFunction generateAggregation(Type valueType, QuantileDigestType outputType, int arity) {
DynamicClassLoader classLoader = new DynamicClassLoader(QuantileDigestAggregationFunction.class.getClassLoader());
List<Type> inputTypes = getInputTypes(valueType, arity);
QuantileDigestStateSerializer stateSerializer = new QuantileDigestStateSerializer(valueType);
Type intermediateType = stateSerializer.getSerializedType();
AggregationMetadata metadata = new AggregationMetadata(generateAggregationName(NAME, outputType.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), createInputParameterMetadata(inputTypes), getMethodHandle(valueType, arity), COMBINE_FUNCTION, OUTPUT_FUNCTION.bindTo(stateSerializer), ImmutableList.of(new AccumulatorStateDescriptor(QuantileDigestState.class, stateSerializer, new QuantileDigestStateFactory())), outputType);
GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader);
return new InternalAggregationFunction(NAME, inputTypes, ImmutableList.of(intermediateType), outputType, true, true, factory);
}
use of io.prestosql.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor in project hetu-core by openlookeng.
the class DecimalAverageAggregation method generateAggregation.
private static InternalAggregationFunction generateAggregation(Type type) {
checkArgument(type instanceof DecimalType, "type must be Decimal");
DynamicClassLoader classLoader = new DynamicClassLoader(DecimalAverageAggregation.class.getClassLoader());
List<Type> inputTypes = ImmutableList.of(type);
MethodHandle inputFunction;
MethodHandle outputFunction;
Class<? extends AccumulatorState> stateInterface = LongDecimalWithOverflowAndLongState.class;
AccumulatorStateSerializer<?> stateSerializer = new LongDecimalWithOverflowAndLongStateSerializer();
if (((DecimalType) type).isShort()) {
inputFunction = SHORT_DECIMAL_INPUT_FUNCTION;
outputFunction = SHORT_DECIMAL_OUTPUT_FUNCTION;
} else {
inputFunction = LONG_DECIMAL_INPUT_FUNCTION;
outputFunction = LONG_DECIMAL_OUTPUT_FUNCTION;
}
inputFunction = inputFunction.bindTo(type);
outputFunction = outputFunction.bindTo(type);
AggregationMetadata metadata = new AggregationMetadata(generateAggregationName(NAME, type.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), createInputParameterMetadata(type), inputFunction, COMBINE_FUNCTION, outputFunction, ImmutableList.of(new AccumulatorStateDescriptor(stateInterface, stateSerializer, new LongDecimalWithOverflowAndLongStateFactory())), type);
Type intermediateType = stateSerializer.getSerializedType();
GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader);
return new InternalAggregationFunction(NAME, inputTypes, ImmutableList.of(intermediateType), type, true, false, factory);
}
use of io.prestosql.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor in project hetu-core by openlookeng.
the class DecimalSumAggregation method generateAggregation.
private static InternalAggregationFunction generateAggregation(Type inputType, Type outputType) {
checkArgument(inputType instanceof DecimalType, "type must be Decimal");
DynamicClassLoader classLoader = new DynamicClassLoader(DecimalSumAggregation.class.getClassLoader());
List<Type> inputTypes = ImmutableList.of(inputType);
MethodHandle inputFunction;
Class<? extends AccumulatorState> stateInterface = LongDecimalWithOverflowState.class;
AccumulatorStateSerializer<?> stateSerializer = new LongDecimalWithOverflowStateSerializer();
if (((DecimalType) inputType).isShort()) {
inputFunction = SHORT_DECIMAL_INPUT_FUNCTION;
} else {
inputFunction = LONG_DECIMAL_INPUT_FUNCTION;
}
AggregationMetadata metadata = new AggregationMetadata(generateAggregationName(NAME, outputType.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), createInputParameterMetadata(inputType), inputFunction.bindTo(inputType), COMBINE_FUNCTION, LONG_DECIMAL_OUTPUT_FUNCTION.bindTo(outputType), ImmutableList.of(new AccumulatorStateDescriptor(stateInterface, stateSerializer, new LongDecimalWithOverflowStateFactory())), outputType);
Type intermediateType = stateSerializer.getSerializedType();
GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader);
return new InternalAggregationFunction(NAME, inputTypes, ImmutableList.of(intermediateType), outputType, true, false, factory);
}
use of io.prestosql.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor in project hetu-core by openlookeng.
the class ArrayAggregationFunction method generateAggregation.
private static InternalAggregationFunction generateAggregation(Type type, ArrayAggGroupImplementation groupMode) {
DynamicClassLoader classLoader = new DynamicClassLoader(ArrayAggregationFunction.class.getClassLoader());
AccumulatorStateSerializer<?> stateSerializer = new ArrayAggregationStateSerializer(type);
AccumulatorStateFactory<?> stateFactory = new ArrayAggregationStateFactory(type, groupMode);
List<Type> inputTypes = ImmutableList.of(type);
Type outputType = new ArrayType(type);
Type intermediateType = stateSerializer.getSerializedType();
List<ParameterMetadata> inputParameterMetadata = createInputParameterMetadata(type);
MethodHandle inputFunction = INPUT_FUNCTION.bindTo(type);
MethodHandle combineFunction = COMBINE_FUNCTION.bindTo(type);
MethodHandle outputFunction = OUTPUT_FUNCTION.bindTo(type);
Class<? extends AccumulatorState> stateInterface = ArrayAggregationState.class;
AggregationMetadata metadata = new AggregationMetadata(generateAggregationName(NAME, type.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), inputParameterMetadata, inputFunction, combineFunction, outputFunction, ImmutableList.of(new AccumulatorStateDescriptor(stateInterface, stateSerializer, stateFactory)), outputType);
GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader);
return new InternalAggregationFunction(NAME, inputTypes, ImmutableList.of(intermediateType), outputType, true, true, factory);
}
Aggregations