### Question:
RaptorBucketFunction implements BucketFunction { @SuppressWarnings("NumericCastThatLosesPrecision") @Override public int getBucket(Page page, int position) { long hash = 0; for (int i = 0; i < page.getChannelCount(); i++) { Block block = page.getBlock(i); long value = functions[i].hash(block, position); hash = (hash * 31) + value; } int value = (int) (hash & Integer.MAX_VALUE); return value % bucketCount; } RaptorBucketFunction(int bucketCount, List<Type> types); @SuppressWarnings("NumericCastThatLosesPrecision") @Override int getBucket(Page page, int position); static void validateBucketType(Type type);  }### Answer:
@Test public void testBigint() { BucketFunction function = bucketFunction(50, BIGINT); assertEquals(getBucket(function, createLongsBlock(123456789012L)), 12); assertEquals(getBucket(function, createLongsBlock(454345325)), 16); assertEquals(getBucket(function, createLongsBlock(365363)), 42); assertEquals(getBucket(function, createLongsBlock(45645747)), 41); assertEquals(getBucket(function, createLongsBlock(3244)), 29); function = bucketFunction(2, BIGINT); assertEquals(getBucket(function, createLongsBlock(123456789012L)), 0); assertEquals(getBucket(function, createLongsBlock(454345325)), 0); assertEquals(getBucket(function, createLongsBlock(365363)), 0); assertEquals(getBucket(function, createLongsBlock(45645747)), 1); assertEquals(getBucket(function, createLongsBlock(3244)), 1); }
@Test public void testInteger() { BucketFunction function = bucketFunction(50, INTEGER); assertEquals(getBucket(function, createIntsBlock(454345325)), 16); assertEquals(getBucket(function, createIntsBlock(365363)), 42); assertEquals(getBucket(function, createIntsBlock(45645747)), 41); assertEquals(getBucket(function, createIntsBlock(3244)), 29); }
@Test public void testVarchar() { BucketFunction function = bucketFunction(50, createUnboundedVarcharType()); assertEquals(getBucket(function, createStringsBlock("lorem ipsum")), 2); assertEquals(getBucket(function, createStringsBlock("lorem")), 26); assertEquals(getBucket(function, createStringsBlock("ipsum")), 3); assertEquals(getBucket(function, createStringsBlock("hello")), 19); }
@Test public void testVarcharBigint() { BucketFunction function = bucketFunction(50, createUnboundedVarcharType(), BIGINT); assertEquals(getBucket(function, createStringsBlock("lorem ipsum"), createLongsBlock(123456789012L)), 24); assertEquals(getBucket(function, createStringsBlock("lorem"), createLongsBlock(454345325)), 32); assertEquals(getBucket(function, createStringsBlock("ipsum"), createLongsBlock(365363)), 21); assertEquals(getBucket(function, createStringsBlock("hello"), createLongsBlock(45645747)), 34); assertEquals(getBucket(function, createStringsBlock("world"), createLongsBlock(3244)), 4); }