Search in sources :

Example 11 with AccumulatorStateDescriptor

use of io.prestosql.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor in project hetu-core by openlookeng.

the class MultimapAggregationFunction method generateAggregation.

private InternalAggregationFunction generateAggregation(Type keyType, Type valueType, Type outputType) {
    DynamicClassLoader classLoader = new DynamicClassLoader(MultimapAggregationFunction.class.getClassLoader());
    List<Type> inputTypes = ImmutableList.of(keyType, valueType);
    MultimapAggregationStateSerializer stateSerializer = new MultimapAggregationStateSerializer(keyType, valueType);
    Type intermediateType = stateSerializer.getSerializedType();
    AggregationMetadata metadata = new AggregationMetadata(generateAggregationName(NAME, outputType.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), createInputParameterMetadata(keyType, valueType), INPUT_FUNCTION, COMBINE_FUNCTION, OUTPUT_FUNCTION.bindTo(keyType).bindTo(valueType), ImmutableList.of(new AccumulatorStateDescriptor(MultimapAggregationState.class, stateSerializer, new MultimapAggregationStateFactory(keyType, valueType, groupMode))), outputType);
    GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader);
    return new InternalAggregationFunction(NAME, inputTypes, ImmutableList.of(intermediateType), outputType, true, true, factory);
}
Also used : DynamicClassLoader(io.airlift.bytecode.DynamicClassLoader) Type(io.prestosql.spi.type.Type) ArrayType(io.prestosql.spi.type.ArrayType) AccumulatorStateDescriptor(io.prestosql.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor) GenericAccumulatorFactoryBinder(io.prestosql.operator.aggregation.GenericAccumulatorFactoryBinder) AggregationMetadata(io.prestosql.operator.aggregation.AggregationMetadata) InternalAggregationFunction(io.prestosql.operator.aggregation.InternalAggregationFunction)

Example 12 with AccumulatorStateDescriptor

use of io.prestosql.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor in project hetu-core by openlookeng.

the class AbstractMinMaxAggregationFunction method generateAggregation.

protected InternalAggregationFunction generateAggregation(Type type, MethodHandle compareMethodHandle) {
    DynamicClassLoader classLoader = new DynamicClassLoader(AbstractMinMaxAggregationFunction.class.getClassLoader());
    List<Type> inputTypes = ImmutableList.of(type);
    MethodHandle inputFunction;
    MethodHandle combineFunction;
    MethodHandle outputFunction;
    Class<? extends AccumulatorState> stateInterface;
    AccumulatorStateSerializer<?> stateSerializer;
    if (type.getJavaType() == long.class) {
        stateInterface = NullableLongState.class;
        stateSerializer = StateCompiler.generateStateSerializer(stateInterface, classLoader);
        inputFunction = LONG_INPUT_FUNCTION.bindTo(compareMethodHandle);
        combineFunction = LONG_COMBINE_FUNCTION.bindTo(compareMethodHandle);
        outputFunction = LONG_OUTPUT_FUNCTION.bindTo(type);
    } else if (type.getJavaType() == double.class) {
        stateInterface = NullableDoubleState.class;
        stateSerializer = StateCompiler.generateStateSerializer(stateInterface, classLoader);
        inputFunction = DOUBLE_INPUT_FUNCTION.bindTo(compareMethodHandle);
        combineFunction = DOUBLE_COMBINE_FUNCTION.bindTo(compareMethodHandle);
        outputFunction = DOUBLE_OUTPUT_FUNCTION.bindTo(type);
    } else if (type.getJavaType() == boolean.class) {
        stateInterface = NullableBooleanState.class;
        stateSerializer = StateCompiler.generateStateSerializer(stateInterface, classLoader);
        inputFunction = BOOLEAN_INPUT_FUNCTION.bindTo(compareMethodHandle);
        combineFunction = BOOLEAN_COMBINE_FUNCTION.bindTo(compareMethodHandle);
        outputFunction = BOOLEAN_OUTPUT_FUNCTION.bindTo(type);
    } else {
        // native container type is Slice or Block
        stateInterface = BlockPositionState.class;
        stateSerializer = new BlockPositionStateSerializer(type);
        inputFunction = min ? BLOCK_POSITION_MIN_INPUT_FUNCTION.bindTo(type) : BLOCK_POSITION_MAX_INPUT_FUNCTION.bindTo(type);
        combineFunction = min ? BLOCK_POSITION_MIN_COMBINE_FUNCTION.bindTo(type) : BLOCK_POSITION_MAX_COMBINE_FUNCTION.bindTo(type);
        outputFunction = BLOCK_POSITION_OUTPUT_FUNCTION.bindTo(type);
    }
    AccumulatorStateFactory<?> stateFactory = StateCompiler.generateStateFactory(stateInterface, classLoader);
    Type intermediateType = stateSerializer.getSerializedType();
    AggregationMetadata metadata = new AggregationMetadata(generateAggregationName(getSignature().getNameSuffix(), type.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), createParameterMetadata(type), inputFunction, combineFunction, outputFunction, ImmutableList.of(new AccumulatorStateDescriptor(stateInterface, stateSerializer, stateFactory)), type);
    GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader);
    return new InternalAggregationFunction(getSignature().getNameSuffix(), inputTypes, ImmutableList.of(intermediateType), type, true, false, factory);
}
Also used : DynamicClassLoader(io.airlift.bytecode.DynamicClassLoader) AccumulatorStateDescriptor(io.prestosql.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor) BlockPositionStateSerializer(io.prestosql.operator.aggregation.state.BlockPositionStateSerializer) OperatorType(io.prestosql.spi.function.OperatorType) Type(io.prestosql.spi.type.Type) NullableDoubleState(io.prestosql.operator.aggregation.state.NullableDoubleState) MethodHandle(java.lang.invoke.MethodHandle)

