Search in sources :

Example 6 with ByteArrayBlock

use of io.trino.spi.block.ByteArrayBlock in project trino by trinodb.

the class TestRowBlock method testCompactBlock.

@Test
public void testCompactBlock() {
    Block emptyBlock = new ByteArrayBlock(0, Optional.empty(), new byte[0]);
    Block compactFieldBlock1 = new ByteArrayBlock(5, Optional.empty(), createExpectedValue(5).getBytes());
    Block compactFieldBlock2 = new ByteArrayBlock(5, Optional.empty(), createExpectedValue(5).getBytes());
    Block incompactFiledBlock1 = new ByteArrayBlock(5, Optional.empty(), createExpectedValue(6).getBytes());
    Block incompactFiledBlock2 = new ByteArrayBlock(5, Optional.empty(), createExpectedValue(6).getBytes());
    boolean[] rowIsNull = { false, true, false, false, false, false };
    assertCompact(fromFieldBlocks(0, Optional.empty(), new Block[] { emptyBlock, emptyBlock }));
    assertCompact(fromFieldBlocks(rowIsNull.length, Optional.of(rowIsNull), new Block[] { compactFieldBlock1, compactFieldBlock2 }));
    // TODO: add test case for a sliced RowBlock
    // underlying field blocks are not compact
    testIncompactBlock(fromFieldBlocks(rowIsNull.length, Optional.of(rowIsNull), new Block[] { incompactFiledBlock1, incompactFiledBlock2 }));
    testIncompactBlock(fromFieldBlocks(rowIsNull.length, Optional.of(rowIsNull), new Block[] { incompactFiledBlock1, incompactFiledBlock2 }));
}
Also used : SingleRowBlock(io.trino.spi.block.SingleRowBlock) Block(io.trino.spi.block.Block) ByteArrayBlock(io.trino.spi.block.ByteArrayBlock) ByteArrayBlock(io.trino.spi.block.ByteArrayBlock) Test(org.testng.annotations.Test)

Example 7 with ByteArrayBlock

use of io.trino.spi.block.ByteArrayBlock in project trino by trinodb.

the class TestRowBlock method testFromFieldBlocksNoNullsDetection.

@Test
public void testFromFieldBlocksNoNullsDetection() {
    Block emptyBlock = new ByteArrayBlock(0, Optional.empty(), new byte[0]);
    Block fieldBlock = new ByteArrayBlock(5, Optional.empty(), createExpectedValue(5).getBytes());
    boolean[] rowIsNull = new boolean[fieldBlock.getPositionCount()];
    Arrays.fill(rowIsNull, false);
    // Blocks may discard the null mask during creation if no values are null
    assertFalse(fromFieldBlocks(5, Optional.of(rowIsNull), new Block[] { fieldBlock }).mayHaveNull());
    // Last position is null must retain the nulls mask
    rowIsNull[rowIsNull.length - 1] = true;
    assertTrue(fromFieldBlocks(5, Optional.of(rowIsNull), new Block[] { fieldBlock }).mayHaveNull());
    // Empty blocks have no nulls and can also discard their null mask
    assertFalse(fromFieldBlocks(0, Optional.of(new boolean[0]), new Block[] { emptyBlock }).mayHaveNull());
    // Normal blocks should have null masks preserved
    List<Type> fieldTypes = ImmutableList.of(VARCHAR, BIGINT);
    Block hasNullsBlock = createBlockBuilderWithValues(fieldTypes, alternatingNullValues(generateTestRows(fieldTypes, 100))).build();
    assertTrue(hasNullsBlock.mayHaveNull());
}
Also used : Type(io.trino.spi.type.Type) SingleRowBlock(io.trino.spi.block.SingleRowBlock) Block(io.trino.spi.block.Block) ByteArrayBlock(io.trino.spi.block.ByteArrayBlock) ByteArrayBlock(io.trino.spi.block.ByteArrayBlock) Test(org.testng.annotations.Test)

Example 8 with ByteArrayBlock

