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))));
}
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());
}
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));
}
Aggregations