Search in sources :

Example 1 with BlockPositionEqual

use of io.trino.type.BlockTypeOperators.BlockPositionEqual 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 BlockPositionEqual

use of io.trino.type.BlockTypeOperators.BlockPositionEqual 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 3 with BlockPositionEqual

use of io.trino.type.BlockTypeOperators.BlockPositionEqual in project trino by trinodb.

the class TuplePageFilter method matches.

private boolean matches(Page page, int position) {
    for (int channel = 0; channel < inputChannels.size(); channel++) {
        BlockPositionEqual equalOperator = equalOperators.get(channel);
        Block outputBlock = page.getBlock(channel);
        Block singleTupleBlock = tuplePage.getBlock(channel);
        if (!equalOperator.equal(singleTupleBlock, 0, outputBlock, position)) {
            return false;
        }
    }
    return true;
}
Also used : BlockPositionEqual(io.trino.type.BlockTypeOperators.BlockPositionEqual) Block(io.trino.spi.block.Block)

Example 4 with BlockPositionEqual

use of io.trino.type.BlockTypeOperators.BlockPositionEqual in project trino by trinodb.

the class MapToMapCast method specialize.

@Override
public ScalarFunctionImplementation specialize(BoundSignature boundSignature, FunctionDependencies functionDependencies) {
    checkArgument(boundSignature.getArity() == 1, "Expected arity to be 1");
    MapType fromMapType = (MapType) boundSignature.getArgumentType(0);
    Type fromKeyType = fromMapType.getKeyType();
    Type fromValueType = fromMapType.getValueType();
    MapType toMapType = (MapType) boundSignature.getReturnType();
    Type toKeyType = toMapType.getKeyType();
    Type toValueType = toMapType.getValueType();
    MethodHandle keyProcessor = buildProcessor(functionDependencies, fromKeyType, toKeyType, true);
    MethodHandle valueProcessor = buildProcessor(functionDependencies, fromValueType, toValueType, false);
    BlockPositionEqual keyEqual = blockTypeOperators.getEqualOperator(toKeyType);
    BlockPositionHashCode keyHashCode = blockTypeOperators.getHashCodeOperator(toKeyType);
    MethodHandle target = MethodHandles.insertArguments(METHOD_HANDLE, 0, keyProcessor, valueProcessor, toMapType, keyEqual, keyHashCode);
    return new ChoicesScalarFunctionImplementation(boundSignature, NULLABLE_RETURN, ImmutableList.of(NEVER_NULL), target);
}
Also used : BlockPositionEqual(io.trino.type.BlockTypeOperators.BlockPositionEqual) Type(io.trino.spi.type.Type) MethodType.methodType(java.lang.invoke.MethodType.methodType) MapType(io.trino.spi.type.MapType) TypeSignature.mapType(io.trino.spi.type.TypeSignature.mapType) BlockPositionHashCode(io.trino.type.BlockTypeOperators.BlockPositionHashCode) MapType(io.trino.spi.type.MapType) MethodHandle(java.lang.invoke.MethodHandle)

Example 5 with BlockPositionEqual

use of io.trino.type.BlockTypeOperators.BlockPositionEqual in project trino by trinodb.

the class StructuralTestUtil method mapBlocksEqual.

public static boolean mapBlocksEqual(Type keyType, Type valueType, Block block1, Block block2) {
    if (block1.getPositionCount() != block2.getPositionCount()) {
        return false;
    }
    BlockPositionEqual keyEqualOperator = TYPE_OPERATORS_CACHE.getEqualOperator(keyType);
    BlockPositionEqual valueEqualOperator = TYPE_OPERATORS_CACHE.getEqualOperator(valueType);
    for (int i = 0; i < block1.getPositionCount(); i += 2) {
        if (block1.isNull(i) != block2.isNull(i) || block1.isNull(i + 1) != block2.isNull(i + 1)) {
            return false;
        }
        if (!block1.isNull(i) && !keyEqualOperator.equal(block1, i, block2, i)) {
            return false;
        }
        if (!block1.isNull(i + 1) && !valueEqualOperator.equal(block1, i + 1, block2, i + 1)) {
            return false;
        }
    }
    return true;
}
Also used : BlockPositionEqual(io.trino.type.BlockTypeOperators.BlockPositionEqual)

Aggregations

BlockPositionEqual (io.trino.type.BlockTypeOperators.BlockPositionEqual)11 Type (io.trino.spi.type.Type)7 BlockPositionHashCode (io.trino.type.BlockTypeOperators.BlockPositionHashCode)7 TypeSignature.mapType (io.trino.spi.type.TypeSignature.mapType)6 AccumulatorStateDescriptor (io.trino.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor)4 MapType (io.trino.spi.type.MapType)4 Block (io.trino.spi.block.Block)3 MethodHandle (java.lang.invoke.MethodHandle)3 AggregationMetadata (io.trino.operator.aggregation.AggregationMetadata)2 KeyValuePairStateSerializer (io.trino.operator.aggregation.state.KeyValuePairStateSerializer)2 KeyValuePairsStateFactory (io.trino.operator.aggregation.state.KeyValuePairsStateFactory)2 BlockTypeOperators (io.trino.type.BlockTypeOperators)2 ImmutableList (com.google.common.collect.ImmutableList)1 PagesHashStrategy (io.trino.operator.PagesHashStrategy)1 SimplePagesHashStrategy (io.trino.operator.SimplePagesHashStrategy)1 Page (io.trino.spi.Page)1 PageBuilder (io.trino.spi.PageBuilder)1 TrinoException (io.trino.spi.TrinoException)1 BlockBuilder (io.trino.spi.block.BlockBuilder)1 ArrayType (io.trino.spi.type.ArrayType)1