use of com.facebook.presto.spi.block.InterleavedBlock in project presto by prestodb.
the class TestInterleavedBlock method testGetSizeInBytes.
@Test
private void testGetSizeInBytes() {
int numEntries = 2000;
VarcharType unboundedVarcharType = createUnboundedVarcharType();
InterleavedBlockBuilder blockBuilder = new InterleavedBlockBuilder(ImmutableList.of(unboundedVarcharType, BIGINT), new BlockBuilderStatus(), numEntries);
for (int i = 0; i < numEntries; i += 2) {
unboundedVarcharType.writeString(blockBuilder, String.valueOf(ThreadLocalRandom.current().nextLong()));
BIGINT.writeLong(blockBuilder, ThreadLocalRandom.current().nextLong());
}
InterleavedBlock block = blockBuilder.build();
List<Block> splitQuarter = splitBlock(block, 4);
int sizeInBytes = block.getSizeInBytes();
int quarter1size = splitQuarter.get(0).getSizeInBytes();
int quarter2size = splitQuarter.get(1).getSizeInBytes();
int quarter3size = splitQuarter.get(2).getSizeInBytes();
int quarter4size = splitQuarter.get(3).getSizeInBytes();
double expectedQuarterSizeMin = sizeInBytes * 0.2;
double expectedQuarterSizeMax = sizeInBytes * 0.3;
assertTrue(quarter1size > expectedQuarterSizeMin && quarter1size < expectedQuarterSizeMax, format("quarter1size is %s, should be between %s and %s", quarter1size, expectedQuarterSizeMin, expectedQuarterSizeMax));
assertTrue(quarter2size > expectedQuarterSizeMin && quarter2size < expectedQuarterSizeMax, format("quarter2size is %s, should be between %s and %s", quarter2size, expectedQuarterSizeMin, expectedQuarterSizeMax));
assertTrue(quarter3size > expectedQuarterSizeMin && quarter3size < expectedQuarterSizeMax, format("quarter3size is %s, should be between %s and %s", quarter3size, expectedQuarterSizeMin, expectedQuarterSizeMax));
assertTrue(quarter4size > expectedQuarterSizeMin && quarter4size < expectedQuarterSizeMax, format("quarter4size is %s, should be between %s and %s", quarter4size, expectedQuarterSizeMin, expectedQuarterSizeMax));
assertEquals(quarter1size + quarter2size + quarter3size + quarter4size, sizeInBytes);
}
use of com.facebook.presto.spi.block.InterleavedBlock in project presto by prestodb.
the class ParquetReader method readStruct.
private Block readStruct(Type type, List<String> path, IntList elementOffsets) throws IOException {
List<TypeSignatureParameter> parameters = type.getTypeSignature().getParameters();
Block[] blocks = new Block[parameters.size()];
for (int i = 0; i < parameters.size(); i++) {
NamedTypeSignature namedTypeSignature = parameters.get(i).getNamedTypeSignature();
Type fieldType = typeManager.getType(namedTypeSignature.getTypeSignature());
String name = namedTypeSignature.getName();
blocks[i] = readBlock(name, fieldType, path, new IntArrayList());
}
InterleavedBlock interleavedBlock = new InterleavedBlock(blocks);
int blockSize = blocks[0].getPositionCount();
int[] offsets = new int[blockSize + 1];
for (int i = 1; i < offsets.length; i++) {
elementOffsets.add(parameters.size());
offsets[i] = i * parameters.size();
}
return new ArrayBlock(blockSize, new boolean[blockSize], offsets, interleavedBlock);
}
Aggregations