Search in sources :

Example 11 with RowBlock

use of com.facebook.presto.common.block.RowBlock in project presto by prestodb.

the class TestWriterBlockRawSize method testRowType.

@Test
public void testRowType() {
    Type elementType = INTEGER;
    Type rowType = RowType.anonymous(ImmutableList.of(elementType, elementType));
    ColumnWriter columnWriter = createColumnWriter(rowType);
    BlockBuilder blockBuilder = elementType.createBlockBuilder(null, NUM_ELEMENTS);
    boolean[] isNull = new boolean[NUM_ELEMENTS * 2];
    for (int i = 0; i < NUM_ELEMENTS; i++) {
        elementType.writeLong(blockBuilder, i);
        isNull[i * 2] = true;
    }
    Block elementBlock = blockBuilder.build();
    Block[] elementBlocks = new Block[] { elementBlock, elementBlock };
    Block rowBlock = RowBlock.fromFieldBlocks(NUM_ELEMENTS * 2, Optional.of(isNull), elementBlocks);
    long rawSize = columnWriter.writeBlock(rowBlock);
    long expectedSize = NUM_ELEMENTS + (NUM_ELEMENTS * 2 * ((FixedWidthType) elementType).getFixedSize());
    assertEquals(rawSize, expectedSize);
}
Also used : TestOrcMapNullKey.createMapType(com.facebook.presto.orc.TestOrcMapNullKey.createMapType) TimestampType(com.facebook.presto.common.type.TimestampType) ArrayType(com.facebook.presto.common.type.ArrayType) OrcType(com.facebook.presto.orc.metadata.OrcType) Type(com.facebook.presto.common.type.Type) FixedWidthType(com.facebook.presto.common.type.FixedWidthType) RowType(com.facebook.presto.common.type.RowType) RowBlock(com.facebook.presto.common.block.RowBlock) Block(com.facebook.presto.common.block.Block) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) Test(org.testng.annotations.Test)

Aggregations

RowBlock (com.facebook.presto.common.block.RowBlock)11 Type (com.facebook.presto.common.type.Type)8 ImmutableList (com.google.common.collect.ImmutableList)6 Test (org.testng.annotations.Test)6 Block (com.facebook.presto.common.block.Block)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 RunLengthEncodedBlock (com.facebook.presto.common.block.RunLengthEncodedBlock)3 ArrayBlock (com.facebook.presto.common.block.ArrayBlock)2 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)2 RowType (com.facebook.presto.common.type.RowType)2 DataSize (io.airlift.units.DataSize)2 Page (com.facebook.presto.common.Page)1 RuntimeStats (com.facebook.presto.common.RuntimeStats)1 BlockLease (com.facebook.presto.common.block.BlockLease)1 ColumnarArray (com.facebook.presto.common.block.ColumnarArray)1 ColumnarMap (com.facebook.presto.common.block.ColumnarMap)1 ColumnarRow (com.facebook.presto.common.block.ColumnarRow)1 DictionaryBlock (com.facebook.presto.common.block.DictionaryBlock)1 IntArrayBlock (com.facebook.presto.common.block.IntArrayBlock)1