use of io.trino.spi.block.ByteArrayBlock in project trino by trinodb.

the class TestByteArrayBlock method testCompactBlock.

@Test
public void testCompactBlock() {
    byte[] byteArray = { (byte) 0, (byte) 0, (byte) 1, (byte) 2, (byte) 3, (byte) 4 };
    boolean[] valueIsNull = { false, true, false, false, false, false };
    testCompactBlock(new ByteArrayBlock(0, Optional.empty(), new byte[0]));
    testCompactBlock(new ByteArrayBlock(byteArray.length, Optional.of(valueIsNull), byteArray));
    testIncompactBlock(new ByteArrayBlock(byteArray.length - 1, Optional.of(valueIsNull), byteArray));
}
Also used : ByteArrayBlock(io.trino.spi.block.ByteArrayBlock) Test(org.testng.annotations.Test)

Example 9 with ByteArrayBlock

use of io.trino.spi.block.ByteArrayBlock in project trino by trinodb.

the class TestArrayBlock method testCompactBlock.

@Test
public void testCompactBlock() {
    Block emptyValueBlock = new ByteArrayBlock(0, Optional.empty(), new byte[0]);
    Block compactValueBlock = new ByteArrayBlock(16, Optional.empty(), createExpectedValue(16).getBytes());
    Block inCompactValueBlock = new ByteArrayBlock(16, Optional.empty(), createExpectedValue(17).getBytes());
    int[] offsets = { 0, 1, 1, 2, 4, 8, 16 };
    boolean[] valueIsNull = { false, true, false, false, false, false };
    testCompactBlock(fromElementBlock(0, Optional.empty(), new int[1], emptyValueBlock));
    testCompactBlock(fromElementBlock(valueIsNull.length, Optional.of(valueIsNull), offsets, compactValueBlock));
    testIncompactBlock(fromElementBlock(valueIsNull.length - 1, Optional.of(valueIsNull), offsets, compactValueBlock));
    // underlying value block is not compact
    testIncompactBlock(fromElementBlock(valueIsNull.length, Optional.of(valueIsNull), offsets, inCompactValueBlock));
}
Also used : ArrayBlock.fromElementBlock(io.trino.spi.block.ArrayBlock.fromElementBlock) Block(io.trino.spi.block.Block) ByteArrayBlock(io.trino.spi.block.ByteArrayBlock) ByteArrayBlock(io.trino.spi.block.ByteArrayBlock) Test(org.testng.annotations.Test)

Aggregations

ByteArrayBlock (io.trino.spi.block.ByteArrayBlock)9 Test (org.testng.annotations.Test)8 Block (io.trino.spi.block.Block)7 BlockAssertions.createLongsBlock (io.trino.block.BlockAssertions.createLongsBlock)2 AggregationOperatorFactory (io.trino.operator.AggregationOperator.AggregationOperatorFactory)2 Page (io.trino.spi.Page)2 RunLengthEncodedBlock (io.trino.spi.block.RunLengthEncodedBlock)2 SingleRowBlock (io.trino.spi.block.SingleRowBlock)2 Type (io.trino.spi.type.Type)2 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)2 MaterializedResult (io.trino.testing.MaterializedResult)2 BlockAssertions.createBooleansBlock (io.trino.block.BlockAssertions.createBooleansBlock)1 BlockAssertions.createStringsBlock (io.trino.block.BlockAssertions.createStringsBlock)1 AggregatorFactory (io.trino.operator.aggregation.AggregatorFactory)1 OrcCorruptionException (io.trino.orc.OrcCorruptionException)1 ColumnReaders.createColumnReader (io.trino.orc.reader.ColumnReaders.createColumnReader)1 ReaderUtils.verifyStreamType (io.trino.orc.reader.ReaderUtils.verifyStreamType)1 ArrayBlock.fromElementBlock (io.trino.spi.block.ArrayBlock.fromElementBlock)1 BlockBuilder (io.trino.spi.block.BlockBuilder)1 LazyBlock (io.trino.spi.block.LazyBlock)1