Example 13 with AccumulatorStateDescriptor

use of io.prestosql.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor in project hetu-core by openlookeng.

the class AbstractMinMaxNAggregationFunction method generateAggregation.

protected InternalAggregationFunction generateAggregation(Type type) {
    DynamicClassLoader classLoader = new DynamicClassLoader(AbstractMinMaxNAggregationFunction.class.getClassLoader());
    BlockComparator comparator = typeToComparator.apply(type);
    List<Type> inputTypes = ImmutableList.of(type, BIGINT);
    MinMaxNStateSerializer stateSerializer = new MinMaxNStateSerializer(comparator, type);
    Type intermediateType = stateSerializer.getSerializedType();
    ArrayType outputType = new ArrayType(type);
    List<ParameterMetadata> inputParameterMetadata = ImmutableList.of(new ParameterMetadata(STATE), new ParameterMetadata(BLOCK_INPUT_CHANNEL, type), new ParameterMetadata(INPUT_CHANNEL, BIGINT), new ParameterMetadata(BLOCK_INDEX));
    AggregationMetadata metadata = new AggregationMetadata(generateAggregationName(getSignature().getNameSuffix(), type.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), inputParameterMetadata, INPUT_FUNCTION.bindTo(comparator).bindTo(type), COMBINE_FUNCTION, OUTPUT_FUNCTION.bindTo(outputType), ImmutableList.of(new AccumulatorStateDescriptor(MinMaxNState.class, stateSerializer, new MinMaxNStateFactory())), outputType);
    GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader);
    return new InternalAggregationFunction(getSignature().getNameSuffix(), inputTypes, ImmutableList.of(intermediateType), outputType, true, false, factory);
}
Also used : DynamicClassLoader(io.airlift.bytecode.DynamicClassLoader) MinMaxNStateSerializer(io.prestosql.operator.aggregation.state.MinMaxNStateSerializer) AccumulatorStateDescriptor(io.prestosql.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor) ParameterMetadata(io.prestosql.operator.aggregation.AggregationMetadata.ParameterMetadata) ArrayType(io.prestosql.spi.type.ArrayType) Type(io.prestosql.spi.type.Type) ArrayType(io.prestosql.spi.type.ArrayType) MinMaxNStateFactory(io.prestosql.operator.aggregation.state.MinMaxNStateFactory)

Example 14 with AccumulatorStateDescriptor

use of io.prestosql.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor in project hetu-core by openlookeng.

the class ArbitraryAggregationFunction method generateAggregation.

private static InternalAggregationFunction generateAggregation(Type type) {
    DynamicClassLoader classLoader = new DynamicClassLoader(ArbitraryAggregationFunction.class.getClassLoader());
    List<Type> inputTypes = ImmutableList.of(type);
    MethodHandle inputFunction;
    MethodHandle combineFunction;
    MethodHandle outputFunction;
    Class<? extends AccumulatorState> stateInterface;
    AccumulatorStateSerializer<?> stateSerializer;
    if (type.getJavaType() == long.class) {
        stateInterface = NullableLongState.class;
        stateSerializer = StateCompiler.generateStateSerializer(stateInterface, classLoader);
        inputFunction = LONG_INPUT_FUNCTION;
        combineFunction = LONG_COMBINE_FUNCTION;
        outputFunction = LONG_OUTPUT_FUNCTION;
    } else if (type.getJavaType() == double.class) {
        stateInterface = NullableDoubleState.class;
        stateSerializer = StateCompiler.generateStateSerializer(stateInterface, classLoader);
        inputFunction = DOUBLE_INPUT_FUNCTION;
        combineFunction = DOUBLE_COMBINE_FUNCTION;
        outputFunction = DOUBLE_OUTPUT_FUNCTION;
    } else if (type.getJavaType() == boolean.class) {
        stateInterface = NullableBooleanState.class;
        stateSerializer = StateCompiler.generateStateSerializer(stateInterface, classLoader);
        inputFunction = BOOLEAN_INPUT_FUNCTION;
        combineFunction = BOOLEAN_COMBINE_FUNCTION;
        outputFunction = BOOLEAN_OUTPUT_FUNCTION;
    } else {
        // native container type is Slice or Block
        stateInterface = BlockPositionState.class;
        stateSerializer = new BlockPositionStateSerializer(type);
        inputFunction = BLOCK_POSITION_INPUT_FUNCTION;
        combineFunction = BLOCK_POSITION_COMBINE_FUNCTION;
        outputFunction = BLOCK_POSITION_OUTPUT_FUNCTION;
    }
    inputFunction = inputFunction.bindTo(type);
    Type intermediateType = stateSerializer.getSerializedType();
    List<ParameterMetadata> inputParameterMetadata = createInputParameterMetadata(type);
    AggregationMetadata metadata = new AggregationMetadata(generateAggregationName(NAME, type.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), inputParameterMetadata, inputFunction, combineFunction, outputFunction.bindTo(type), ImmutableList.of(new AccumulatorStateDescriptor(stateInterface, stateSerializer, StateCompiler.generateStateFactory(stateInterface, classLoader))), type);
    GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader);
    return new InternalAggregationFunction(NAME, inputTypes, ImmutableList.of(intermediateType), type, true, false, factory);
}
Also used : DynamicClassLoader(io.airlift.bytecode.DynamicClassLoader) AccumulatorStateDescriptor(io.prestosql.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor) BlockPositionStateSerializer(io.prestosql.operator.aggregation.state.BlockPositionStateSerializer) ParameterMetadata(io.prestosql.operator.aggregation.AggregationMetadata.ParameterMetadata) Type(io.prestosql.spi.type.Type) NullableDoubleState(io.prestosql.operator.aggregation.state.NullableDoubleState) MethodHandle(java.lang.invoke.MethodHandle)

