use of com.facebook.presto.common.block.ColumnarArray in project presto by prestodb.
the class ListColumnWriter method writeBlock.
@Override
public long writeBlock(Block block) {
checkState(!closed);
checkArgument(block.getPositionCount() > 0, "Block is empty");
ColumnarArray columnarArray = toColumnarArray(block);
return writeColumnarArray(columnarArray);
}
use of com.facebook.presto.common.block.ColumnarArray in project presto by prestodb.
the class ArrayColumnWriter method writeBlock.
@Override
public void writeBlock(ColumnChunk columnChunk) throws IOException {
ColumnarArray columnarArray = ColumnarArray.toColumnarArray(columnChunk.getBlock());
elementWriter.writeBlock(new ColumnChunk(columnarArray.getElementsBlock(), ImmutableList.<DefinitionLevelIterable>builder().addAll(columnChunk.getDefinitionLevelIterables()).add(DefinitionLevelIterables.of(columnarArray, maxDefinitionLevel)).build(), ImmutableList.<RepetitionLevelIterable>builder().addAll(columnChunk.getRepetitionLevelIterables()).add(RepetitionLevelIterables.of(columnarArray, maxRepetitionLevel)).build()));
}
use of com.facebook.presto.common.block.ColumnarArray in project presto by prestodb.
the class TestUnnesterUtil method calculateMaxCardinalities.
static int[] calculateMaxCardinalities(Page page, List<Type> replicatedTypes, List<Type> unnestTypes) {
int positionCount = page.getPositionCount();
int[] maxCardinalities = new int[positionCount];
int replicatedChannelCount = replicatedTypes.size();
int unnestChannelCount = unnestTypes.size();
for (int i = 0; i < unnestChannelCount; i++) {
Type type = unnestTypes.get(i);
Block block = page.getBlock(replicatedChannelCount + i);
assertTrue(type instanceof ArrayType || type instanceof MapType);
if (type instanceof ArrayType) {
ColumnarArray columnarArray = ColumnarArray.toColumnarArray(block);
for (int j = 0; j < positionCount; j++) {
maxCardinalities[j] = max(maxCardinalities[j], columnarArray.getLength(j));
}
} else if (type instanceof MapType) {
ColumnarMap columnarMap = ColumnarMap.toColumnarMap(block);
for (int j = 0; j < positionCount; j++) {
maxCardinalities[j] = max(maxCardinalities[j], columnarMap.getEntryCount(j));
}
} else {
fail("expected an ArrayType or MapType, but found " + type);
}
}
return maxCardinalities;
}
use of com.facebook.presto.common.block.ColumnarArray 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.ColumnarArray in project presto by prestodb.
the class TestColumnarArray method assertColumnarArray.
private static <T> void assertColumnarArray(Block block, T[] expectedValues) {
ColumnarArray columnarArray = toColumnarArray(block);
assertEquals(columnarArray.getPositionCount(), expectedValues.length);
Block elementsBlock = columnarArray.getElementsBlock();
int elementsPosition = 0;
for (int position = 0; position < expectedValues.length; position++) {
T expectedArray = expectedValues[position];
assertEquals(columnarArray.isNull(position), expectedArray == null);
assertEquals(columnarArray.getLength(position), expectedArray == null ? 0 : Array.getLength(expectedArray));
assertEquals(elementsPosition, columnarArray.getOffset(position));
for (int i = 0; i < columnarArray.getLength(position); i++) {
Object expectedElement = Array.get(expectedArray, i);
assertBlockPosition(elementsBlock, elementsPosition, expectedElement);
elementsPosition++;
}
}
}
Aggregations