Search in sources :

Example 1 with ByteArrayBlock

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

the class TestAggregationOperator method testMaskWithDirtyNulls.

@Test
public void testMaskWithDirtyNulls() {
    List<Page> input = ImmutableList.of(new Page(4, createLongsBlock(1, 2, 3, 4), new ByteArrayBlock(4, Optional.of(new boolean[] { true, true, false, false }), new byte[] { 0, 27, /* dirty null */
    0, 75 /* non-zero value is true */
    })));
    OperatorFactory operatorFactory = new AggregationOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(COUNT.createAggregatorFactory(SINGLE, ImmutableList.of(0), OptionalInt.of(1))));
    DriverContext driverContext = createTaskContext(executor, scheduledExecutor, TEST_SESSION).addPipelineContext(0, true, true, false).addDriverContext();
    MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT).row(1L).build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) AggregationOperatorFactory(io.trino.operator.AggregationOperator.AggregationOperatorFactory) AggregationOperatorFactory(io.trino.operator.AggregationOperator.AggregationOperatorFactory) Page(io.trino.spi.Page) ByteArrayBlock(io.trino.spi.block.ByteArrayBlock) MaterializedResult(io.trino.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 2 with ByteArrayBlock

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

the class TestMapBlock method testCompactBlock.

@Test
public void testCompactBlock() {
    Block emptyBlock = new ByteArrayBlock(0, Optional.empty(), new byte[0]);
    Block compactKeyBlock = new ByteArrayBlock(16, Optional.empty(), createExpectedValue(16).getBytes());
    Block compactValueBlock = new ByteArrayBlock(16, Optional.empty(), createExpectedValue(16).getBytes());
    Block inCompactKeyBlock = new ByteArrayBlock(16, Optional.empty(), createExpectedValue(17).getBytes());
    Block inCompactValueBlock = new ByteArrayBlock(16, Optional.empty(), createExpectedValue(17).getBytes());
    int[] offsets = { 0, 1, 1, 2, 4, 8, 16 };
    boolean[] mapIsNull = { false, true, false, false, false, false };
    testCompactBlock(mapType(TINYINT, TINYINT).createBlockFromKeyValue(Optional.empty(), new int[1], emptyBlock, emptyBlock));
    testCompactBlock(mapType(TINYINT, TINYINT).createBlockFromKeyValue(Optional.of(mapIsNull), offsets, compactKeyBlock, compactValueBlock));
    // TODO: Add test case for a sliced MapBlock
    // underlying key/value block is not compact
    testIncompactBlock(mapType(TINYINT, TINYINT).createBlockFromKeyValue(Optional.of(mapIsNull), offsets, inCompactKeyBlock, inCompactValueBlock));
}
Also used : MapBlock(io.trino.spi.block.MapBlock) Block(io.trino.spi.block.Block) BlockAssertions.createStringsBlock(io.trino.block.BlockAssertions.createStringsBlock) SingleMapBlock(io.trino.spi.block.SingleMapBlock) BlockAssertions.createLongsBlock(io.trino.block.BlockAssertions.createLongsBlock) ByteArrayBlock(io.trino.spi.block.ByteArrayBlock) ByteArrayBlock(io.trino.spi.block.ByteArrayBlock) Test(org.testng.annotations.Test)

Example 3 with ByteArrayBlock

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

the class UnionColumnReader method getBlocks.

private Block[] getBlocks(int positionCount) throws IOException {
    if (dataStream == null) {
        throw new OrcCorruptionException(column.getOrcDataSourceId(), "Value is not null but data stream is missing");
    }
    Block[] blocks = new Block[fieldReaders.size() + 1];
    byte[] tags = dataStream.next(positionCount);
    blocks[0] = new ByteArrayBlock(positionCount, Optional.empty(), tags);
    boolean[][] valueIsNonNull = new boolean[fieldReaders.size()][positionCount];
    int[] nonNullValueCount = new int[fieldReaders.size()];
    for (int i = 0; i < positionCount; i++) {
        valueIsNonNull[tags[i]][i] = true;
        nonNullValueCount[tags[i]]++;
    }
    for (int i = 0; i < fieldReaders.size(); i++) {
        Type fieldType = type.getTypeParameters().get(i + 1);
        if (nonNullValueCount[i] > 0) {
            ColumnReader reader = fieldReaders.get(i);
            reader.prepareNextRead(nonNullValueCount[i]);
            Block rawBlock = blockFactory.createBlock(nonNullValueCount[i], reader::readBlock, true);
            blocks[i + 1] = new LazyBlock(positionCount, new UnpackLazyBlockLoader(rawBlock, fieldType, valueIsNonNull[i]));
        } else {
            blocks[i + 1] = new RunLengthEncodedBlock(fieldType.createBlockBuilder(null, 1).appendNull().build(), positionCount);
        }
    }
    return blocks;
}
Also used : Type(io.trino.spi.type.Type) RowType(io.trino.spi.type.RowType) ReaderUtils.verifyStreamType(io.trino.orc.reader.ReaderUtils.verifyStreamType) LazyBlock(io.trino.spi.block.LazyBlock) LazyBlock(io.trino.spi.block.LazyBlock) Block(io.trino.spi.block.Block) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) RowBlock(io.trino.spi.block.RowBlock) ByteArrayBlock(io.trino.spi.block.ByteArrayBlock) ByteArrayBlock(io.trino.spi.block.ByteArrayBlock) OrcCorruptionException(io.trino.orc.OrcCorruptionException) ColumnReaders.createColumnReader(io.trino.orc.reader.ColumnReaders.createColumnReader) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock)

