VARCHAR.writeString(blockBuilder, "bob");
VARCHAR.writeString(blockBuilder, "charlie");
VARCHAR.writeString(blockBuilder, "dave");
Block block = blockBuilder.build();
DynamicSliceOutput encoderOutput = new DynamicSliceOutput(1024);
Encoder encoder = BlocksFileEncoding.SNAPPY.createBlocksWriter(VARCHAR, encoderOutput);
BlockBuilder expectedBlockBuilder = VARCHAR.createBlockBuilder(new BlockBuilderStatus());
int count = 1000;
for (int i = 0; i < count; i++) {
// select a random position
int position = ThreadLocalRandom.current().nextInt(block.getPositionCount());
// add to expected block
VARCHAR.appendTo(block, position, expectedBlockBuilder);
// create block with single value and add to encoder
encoder.append(block.getSingleValueBlock(position));
}
Block expectedBlock = expectedBlockBuilder.build();
BlockEncoding snappyEncoding = encoder.finish();
assertTrue(encoderOutput.size() < expectedBlock.getSizeInBytes());
Block actualBlock = snappyEncoding.readBlock(encoderOutput.slice().getInput());
BlockAssertions.assertBlockEquals(VARCHAR, actualBlock, expectedBlock);
}