Search in sources :

Example 1 with AccumulatorStateDescriptor

use of io.trino.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor in project trino by trinodb.

the class MapUnionAggregation method specialize.

@Override
public AggregationMetadata specialize(BoundSignature boundSignature) {
    MapType outputType = (MapType) boundSignature.getReturnType();
    Type keyType = outputType.getKeyType();
    BlockPositionEqual keyEqual = blockTypeOperators.getEqualOperator(keyType);
    BlockPositionHashCode keyHashCode = blockTypeOperators.getHashCodeOperator(keyType);
    Type valueType = outputType.getValueType();
    KeyValuePairStateSerializer stateSerializer = new KeyValuePairStateSerializer(outputType, keyEqual, keyHashCode);
    MethodHandle inputFunction = MethodHandles.insertArguments(INPUT_FUNCTION, 0, keyType, keyEqual, keyHashCode, valueType);
    inputFunction = normalizeInputMethod(inputFunction, boundSignature, STATE, INPUT_CHANNEL);
    return new AggregationMetadata(inputFunction, Optional.empty(), Optional.of(COMBINE_FUNCTION), OUTPUT_FUNCTION, ImmutableList.of(new AccumulatorStateDescriptor<>(KeyValuePairsState.class, stateSerializer, new KeyValuePairsStateFactory(keyType, valueType))));
}
Also used : BlockPositionEqual(io.trino.type.BlockTypeOperators.BlockPositionEqual) Type(io.trino.spi.type.Type) MapType(io.trino.spi.type.MapType) TypeSignature.mapType(io.trino.spi.type.TypeSignature.mapType) KeyValuePairStateSerializer(io.trino.operator.aggregation.state.KeyValuePairStateSerializer) AccumulatorStateDescriptor(io.trino.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor) BlockPositionHashCode(io.trino.type.BlockTypeOperators.BlockPositionHashCode) KeyValuePairsStateFactory(io.trino.operator.aggregation.state.KeyValuePairsStateFactory) MapType(io.trino.spi.type.MapType) MethodHandle(java.lang.invoke.MethodHandle)

Example 2 with AccumulatorStateDescriptor

use of io.trino.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor in project trino by trinodb.

the class MergeQuantileDigestFunction method specialize.

@Override
public AggregationMetadata specialize(BoundSignature boundSignature) {
    QuantileDigestType outputType = (QuantileDigestType) boundSignature.getReturnType();
    Type valueType = outputType.getValueType();
    QuantileDigestStateSerializer stateSerializer = new QuantileDigestStateSerializer(valueType);
    return new AggregationMetadata(INPUT_FUNCTION.bindTo(outputType), Optional.empty(), Optional.of(COMBINE_FUNCTION), OUTPUT_FUNCTION.bindTo(stateSerializer), ImmutableList.of(new AccumulatorStateDescriptor<>(QuantileDigestState.class, stateSerializer, new QuantileDigestStateFactory())));
}
Also used : Type(io.trino.spi.type.Type) TypeSignature.parametricType(io.trino.spi.type.TypeSignature.parametricType) QuantileDigestType(io.trino.spi.type.QuantileDigestType) QuantileDigestStateSerializer(io.trino.operator.aggregation.state.QuantileDigestStateSerializer) AccumulatorStateDescriptor(io.trino.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor) QuantileDigestStateFactory(io.trino.operator.aggregation.state.QuantileDigestStateFactory) QuantileDigestType(io.trino.spi.type.QuantileDigestType)

Example 3 with AccumulatorStateDescriptor

use of io.trino.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor in project trino by trinodb.

the class MapAggregationFunction method specialize.

@Override
public AggregationMetadata specialize(BoundSignature boundSignature) {
    MapType outputType = (MapType) boundSignature.getReturnType();
    Type keyType = outputType.getKeyType();
    BlockPositionEqual keyEqual = blockTypeOperators.getEqualOperator(keyType);
    BlockPositionHashCode keyHashCode = blockTypeOperators.getHashCodeOperator(keyType);
    Type valueType = outputType.getValueType();
    KeyValuePairStateSerializer stateSerializer = new KeyValuePairStateSerializer(outputType, keyEqual, keyHashCode);
    return new AggregationMetadata(MethodHandles.insertArguments(INPUT_FUNCTION, 0, keyType, keyEqual, keyHashCode, valueType), Optional.empty(), Optional.of(COMBINE_FUNCTION), OUTPUT_FUNCTION, ImmutableList.of(new AccumulatorStateDescriptor<>(KeyValuePairsState.class, stateSerializer, new KeyValuePairsStateFactory(keyType, valueType))));
}
Also used : BlockPositionEqual(io.trino.type.BlockTypeOperators.BlockPositionEqual) Type(io.trino.spi.type.Type) MapType(io.trino.spi.type.MapType) TypeSignature.mapType(io.trino.spi.type.TypeSignature.mapType) KeyValuePairStateSerializer(io.trino.operator.aggregation.state.KeyValuePairStateSerializer) AccumulatorStateDescriptor(io.trino.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor) BlockPositionHashCode(io.trino.type.BlockTypeOperators.BlockPositionHashCode) KeyValuePairsStateFactory(io.trino.operator.aggregation.state.KeyValuePairsStateFactory) MapType(io.trino.spi.type.MapType)

