Search in sources :

Example 1 with BlockPositionHashCode

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

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

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

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

the class MapConcatFunction method specialize.

@Override
protected ScalarFunctionImplementation specialize(BoundSignature boundSignature) {
    if (boundSignature.getArity() < 2) {
        throw new TrinoException(INVALID_FUNCTION_ARGUMENT, "There must be two or more concatenation arguments to " + FUNCTION_NAME);
    }
    MapType mapType = (MapType) boundSignature.getReturnType();
    Type keyType = mapType.getKeyType();
    BlockPositionEqual keyEqual = blockTypeOperators.getEqualOperator(keyType);
    BlockPositionHashCode keyHashCode = blockTypeOperators.getHashCodeOperator(keyType);
    MethodHandleAndConstructor methodHandleAndConstructor = generateVarArgsToArrayAdapter(Block.class, Block.class, boundSignature.getArity(), MethodHandles.insertArguments(METHOD_HANDLE, 0, mapType, keyEqual, keyHashCode), USER_STATE_FACTORY.bindTo(mapType));
    return new ChoicesScalarFunctionImplementation(boundSignature, FAIL_ON_NULL, nCopies(boundSignature.getArity(), NEVER_NULL), methodHandleAndConstructor.getMethodHandle(), Optional.of(methodHandleAndConstructor.getConstructor()));
}
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) MethodHandleAndConstructor(io.trino.sql.gen.VarArgsToArrayAdapterGenerator.MethodHandleAndConstructor) TrinoException(io.trino.spi.TrinoException) BlockPositionHashCode(io.trino.type.BlockTypeOperators.BlockPositionHashCode) MapType(io.trino.spi.type.MapType)

Example 5 with BlockPositionHashCode

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

the class TestRealType method testNaNHash.

@Test
public void testNaNHash() {
    BlockBuilder blockBuilder = new IntArrayBlockBuilder(null, 4);
    blockBuilder.writeInt(floatToIntBits(Float.NaN));
    blockBuilder.writeInt(floatToRawIntBits(Float.NaN));
    // the following two are the integer values of a float NaN
    blockBuilder.writeInt(-0x400000);
    blockBuilder.writeInt(0x7fc00000);
    BlockPositionHashCode hashCodeOperator = blockTypeOperators.getHashCodeOperator(REAL);
    assertEquals(hashCodeOperator.hashCode(blockBuilder, 0), hashCodeOperator.hashCode(blockBuilder, 1));
    assertEquals(hashCodeOperator.hashCode(blockBuilder, 0), hashCodeOperator.hashCode(blockBuilder, 2));
    assertEquals(hashCodeOperator.hashCode(blockBuilder, 0), hashCodeOperator.hashCode(blockBuilder, 3));
}
Also used : IntArrayBlockBuilder(io.trino.spi.block.IntArrayBlockBuilder) BlockPositionHashCode(io.trino.type.BlockTypeOperators.BlockPositionHashCode) IntArrayBlockBuilder(io.trino.spi.block.IntArrayBlockBuilder) BlockBuilder(io.trino.spi.block.BlockBuilder) Test(org.testng.annotations.Test)

Aggregations

BlockPositionHashCode (io.trino.type.BlockTypeOperators.BlockPositionHashCode)9 Type (io.trino.spi.type.Type)7 BlockPositionEqual (io.trino.type.BlockTypeOperators.BlockPositionEqual)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 MethodHandle (java.lang.invoke.MethodHandle)3 Test (org.testng.annotations.Test)3 AggregationMetadata (io.trino.operator.aggregation.AggregationMetadata)2 KeyValuePairStateSerializer (io.trino.operator.aggregation.state.KeyValuePairStateSerializer)2 KeyValuePairsStateFactory (io.trino.operator.aggregation.state.KeyValuePairsStateFactory)2 BlockBuilder (io.trino.spi.block.BlockBuilder)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 Block (io.trino.spi.block.Block)1 IntArrayBlockBuilder (io.trino.spi.block.IntArrayBlockBuilder)1