Example 4 with ByteArrayBlock

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

the class TestAggregationOperator method testDistinctMaskWithNulls.

@Test
public void testDistinctMaskWithNulls() {
    AggregatorFactory distinctFactory = LONG_SUM.createDistinctAggregatorFactory(SINGLE, ImmutableList.of(0), OptionalInt.of(1));
    DriverContext driverContext = createTaskContext(executor, scheduledExecutor, TEST_SESSION).addPipelineContext(0, true, true, false).addDriverContext();
    OperatorFactory operatorFactory = new AggregationOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(distinctFactory));
    ByteArrayBlock trueMaskAllNull = new ByteArrayBlock(4, Optional.of(new boolean[] { true, true, true, true }), /* all positions are null */
    new byte[] { 1, 1, 1, 1 });
    /* non-zero value is true, all masks are true */
    Block trueNullRleMask = new RunLengthEncodedBlock(trueMaskAllNull.getSingleValueBlock(0), 4);
    List<Page> nullTrueMaskInput = ImmutableList.of(new Page(4, createLongsBlock(1, 2, 3, 4), trueMaskAllNull), new Page(4, createLongsBlock(10, 11, 10, 11), createBooleansBlock(true, true, true, true)), new Page(4, createLongsBlock(5, 6, 7, 8), trueNullRleMask));
    MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT).row(21L).build();
    assertOperatorEquals(operatorFactory, driverContext, nullTrueMaskInput, expected);
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) AggregationOperatorFactory(io.trino.operator.AggregationOperator.AggregationOperatorFactory) AggregationOperatorFactory(io.trino.operator.AggregationOperator.AggregationOperatorFactory) Block(io.trino.spi.block.Block) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) BlockAssertions.createBooleansBlock(io.trino.block.BlockAssertions.createBooleansBlock) BlockAssertions.createLongsBlock(io.trino.block.BlockAssertions.createLongsBlock) ByteArrayBlock(io.trino.spi.block.ByteArrayBlock) ByteArrayBlock(io.trino.spi.block.ByteArrayBlock) Page(io.trino.spi.Page) AggregatorFactory(io.trino.operator.aggregation.AggregatorFactory) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) MaterializedResult(io.trino.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 5 with ByteArrayBlock

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

the class TestBooleanType method testBooleanBlockWithoutNullsFromByteArray.

@Test
public void testBooleanBlockWithoutNullsFromByteArray() {
    byte[] booleanBytes = new byte[4];
    BlockBuilder builder = BOOLEAN.createFixedSizeBlockBuilder(booleanBytes.length);
    for (int i = 0; i < booleanBytes.length; i++) {
        boolean value = i % 2 == 0;
        booleanBytes[i] = value ? (byte) 1 : 0;
        BOOLEAN.writeBoolean(builder, value);
    }
    Block wrappedBlock = BooleanType.wrapByteArrayAsBooleanBlockWithoutNulls(booleanBytes);
    Block builderBlock = builder.build();
    // wrapped instances have no nulls
    assertFalse(wrappedBlock.mayHaveNull());
    // wrapped byte array instances and builder based instances both produce ByteArrayBlock
    assertTrue(wrappedBlock instanceof ByteArrayBlock);
    assertTrue(builderBlock instanceof ByteArrayBlock);
    assertBlockEquals(BOOLEAN, wrappedBlock, builderBlock);
    // the wrapping instance does not copy the byte array defensively
    assertTrue(BOOLEAN.getBoolean(wrappedBlock, 0));
    booleanBytes[0] = 0;
    assertFalse(BOOLEAN.getBoolean(wrappedBlock, 0));
}
Also used : Block(io.trino.spi.block.Block) ByteArrayBlock(io.trino.spi.block.ByteArrayBlock) ByteArrayBlock(io.trino.spi.block.ByteArrayBlock) BlockBuilder(io.trino.spi.block.BlockBuilder) 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