Search in sources :

Example 1 with BlockPositionXxHash64

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

the class ChecksumAggregationFunction method specialize.

@Override
public AggregationMetadata specialize(BoundSignature boundSignature) {
    BlockPositionXxHash64 xxHash64Operator = blockTypeOperators.getXxHash64Operator(boundSignature.getArgumentTypes().get(0));
    AccumulatorStateSerializer<NullableLongState> stateSerializer = StateCompiler.generateStateSerializer(NullableLongState.class);
    return new AggregationMetadata(INPUT_FUNCTION.bindTo(xxHash64Operator), Optional.empty(), Optional.of(COMBINE_FUNCTION), OUTPUT_FUNCTION, ImmutableList.of(new AccumulatorStateDescriptor<>(NullableLongState.class, stateSerializer, StateCompiler.generateStateFactory(NullableLongState.class))));
}
Also used : NullableLongState(io.trino.operator.aggregation.state.NullableLongState) BlockPositionXxHash64(io.trino.type.BlockTypeOperators.BlockPositionXxHash64) AccumulatorStateDescriptor(io.trino.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor)

Example 2 with BlockPositionXxHash64

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

the class TestChecksumAggregation method expectedChecksum.

private static SqlVarbinary expectedChecksum(Type type, Block block) {
    BlockPositionXxHash64 xxHash64Operator = blockTypeOperators.getXxHash64Operator(type);
    long result = 0;
    for (int i = 0; i < block.getPositionCount(); i++) {
        if (block.isNull(i)) {
            result += PRIME64;
        } else {
            result += xxHash64Operator.xxHash64(block, i) * PRIME64;
        }
    }
    return new SqlVarbinary(wrappedLongArray(result).getBytes());
}
Also used : BlockPositionXxHash64(io.trino.type.BlockTypeOperators.BlockPositionXxHash64) SqlVarbinary(io.trino.spi.type.SqlVarbinary)

Example 3 with BlockPositionXxHash64

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

the class TestDoubleType method testNaNHash.

@Test
public void testNaNHash() {
    BlockBuilder blockBuilder = new LongArrayBlockBuilder(null, 4);
    blockBuilder.writeLong(doubleToLongBits(Double.NaN));
    blockBuilder.writeLong(doubleToRawLongBits(Double.NaN));
    // the following two are the long values of a double NaN
    blockBuilder.writeLong(-0x000fffffffffffffL);
    blockBuilder.writeLong(0x7ff8000000000000L);
    BlockPositionHashCode hashCodeOperator = blockTypeOperators.getHashCodeOperator(DOUBLE);
    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));
    BlockPositionXxHash64 xxHash64Operator = blockTypeOperators.getXxHash64Operator(DOUBLE);
    assertEquals(xxHash64Operator.xxHash64(blockBuilder, 0), xxHash64Operator.xxHash64(blockBuilder, 1));
    assertEquals(xxHash64Operator.xxHash64(blockBuilder, 0), xxHash64Operator.xxHash64(blockBuilder, 2));
    assertEquals(xxHash64Operator.xxHash64(blockBuilder, 0), xxHash64Operator.xxHash64(blockBuilder, 3));
}
Also used : BlockPositionXxHash64(io.trino.type.BlockTypeOperators.BlockPositionXxHash64) LongArrayBlockBuilder(io.trino.spi.block.LongArrayBlockBuilder) BlockPositionHashCode(io.trino.type.BlockTypeOperators.BlockPositionHashCode) LongArrayBlockBuilder(io.trino.spi.block.LongArrayBlockBuilder) BlockBuilder(io.trino.spi.block.BlockBuilder) Test(org.testng.annotations.Test)

Aggregations

BlockPositionXxHash64 (io.trino.type.BlockTypeOperators.BlockPositionXxHash64)3 AccumulatorStateDescriptor (io.trino.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor)1 NullableLongState (io.trino.operator.aggregation.state.NullableLongState)1 BlockBuilder (io.trino.spi.block.BlockBuilder)1 LongArrayBlockBuilder (io.trino.spi.block.LongArrayBlockBuilder)1 SqlVarbinary (io.trino.spi.type.SqlVarbinary)1 BlockPositionHashCode (io.trino.type.BlockTypeOperators.BlockPositionHashCode)1 Test (org.testng.annotations.Test)1