Search in sources :

Example 16 with Type

use of io.trino.spi.type.Type 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 17 with Type

use of io.trino.spi.type.Type 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 18 with Type

use of io.trino.spi.type.Type 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 19 with Type

use of io.trino.spi.type.Type in project trino by trinodb.

the class InMemoryHashAggregationBuilder method toTypes.

public static List<Type> toTypes(List<? extends Type> groupByType, List<AggregatorFactory> factories, Optional<Integer> hashChannel) {
    ImmutableList.Builder<Type> types = ImmutableList.builder();
    types.addAll(groupByType);
    if (hashChannel.isPresent()) {
        types.add(BIGINT);
    }
    for (AggregatorFactory factory : factories) {
        types.add(factory.createAggregator().getType());
    }
    return types.build();
}
Also used : Type(io.trino.spi.type.Type) ImmutableList(com.google.common.collect.ImmutableList) AggregatorFactory(io.trino.operator.aggregation.AggregatorFactory)

Example 20 with Type

use of io.trino.spi.type.Type 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)

Aggregations

Type (io.trino.spi.type.Type)688 Test (org.testng.annotations.Test)266 ArrayType (io.trino.spi.type.ArrayType)218 ImmutableList (com.google.common.collect.ImmutableList)191 RowType (io.trino.spi.type.RowType)177 List (java.util.List)155 VarcharType (io.trino.spi.type.VarcharType)134 Page (io.trino.spi.Page)126 ArrayList (java.util.ArrayList)126 VarcharType.createUnboundedVarcharType (io.trino.spi.type.VarcharType.createUnboundedVarcharType)114 Block (io.trino.spi.block.Block)110 MapType (io.trino.spi.type.MapType)107 DecimalType (io.trino.spi.type.DecimalType)102 TrinoException (io.trino.spi.TrinoException)98 Optional (java.util.Optional)98 Map (java.util.Map)97 ImmutableMap (com.google.common.collect.ImmutableMap)93 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)92 DecimalType.createDecimalType (io.trino.spi.type.DecimalType.createDecimalType)86 BlockBuilder (io.trino.spi.block.BlockBuilder)72