Search in sources :

Example 26 with RunLengthEncodedBlock

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

the class OrcFileWriter method appendRows.

@Override
public void appendRows(Page dataPage) {
    Block[] blocks = new Block[fileInputColumnIndexes.length];
    boolean[] nullBlocksArray = new boolean[fileInputColumnIndexes.length];
    boolean hasNullBlocks = false;
    int positionCount = dataPage.getPositionCount();
    for (int i = 0; i < fileInputColumnIndexes.length; i++) {
        int inputColumnIndex = fileInputColumnIndexes[i];
        if (inputColumnIndex < 0) {
            hasNullBlocks = true;
            blocks[i] = new RunLengthEncodedBlock(nullBlocks.get(i), positionCount);
        } else {
            blocks[i] = dataPage.getBlock(inputColumnIndex);
        }
        nullBlocksArray[i] = inputColumnIndex < 0;
    }
    if (transaction.isInsert() && useAcidSchema) {
        Optional<boolean[]> nullBlocks = hasNullBlocks ? Optional.of(nullBlocksArray) : Optional.empty();
        Block rowBlock = RowBlock.fromFieldBlocks(positionCount, nullBlocks, blocks);
        blocks = buildAcidColumns(rowBlock, transaction);
    }
    Page page = new Page(dataPage.getPositionCount(), blocks);
    try {
        orcWriter.write(page);
    } catch (IOException | UncheckedIOException e) {
        throw new TrinoException(HIVE_WRITER_DATA_ERROR, e);
    }
}
Also used : Block(io.trino.spi.block.Block) LongArrayBlock(io.trino.spi.block.LongArrayBlock) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) RowBlock(io.trino.spi.block.RowBlock) TrinoException(io.trino.spi.TrinoException) Page(io.trino.spi.Page) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock)

Example 27 with RunLengthEncodedBlock

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

the class ParquetFileWriter method appendRows.

@Override
public void appendRows(Page dataPage) {
    Block[] blocks = new Block[fileInputColumnIndexes.length];
    for (int i = 0; i < fileInputColumnIndexes.length; i++) {
        int inputColumnIndex = fileInputColumnIndexes[i];
        if (inputColumnIndex < 0) {
            blocks[i] = new RunLengthEncodedBlock(nullBlocks.get(i), dataPage.getPositionCount());
        } else {
            blocks[i] = dataPage.getBlock(inputColumnIndex);
        }
    }
    Page page = new Page(dataPage.getPositionCount(), blocks);
    try {
        parquetWriter.write(page);
    } catch (IOException | UncheckedIOException e) {
        throw new TrinoException(HIVE_WRITER_DATA_ERROR, e);
    }
}
Also used : RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) Block(io.trino.spi.block.Block) TrinoException(io.trino.spi.TrinoException) Page(io.trino.spi.Page) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock)

Example 28 with RunLengthEncodedBlock

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

the class IcebergPageSource method getNextPage.

@Override
public Page getNextPage() {
    try {
        Page dataPage = delegate.getNextPage();
        if (projectionsAdapter.isPresent()) {
            dataPage = projectionsAdapter.get().adaptPage(dataPage);
        }
        if (dataPage == null) {
            return null;
        }
        int batchSize = dataPage.getPositionCount();
        Block[] blocks = new Block[prefilledBlocks.length];
        for (int i = 0; i < prefilledBlocks.length; i++) {
            if (prefilledBlocks[i] != null) {
                blocks[i] = new RunLengthEncodedBlock(prefilledBlocks[i], batchSize);
            } else {
                blocks[i] = dataPage.getBlock(delegateIndexes[i]);
            }
        }
        return new Page(batchSize, blocks);
    } catch (RuntimeException e) {
        closeWithSuppression(e);
        throwIfInstanceOf(e, TrinoException.class);
        throw new TrinoException(ICEBERG_BAD_DATA, e);
    }
}
Also used : RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) Block(io.trino.spi.block.Block) TrinoException(io.trino.spi.TrinoException) Page(io.trino.spi.Page) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock)

Example 29 with RunLengthEncodedBlock

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

the class ProjectingPagesWindowIndex method getRawBlock.

@Override
public Block getRawBlock(int channel, int position) {
    if (channel < firstProjectedChannel) {
        return pagesIndex.getRawBlock(channel, position(position));
    }
    int channelIndex = channel - firstProjectedChannel;
    Block compute = compute(position, channelIndex);
    // if there are no non-projected columns, no correction needed
    if (firstProjectedChannel == 0) {
        return compute;
    }
    // projection always creates a single row block, and will not align with the blocks from the pages index,
    // so we use an RLE block of the same length as the raw block
    int rawBlockPositionCount = pagesIndex.getRawBlock(0, position(position)).getPositionCount();
    return new RunLengthEncodedBlock(compute, rawBlockPositionCount);
}
Also used : RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) Utils.nativeValueToBlock(io.trino.spi.predicate.Utils.nativeValueToBlock) Block(io.trino.spi.block.Block) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock)

Example 30 with RunLengthEncodedBlock

use of io.trino.spi.block.RunLengthEncodedBlock 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)

Aggregations

RunLengthEncodedBlock (io.trino.spi.block.RunLengthEncodedBlock)41 Block (io.trino.spi.block.Block)25 Page (io.trino.spi.Page)22 Test (org.testng.annotations.Test)13 DictionaryBlock (io.trino.spi.block.DictionaryBlock)8 TrinoException (io.trino.spi.TrinoException)6 BlockBuilder (io.trino.spi.block.BlockBuilder)6 Slice (io.airlift.slice.Slice)5 BlockAssertions.createLongsBlock (io.trino.block.BlockAssertions.createLongsBlock)5 LongArrayBlock (io.trino.spi.block.LongArrayBlock)5 BlockAssertions.createLongSequenceBlock (io.trino.block.BlockAssertions.createLongSequenceBlock)4 LazyBlock (io.trino.spi.block.LazyBlock)4 Type (io.trino.spi.type.Type)4 IOException (java.io.IOException)4 Utils.nativeValueToBlock (io.trino.spi.predicate.Utils.nativeValueToBlock)3 UncheckedIOException (java.io.UncheckedIOException)3 BlockAssertions.createStringSequenceBlock (io.trino.block.BlockAssertions.createStringSequenceBlock)2 PageSplitterUtil.splitPage (io.trino.execution.buffer.PageSplitterUtil.splitPage)2 DriverYieldSignal (io.trino.operator.DriverYieldSignal)2 PageProcessor (io.trino.operator.project.PageProcessor)2