Example 15 with AccumulatorStateDescriptor

use of io.prestosql.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor in project hetu-core by openlookeng.

the class MergeQuantileDigestFunction method generateAggregation.

private static InternalAggregationFunction generateAggregation(Type valueType, QuantileDigestType type) {
    DynamicClassLoader classLoader = new DynamicClassLoader(MapAggregationFunction.class.getClassLoader());
    QuantileDigestStateSerializer stateSerializer = new QuantileDigestStateSerializer(valueType);
    Type intermediateType = stateSerializer.getSerializedType();
    AggregationMetadata metadata = new AggregationMetadata(generateAggregationName(NAME, type.getTypeSignature(), ImmutableList.of(type.getTypeSignature())), createInputParameterMetadata(type), INPUT_FUNCTION.bindTo(type), COMBINE_FUNCTION, OUTPUT_FUNCTION.bindTo(stateSerializer), ImmutableList.of(new AccumulatorStateDescriptor(QuantileDigestState.class, stateSerializer, new QuantileDigestStateFactory())), type);
    GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader);
    return new InternalAggregationFunction(NAME, ImmutableList.of(type), ImmutableList.of(intermediateType), type, true, true, factory);
}
Also used : DynamicClassLoader(io.airlift.bytecode.DynamicClassLoader) QuantileDigestStateSerializer(io.prestosql.operator.aggregation.state.QuantileDigestStateSerializer) QuantileDigestType(io.prestosql.spi.type.QuantileDigestType) Type(io.prestosql.spi.type.Type) AccumulatorStateDescriptor(io.prestosql.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor) QuantileDigestStateFactory(io.prestosql.operator.aggregation.state.QuantileDigestStateFactory)

Aggregations

AccumulatorStateDescriptor (io.prestosql.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor)20 DynamicClassLoader (io.airlift.bytecode.DynamicClassLoader)19 Type (io.prestosql.spi.type.Type)17 MethodHandle (java.lang.invoke.MethodHandle)9 AggregationMetadata (io.prestosql.operator.aggregation.AggregationMetadata)5 ParameterMetadata (io.prestosql.operator.aggregation.AggregationMetadata.ParameterMetadata)5 GenericAccumulatorFactoryBinder (io.prestosql.operator.aggregation.GenericAccumulatorFactoryBinder)5 InternalAggregationFunction (io.prestosql.operator.aggregation.InternalAggregationFunction)5 ArrayType (io.prestosql.spi.type.ArrayType)5 NullableDoubleState (io.prestosql.operator.aggregation.state.NullableDoubleState)3 ClassDefinition (io.airlift.bytecode.ClassDefinition)2 BlockPositionStateSerializer (io.prestosql.operator.aggregation.state.BlockPositionStateSerializer)2 KeyValuePairStateSerializer (io.prestosql.operator.aggregation.state.KeyValuePairStateSerializer)2 KeyValuePairsStateFactory (io.prestosql.operator.aggregation.state.KeyValuePairsStateFactory)2 LongState (io.prestosql.operator.aggregation.state.LongState)2 NullableLongState (io.prestosql.operator.aggregation.state.NullableLongState)2 QuantileDigestStateFactory (io.prestosql.operator.aggregation.state.QuantileDigestStateFactory)2 QuantileDigestStateSerializer (io.prestosql.operator.aggregation.state.QuantileDigestStateSerializer)2 OperatorType (io.prestosql.spi.function.OperatorType)2 DecimalType (io.prestosql.spi.type.DecimalType)2