use of com.facebook.presto.common.block.ColumnarRow in project presto by prestodb.
the class StructColumnWriter method writeBlock.
@Override
public long writeBlock(Block block) {
checkState(!closed);
checkArgument(block.getPositionCount() > 0, "Block is empty");
ColumnarRow columnarRow = toColumnarRow(block);
return writeColumnarRow(columnarRow);
}
use of com.facebook.presto.common.block.ColumnarRow in project presto by prestodb.
the class MultimapAggregationStateSerializer method deserialize.
@Override
public void deserialize(Block block, int index, MultimapAggregationState state) {
state.reset();
ColumnarRow columnarRow = toColumnarRow(arrayType.getObject(block, index));
Block keys = columnarRow.getField(KEY_CHANNEL);
Block values = columnarRow.getField(VALUE_CHANNEL);
for (int i = 0; i < columnarRow.getPositionCount(); i++) {
state.add(keys, values, i);
}
}
use of com.facebook.presto.common.block.ColumnarRow 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);
}
use of com.facebook.presto.common.block.ColumnarRow in project presto by prestodb.
the class TestColumnarRow method assertColumnarRow.
private static <T> void assertColumnarRow(Block block, T[] expectedValues) {
ColumnarRow columnarRow = toColumnarRow(block);
assertEquals(columnarRow.getPositionCount(), expectedValues.length);
for (int fieldId = 0; fieldId < FIELD_COUNT; fieldId++) {
Block fieldBlock = columnarRow.getField(fieldId);
int elementsPosition = 0;
for (int position = 0; position < expectedValues.length; position++) {
T expectedRow = expectedValues[position];
assertEquals(columnarRow.isNull(position), expectedRow == null);
if (expectedRow == null) {
continue;
}
Object expectedElement = Array.get(expectedRow, fieldId);
assertBlockPosition(fieldBlock, elementsPosition, expectedElement);
elementsPosition++;
}
}
}
use of com.facebook.presto.common.block.ColumnarRow in project presto by prestodb.
the class KeyAndBlockPositionValueStateSerializer method deserialize.
@Override
public void deserialize(Block block, int index, T state) {
ColumnarRow columnarRow = toColumnarRow(block);
state.setFirstNull(BOOLEAN.getBoolean(columnarRow.getField(0), index));
state.setSecondNull(BOOLEAN.getBoolean(columnarRow.getField(1), index));
if (!state.isFirstNull()) {
readFirstField(columnarRow.getField(2), index, state);
}
if (!state.isSecondNull()) {
state.setSecondPosition(index);
state.setSecondBlock(columnarRow.getField(3));
}
}
Aggregations