PagesHashStrategy hashStrategy = pagesHashStrategyFactory.createPagesHashStrategy(channels);
// verify channel count
assertEquals(hashStrategy.getChannelCount(), 5);
PagesHashStrategy expectedHashStrategy = new SimplePagesHashStrategy(channels, Ints.asList(1, 2, 3, 4));
// verify hashStrategy is consistent with equals and hash code from block
for (int leftBlockIndex = 0; leftBlockIndex < varcharChannel.size(); leftBlockIndex++) {
PageBuilder pageBuilder = new PageBuilder(ImmutableList.of(VARCHAR, VARCHAR, BIGINT, DOUBLE, BOOLEAN));
int leftPositionCount = varcharChannel.get(leftBlockIndex).getPositionCount();
for (int leftBlockPosition = 0; leftBlockPosition < leftPositionCount; leftBlockPosition++) {
// hash code of position must match block hash
assertEquals(
hashStrategy.hashPosition(leftBlockIndex, leftBlockPosition),
expectedHashStrategy.hashPosition(leftBlockIndex, leftBlockPosition));
// position must be equal to itself
assertTrue(hashStrategy.positionEqualsPosition(leftBlockIndex, leftBlockPosition, leftBlockIndex, leftBlockPosition));
// check equality of every position against every other position in the block
for (int rightBlockIndex = 0; rightBlockIndex < varcharChannel.size(); rightBlockIndex++) {
RandomAccessBlock rightBlock = varcharChannel.get(rightBlockIndex);
for (int rightBlockPosition = 0; rightBlockPosition < rightBlock.getPositionCount(); rightBlockPosition++) {
assertEquals(
hashStrategy.positionEqualsPosition(leftBlockIndex, leftBlockPosition, rightBlockIndex, rightBlockPosition),
expectedHashStrategy.positionEqualsPosition(leftBlockIndex, leftBlockPosition, rightBlockIndex, rightBlockPosition));
}
}
// check equality of every position against every other position in the block cursor
for (int rightBlockIndex = 0; rightBlockIndex < varcharChannel.size(); rightBlockIndex++) {
BlockCursor[] rightCursors = new BlockCursor[4];
rightCursors[0] = varcharChannel.get(rightBlockIndex).cursor();
rightCursors[1] = longChannel.get(rightBlockIndex).cursor();
rightCursors[2] = doubleChannel.get(rightBlockIndex).cursor();
rightCursors[3] = booleanChannel.get(rightBlockIndex).cursor();
int rightPositionCount = varcharChannel.get(rightBlockIndex).getPositionCount();
for (int rightPosition = 0; rightPosition < rightPositionCount; rightPosition++) {
for (BlockCursor rightCursor : rightCursors) {
assertTrue(rightCursor.advanceNextPosition());
}
assertEquals(
hashStrategy.positionEqualsCursors(leftBlockIndex, leftBlockPosition, rightCursors),
expectedHashStrategy.positionEqualsCursors(leftBlockIndex, leftBlockPosition, rightCursors));
}
}
// write position to output block
hashStrategy.appendTo(leftBlockIndex, leftBlockPosition, pageBuilder, 0);