use of com.facebook.presto.common.block.RunLengthEncodedBlock in project presto by prestodb.
the class TestRunLengthEncodedBlock method assertRleBlock.
private void assertRleBlock(int positionCount) {
Slice expectedValue = createExpectedValue(0);
Block block = new RunLengthEncodedBlock(createSingleValueBlock(expectedValue), positionCount);
Slice[] expectedValues = new Slice[positionCount];
for (int position = 0; position < positionCount; position++) {
expectedValues[position] = expectedValue;
}
assertBlock(block, TestRunLengthEncodedBlock::createBlockBuilder, expectedValues);
}
use of com.facebook.presto.common.block.RunLengthEncodedBlock in project presto by prestodb.
the class TestRunLengthEncodedBlock method testEstimatedDataSizeForStats.
@Test
public void testEstimatedDataSizeForStats() {
int positionCount = 10;
Slice expectedValue = createExpectedValue(5);
Block block = new RunLengthEncodedBlock(createSingleValueBlock(expectedValue), positionCount);
for (int postition = 0; postition < positionCount; postition++) {
assertEquals(block.getEstimatedDataSizeForStats(postition), expectedValue.length());
}
}
use of com.facebook.presto.common.block.RunLengthEncodedBlock in project presto by prestodb.
the class ParquetFileWriter method appendRows.
@Override
public void appendRows(Page dataPage) {
Block[] blocks = new Block[fileInputColumnIndexes.length];
for (int i = 0; i < fileInputColumnIndexes.length; i++) {
int inputColumnIndex = fileInputColumnIndexes[i];
if (inputColumnIndex < 0) {
blocks[i] = new RunLengthEncodedBlock(nullBlocks.get(i), dataPage.getPositionCount());
} else {
blocks[i] = dataPage.getBlock(inputColumnIndex);
}
}
Page page = new Page(dataPage.getPositionCount(), blocks);
try {
parquetWriter.write(page);
} catch (IOException | UncheckedIOException e) {
throw new PrestoException(HIVE_WRITER_DATA_ERROR, e);
}
}
use of com.facebook.presto.common.block.RunLengthEncodedBlock in project presto by prestodb.
the class GroupIdOperator method generateNextPage.
private Page generateNextPage() {
// generate 'n' pages for every input page, where n is the number of grouping sets
Block[] outputBlocks = new Block[types.size()];
for (int i = 0; i < groupingSetInputs[currentGroupingSet].length; i++) {
if (groupingSetInputs[currentGroupingSet][i] == -1) {
outputBlocks[i] = new RunLengthEncodedBlock(nullBlocks[i], currentPage.getPositionCount());
} else {
outputBlocks[i] = currentPage.getBlock(groupingSetInputs[currentGroupingSet][i]);
}
}
outputBlocks[outputBlocks.length - 1] = new RunLengthEncodedBlock(groupIdBlocks[currentGroupingSet], currentPage.getPositionCount());
currentGroupingSet = (currentGroupingSet + 1) % groupingSetInputs.length;
Page outputPage = new Page(currentPage.getPositionCount(), outputBlocks);
if (currentGroupingSet == 0) {
currentPage = null;
}
return outputPage;
}
use of com.facebook.presto.common.block.RunLengthEncodedBlock in project presto by prestodb.
the class OptimizedPartitionedOutputOperator method decodeBlock.
/**
* Flatten the block and convert the nested-typed block into ColumnarArray/Map/Row.
* For performance considerations we decode the block only once for each block instead of for each batch.
*
* @return A tree structure that contains the decoded block
*/
@VisibleForTesting
static DecodedBlockNode decodeBlock(BlockFlattener flattener, Closer blockLeaseCloser, Block block) {
BlockLease lease = flattener.flatten(block);
blockLeaseCloser.register(lease::close);
Block decodedBlock = lease.get();
long estimatedSizeInBytes = decodedBlock.getLogicalSizeInBytes();
if (decodedBlock instanceof ArrayBlock) {
ColumnarArray columnarArray = ColumnarArray.toColumnarArray(decodedBlock);
Block childBlock = columnarArray.getElementsBlock();
return new DecodedBlockNode(columnarArray, ImmutableList.of(decodeBlock(flattener, blockLeaseCloser, childBlock)), columnarArray.getRetainedSizeInBytes(), estimatedSizeInBytes);
}
if (decodedBlock instanceof MapBlock) {
ColumnarMap columnarMap = ColumnarMap.toColumnarMap(decodedBlock);
Block keyBlock = columnarMap.getKeysBlock();
Block valueBlock = columnarMap.getValuesBlock();
return new DecodedBlockNode(columnarMap, ImmutableList.of(decodeBlock(flattener, blockLeaseCloser, keyBlock), decodeBlock(flattener, blockLeaseCloser, valueBlock)), columnarMap.getRetainedSizeInBytes(), estimatedSizeInBytes);
}
if (decodedBlock instanceof RowBlock) {
ColumnarRow columnarRow = ColumnarRow.toColumnarRow(decodedBlock);
ImmutableList.Builder<DecodedBlockNode> children = ImmutableList.builder();
for (int i = 0; i < columnarRow.getFieldCount(); i++) {
Block childBlock = columnarRow.getField(i);
children.add(decodeBlock(flattener, blockLeaseCloser, childBlock));
}
return new DecodedBlockNode(columnarRow, children.build(), columnarRow.getRetainedSizeInBytes(), estimatedSizeInBytes);
}
if (decodedBlock instanceof DictionaryBlock) {
Block dictionary = ((DictionaryBlock) decodedBlock).getDictionary();
return new DecodedBlockNode(decodedBlock, ImmutableList.of(decodeBlock(flattener, blockLeaseCloser, dictionary)), decodedBlock.getRetainedSizeInBytes(), estimatedSizeInBytes);
}
if (decodedBlock instanceof RunLengthEncodedBlock) {
Block childBlock = ((RunLengthEncodedBlock) decodedBlock).getValue();
return new DecodedBlockNode(decodedBlock, ImmutableList.of(decodeBlock(flattener, blockLeaseCloser, childBlock)), decodedBlock.getRetainedSizeInBytes(), estimatedSizeInBytes);
}
return new DecodedBlockNode(decodedBlock, ImmutableList.of(), block.getRetainedSizeInBytes(), estimatedSizeInBytes);
}
Aggregations