Search in sources :

Example 26 with DynamicClassLoader

use of com.facebook.presto.bytecode.DynamicClassLoader in project presto by prestodb.

the class AbstractMinMaxByNAggregationFunction method generateAggregation.

protected InternalAggregationFunction generateAggregation(Type valueType, Type keyType) {
    DynamicClassLoader classLoader = new DynamicClassLoader(AbstractMinMaxNAggregationFunction.class.getClassLoader());
    BlockComparator comparator = typeToComparator.apply(keyType);
    List<Type> inputTypes = ImmutableList.of(valueType, keyType, BIGINT);
    MinMaxByNStateSerializer stateSerializer = new MinMaxByNStateSerializer(comparator, keyType, valueType);
    Type intermediateType = stateSerializer.getSerializedType();
    ArrayType outputType = new ArrayType(valueType);
    List<AggregationMetadata.ParameterMetadata> inputParameterMetadata = ImmutableList.of(new AggregationMetadata.ParameterMetadata(STATE), new AggregationMetadata.ParameterMetadata(NULLABLE_BLOCK_INPUT_CHANNEL, valueType), new AggregationMetadata.ParameterMetadata(BLOCK_INPUT_CHANNEL, keyType), new AggregationMetadata.ParameterMetadata(BLOCK_INDEX), new AggregationMetadata.ParameterMetadata(INPUT_CHANNEL, BIGINT));
    AggregationMetadata metadata = new AggregationMetadata(generateAggregationName(name, valueType.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), inputParameterMetadata, INPUT_FUNCTION.bindTo(comparator).bindTo(valueType).bindTo(keyType), COMBINE_FUNCTION, OUTPUT_FUNCTION.bindTo(outputType), MinMaxByNState.class, stateSerializer, new MinMaxByNStateFactory(), outputType);
    GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader);
    return new InternalAggregationFunction(name, inputTypes, intermediateType, outputType, true, factory);
}
Also used : DynamicClassLoader(com.facebook.presto.bytecode.DynamicClassLoader) MinMaxByNStateSerializer(com.facebook.presto.operator.aggregation.state.MinMaxByNStateSerializer) MinMaxByNStateFactory(com.facebook.presto.operator.aggregation.state.MinMaxByNStateFactory) ArrayType(com.facebook.presto.type.ArrayType) ArrayType(com.facebook.presto.type.ArrayType) Type(com.facebook.presto.spi.type.Type)

Aggregations

DynamicClassLoader (com.facebook.presto.bytecode.DynamicClassLoader)26 Type (com.facebook.presto.spi.type.Type)18 MethodHandle (java.lang.invoke.MethodHandle)11 ClassDefinition (com.facebook.presto.bytecode.ClassDefinition)7 MethodDefinition (com.facebook.presto.bytecode.MethodDefinition)6 ArrayType (com.facebook.presto.type.ArrayType)6 MapType (com.facebook.presto.type.MapType)6 Parameter (com.facebook.presto.bytecode.Parameter)5 ImmutableList (com.google.common.collect.ImmutableList)5 BytecodeBlock (com.facebook.presto.bytecode.BytecodeBlock)4 Variable (com.facebook.presto.bytecode.Variable)4 Signature (com.facebook.presto.metadata.Signature)4 ParameterMetadata (com.facebook.presto.operator.aggregation.AggregationMetadata.ParameterMetadata)4 ImmutableCollectors.toImmutableList (com.facebook.presto.util.ImmutableCollectors.toImmutableList)4 CompilerUtils.defineClass (com.facebook.presto.bytecode.CompilerUtils.defineClass)3 Scope (com.facebook.presto.bytecode.Scope)3 BoundVariables (com.facebook.presto.metadata.BoundVariables)3 FunctionRegistry (com.facebook.presto.metadata.FunctionRegistry)3 Block (com.facebook.presto.spi.block.Block)3 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)3