use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class TestUuidType method createTestBlock.
public static Block createTestBlock() {
BlockBuilder blockBuilder = UUID.createBlockBuilder(null, 1);
for (int i = 0; i < 10; i++) {
String uuid = "6b5f5b65-67e4-43b0-8ee3-586cd49f58a" + i;
UUID.writeSlice(blockBuilder, castFromVarcharToUuid(utf8Slice(uuid)));
}
return blockBuilder.build();
}
use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class TestWriterBlockRawSize method testIntegerWriter.
@Test(dataProvider = "IntegerTypes")
public void testIntegerWriter(Type type) {
BlockBuilder blockBuilder = type.createBlockBuilder(null, NUM_ELEMENTS * 2);
for (int i = 0; i < NUM_ELEMENTS; i++) {
blockBuilder.appendNull();
type.writeLong(blockBuilder, i);
}
Block block = blockBuilder.build();
ColumnWriter columnWriter = createColumnWriter(type);
long rawSize = columnWriter.writeBlock(block);
long expectedSize = NUM_ELEMENTS * (1 + ((FixedWidthType) type).getFixedSize());
assertEquals(rawSize, expectedSize);
verifyDictionaryColumnWriter(expectedSize, block, columnWriter);
}
use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class TestWriterBlockRawSize method testFractionalTypes.
@Test(dataProvider = "FractionalTypes")
public void testFractionalTypes(Type type) {
ColumnWriter columnWriter = createColumnWriter(type);
BlockBuilder blockBuilder = type.createBlockBuilder(null, NUM_ELEMENTS * 2);
for (int i = 0; i < NUM_ELEMENTS; i++) {
blockBuilder.appendNull();
if (type == REAL) {
type.writeLong(blockBuilder, Float.floatToIntBits(i));
} else {
type.writeDouble(blockBuilder, (float) i);
}
}
long rawSize = columnWriter.writeBlock(blockBuilder.build());
long expectedSize = NUM_ELEMENTS * (1 + ((FixedWidthType) type).getFixedSize());
assertEquals(rawSize, expectedSize);
}
use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class TestWriterBlockRawSize method testFileMetadataRawSize.
@Test
public void testFileMetadataRawSize() throws IOException {
Type type = INTEGER;
List<Type> types = ImmutableList.of(type);
int numBlocksPerRowGroup = 3;
int numBlocksPerStripe = numBlocksPerRowGroup * 5;
int numStripes = 4;
int numBlocksPerFile = numBlocksPerStripe * numStripes + 1;
BlockBuilder blockBuilder = type.createBlockBuilder(null, NUM_ELEMENTS * 2);
for (int i = 0; i < NUM_ELEMENTS; i++) {
blockBuilder.appendNull();
type.writeLong(blockBuilder, i);
}
long blockRawSize = ((FixedWidthType) type).getFixedSize() * NUM_ELEMENTS + NUM_ELEMENTS;
Block block = blockBuilder.build();
Block[] blocks = new Block[] { block };
OrcWriterOptions writerOptions = OrcWriterOptions.builder().withRowGroupMaxRowCount(block.getPositionCount() * numBlocksPerRowGroup).withFlushPolicy(DefaultOrcWriterFlushPolicy.builder().withStripeMaxRowCount(block.getPositionCount() * numBlocksPerStripe).build()).build();
for (OrcEncoding encoding : OrcEncoding.values()) {
try (TempFile tempFile = new TempFile()) {
OrcWriter writer = createOrcWriter(tempFile.getFile(), encoding, ZSTD, Optional.empty(), types, writerOptions, new OrcWriterStats());
for (int i = 0; i < numBlocksPerFile; i++) {
writer.write(new Page(blocks));
}
writer.close();
writer.validate(new FileOrcDataSource(tempFile.getFile(), new DataSize(1, MEGABYTE), new DataSize(1, MEGABYTE), new DataSize(1, MEGABYTE), true));
Footer footer = OrcTester.getFileMetadata(tempFile.getFile(), encoding).getFooter();
verifyValue(encoding, footer.getRawSize(), blockRawSize * numBlocksPerFile);
assertEquals(footer.getStripes().size(), numStripes + 1);
int numBlocksRemaining = numBlocksPerFile;
for (StripeInformation stripeInfo : footer.getStripes()) {
int numBlocksInStripe = Math.min(numBlocksRemaining, numBlocksPerStripe);
verifyValue(encoding, stripeInfo.getRawDataSize(), blockRawSize * numBlocksInStripe);
numBlocksRemaining -= numBlocksInStripe;
}
}
}
}
use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class TestWriterBlockRawSize method testArrayType.
@Test
public void testArrayType() {
Type elementType = INTEGER;
Type arrayType = new ArrayType(elementType);
ColumnWriter columnWriter = createColumnWriter(arrayType);
BlockBuilder blockBuilder = arrayType.createBlockBuilder(null, NUM_ELEMENTS * 2);
int totalChildElements = 0;
for (int i = 0; i < NUM_ELEMENTS; i++) {
blockBuilder.appendNull();
BlockBuilder elementBlockBuilder = blockBuilder.beginBlockEntry();
for (int j = 0; j < i; j++) {
elementType.writeLong(elementBlockBuilder, j);
}
blockBuilder.closeEntry();
totalChildElements += i;
}
long rawSize = columnWriter.writeBlock(blockBuilder.build());
long expectedSize = NUM_ELEMENTS + (totalChildElements * ((FixedWidthType) elementType).getFixedSize());
assertEquals(rawSize, expectedSize);
}
Aggregations