Example 4 with AccumulatorStateDescriptor

use of io.trino.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor in project trino by trinodb.

the class DecimalAverageAggregation method specialize.

@Override
public AggregationMetadata specialize(BoundSignature boundSignature) {
    Type type = getOnlyElement(boundSignature.getArgumentTypes());
    checkArgument(type instanceof DecimalType, "type must be Decimal");
    MethodHandle inputFunction;
    MethodHandle outputFunction;
    Class<LongDecimalWithOverflowAndLongState> stateInterface = LongDecimalWithOverflowAndLongState.class;
    LongDecimalWithOverflowAndLongStateSerializer 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;
    }
    outputFunction = outputFunction.bindTo(type);
    return new AggregationMetadata(inputFunction, Optional.empty(), Optional.of(COMBINE_FUNCTION), outputFunction, ImmutableList.of(new AccumulatorStateDescriptor<>(stateInterface, stateSerializer, new LongDecimalWithOverflowAndLongStateFactory())));
}
Also used : Type(io.trino.spi.type.Type) DecimalType(io.trino.spi.type.DecimalType) AccumulatorStateDescriptor(io.trino.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor) DecimalType(io.trino.spi.type.DecimalType) LongDecimalWithOverflowAndLongStateSerializer(io.trino.operator.aggregation.state.LongDecimalWithOverflowAndLongStateSerializer) LongDecimalWithOverflowAndLongStateFactory(io.trino.operator.aggregation.state.LongDecimalWithOverflowAndLongStateFactory) LongDecimalWithOverflowAndLongState(io.trino.operator.aggregation.state.LongDecimalWithOverflowAndLongState) MethodHandle(java.lang.invoke.MethodHandle)

Example 5 with AccumulatorStateDescriptor

use of io.trino.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor in project trino by trinodb.

the class ArrayAggregationFunction method specialize.

@Override
public AggregationMetadata specialize(BoundSignature boundSignature) {
    Type type = boundSignature.getArgumentTypes().get(0);
    ArrayAggregationStateSerializer stateSerializer = new ArrayAggregationStateSerializer(type);
    ArrayAggregationStateFactory stateFactory = new ArrayAggregationStateFactory(type);
    MethodHandle inputFunction = INPUT_FUNCTION.bindTo(type);
    MethodHandle combineFunction = COMBINE_FUNCTION.bindTo(type);
    MethodHandle outputFunction = OUTPUT_FUNCTION.bindTo(type);
    return new AggregationMetadata(inputFunction, Optional.empty(), Optional.of(combineFunction), outputFunction, ImmutableList.of(new AccumulatorStateDescriptor<>(ArrayAggregationState.class, stateSerializer, stateFactory)));
}
Also used : TypeSignature.arrayType(io.trino.spi.type.TypeSignature.arrayType) Type(io.trino.spi.type.Type) AccumulatorStateDescriptor(io.trino.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor) AggregationMetadata(io.trino.operator.aggregation.AggregationMetadata) MethodHandle(java.lang.invoke.MethodHandle)

Aggregations

AccumulatorStateDescriptor (io.trino.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor)20 Type (io.trino.spi.type.Type)15 MethodHandle (java.lang.invoke.MethodHandle)14 AggregationMetadata (io.trino.operator.aggregation.AggregationMetadata)5 TypeSignature.arrayType (io.trino.spi.type.TypeSignature.arrayType)4 TypeSignature.mapType (io.trino.spi.type.TypeSignature.mapType)4 BlockPositionEqual (io.trino.type.BlockTypeOperators.BlockPositionEqual)4 BlockPositionHashCode (io.trino.type.BlockTypeOperators.BlockPositionHashCode)4 GenericBooleanState (io.trino.operator.aggregation.state.GenericBooleanState)3 GenericBooleanStateSerializer (io.trino.operator.aggregation.state.GenericBooleanStateSerializer)3 GenericDoubleState (io.trino.operator.aggregation.state.GenericDoubleState)3 GenericDoubleStateSerializer (io.trino.operator.aggregation.state.GenericDoubleStateSerializer)3 GenericLongState (io.trino.operator.aggregation.state.GenericLongState)3 GenericLongStateSerializer (io.trino.operator.aggregation.state.GenericLongStateSerializer)3 ArrayType (io.trino.spi.type.ArrayType)3 ImmutableList (com.google.common.collect.ImmutableList)2 ClassDefinition (io.airlift.bytecode.ClassDefinition)2 FieldDefinition (io.airlift.bytecode.FieldDefinition)2 AggregationFunctionMetadata (io.trino.metadata.AggregationFunctionMetadata)2 BoundSignature (io.trino.metadata.BoundSignature)2