Search in sources :

Example 1 with RunLengthEncodedBlock

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

the class PagePartitioner method partitionBySingleRleValue.

private void partitionBySingleRleValue(Page page, int position, Page partitionFunctionArgs, IntArrayList[] partitionPositions) {
    // copy all positions because all hash function args are the same for every position
    if (nullChannel != -1 && page.getBlock(nullChannel).isNull(0)) {
        verify(page.getBlock(nullChannel) instanceof RunLengthEncodedBlock, "null channel is not RunLengthEncodedBlock", page.getBlock(nullChannel));
        // all positions are null
        int[] allPositions = integersInRange(position, page.getPositionCount());
        for (IntList partitionPosition : partitionPositions) {
            partitionPosition.addElements(position, allPositions);
        }
    } else {
        // extract rle page to prevent JIT profile pollution
        Page rlePage = extractRlePage(partitionFunctionArgs);
        int partition = partitionFunction.getPartition(rlePage, 0);
        IntArrayList positions = partitionPositions[partition];
        for (int i = position; i < page.getPositionCount(); i++) {
            positions.add(i);
        }
    }
}
Also used : Page(io.trino.spi.Page) PageSplitterUtil.splitPage(io.trino.execution.buffer.PageSplitterUtil.splitPage) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) IntList(it.unimi.dsi.fastutil.ints.IntList)

Example 2 with RunLengthEncodedBlock

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

the class HiveUpdatablePageSource method updateRows.

@Override
public void updateRows(Page page, List<Integer> columnValueAndRowIdChannels) {
    int positionCount = page.getPositionCount();
    // should be filtered out by engine
    verify(positionCount > 0, "Unexpected empty page");
    HiveUpdateProcessor updateProcessor = transaction.getUpdateProcessor().orElseThrow(() -> new IllegalArgumentException("updateProcessor not present"));
    ColumnarRow acidBlock = updateProcessor.getAcidBlock(page, columnValueAndRowIdChannels);
    int fieldCount = acidBlock.getFieldCount();
    checkArgument(fieldCount == 3 || fieldCount == 4, "The rowId block for UPDATE should have 3 or 4 children, but has %s", fieldCount);
    deleteRowsInternal(acidBlock);
    Block mergedColumnsBlock = updateProcessor.createMergedColumnsBlock(page, columnValueAndRowIdChannels);
    Block currentTransactionBlock = RunLengthEncodedBlock.create(BIGINT, writeId, positionCount);
    Block[] blockArray = { new RunLengthEncodedBlock(INSERT_OPERATION_BLOCK, positionCount), currentTransactionBlock, acidBlock.getField(BUCKET_CHANNEL), createRowIdBlock(positionCount), currentTransactionBlock, mergedColumnsBlock };
    Page insertPage = new Page(blockArray);
    lazyInitializeInsertFileWriter();
    insertFileWriter.orElseThrow(() -> new IllegalArgumentException("insertFileWriter not present")).appendRows(insertPage);
}
Also used : ColumnarRow.toColumnarRow(io.trino.spi.block.ColumnarRow.toColumnarRow) ColumnarRow(io.trino.spi.block.ColumnarRow) Utils.nativeValueToBlock(io.trino.spi.predicate.Utils.nativeValueToBlock) Block(io.trino.spi.block.Block) LongArrayBlock(io.trino.spi.block.LongArrayBlock) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) Page(io.trino.spi.Page) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock)

Example 3 with RunLengthEncodedBlock

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

the class HiveUpdatablePageSource method deleteRowsInternal.

private void deleteRowsInternal(ColumnarRow columnarRow) {
    int positionCount = columnarRow.getPositionCount();
    if (columnarRow.mayHaveNull()) {
        for (int position = 0; position < positionCount; position++) {
            checkArgument(!columnarRow.isNull(position), "In the delete rowIds, found null row at position %s", position);
        }
    }
    Block originalTransactionChannel = columnarRow.getField(ORIGINAL_TRANSACTION_CHANNEL);
    Block[] blockArray = { new RunLengthEncodedBlock(DELETE_OPERATION_BLOCK, positionCount), originalTransactionChannel, columnarRow.getField(BUCKET_CHANNEL), columnarRow.getField(ROW_ID_CHANNEL), RunLengthEncodedBlock.create(BIGINT, writeId, positionCount), new RunLengthEncodedBlock(hiveRowTypeNullsBlock, positionCount) };
    Page deletePage = new Page(blockArray);
    for (int index = 0; index < positionCount; index++) {
        maxWriteId = Math.max(maxWriteId, originalTransactionChannel.getLong(index, 0));
    }
    lazyInitializeDeleteFileWriter();
    deleteFileWriter.orElseThrow(() -> new IllegalArgumentException("deleteFileWriter not present")).appendRows(deletePage);
    rowCount += positionCount;
}
Also used : Utils.nativeValueToBlock(io.trino.spi.predicate.Utils.nativeValueToBlock) Block(io.trino.spi.block.Block) LongArrayBlock(io.trino.spi.block.LongArrayBlock) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) Page(io.trino.spi.Page) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock)

Example 4 with RunLengthEncodedBlock

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

the class RcFilePageSource method getNextPage.

@Override
public Page getNextPage() {
    try {
        // advance in the current batch
        pageId++;
        // if the batch has been consumed, read the next batch
        int currentPageSize = rcFileReader.advance();
        if (currentPageSize < 0) {
            close();
            return null;
        }
        Block[] blocks = new Block[hiveColumnIndexes.length];
        for (int fieldId = 0; fieldId < blocks.length; fieldId++) {
            if (constantBlocks[fieldId] != null) {
                blocks[fieldId] = new RunLengthEncodedBlock(constantBlocks[fieldId], currentPageSize);
            } else {
                blocks[fieldId] = createBlock(currentPageSize, fieldId);
            }
        }
        return new Page(currentPageSize, blocks);
    } catch (TrinoException e) {
        closeAllSuppress(e, this);
        throw e;
    } catch (RcFileCorruptionException e) {
        closeAllSuppress(e, this);
        throw new TrinoException(HIVE_BAD_DATA, format("Corrupted RC file: %s", rcFileReader.getId()), e);
    } catch (IOException | RuntimeException e) {
        closeAllSuppress(e, this);
        throw new TrinoException(HIVE_CURSOR_ERROR, format("Failed to read RC file: %s", rcFileReader.getId()), e);
    }
}
Also used : RcFileCorruptionException(io.trino.rcfile.RcFileCorruptionException) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) LazyBlock(io.trino.spi.block.LazyBlock) Block(io.trino.spi.block.Block) TrinoException(io.trino.spi.TrinoException) Page(io.trino.spi.Page) IOException(java.io.IOException) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock)

Example 5 with RunLengthEncodedBlock

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

the class TestGroupByHash method testProperWorkTypesSelected.

@Test
public void testProperWorkTypesSelected() {
    Block bigintBlock = BlockAssertions.createLongsBlock(1, 2, 3, 4, 5, 6, 7, 8);
    Block bigintDictionaryBlock = BlockAssertions.createLongDictionaryBlock(0, 8);
    Block bigintRleBlock = BlockAssertions.createRLEBlock(42, 8);
    Block varcharBlock = BlockAssertions.createStringsBlock("1", "2", "3", "4", "5", "6", "7", "8");
    Block varcharDictionaryBlock = BlockAssertions.createStringDictionaryBlock(1, 8);
    Block varcharRleBlock = new RunLengthEncodedBlock(new VariableWidthBlock(1, Slices.EMPTY_SLICE, new int[] { 0, 1 }, Optional.empty()), 8);
    Block bigintBigDictionaryBlock = BlockAssertions.createLongDictionaryBlock(1, 8, 1000);
    Block bigintSingletonDictionaryBlock = BlockAssertions.createLongDictionaryBlock(1, 500000, 1);
    // Above Short.MAX_VALUE
    Block bigintHugeDictionaryBlock = BlockAssertions.createLongDictionaryBlock(1, 500000, 66000);
    Page singleBigintPage = new Page(bigintBlock);
    assertGroupByHashWork(singleBigintPage, ImmutableList.of(BIGINT), BigintGroupByHash.GetGroupIdsWork.class);
    Page singleBigintDictionaryPage = new Page(bigintDictionaryBlock);
    assertGroupByHashWork(singleBigintDictionaryPage, ImmutableList.of(BIGINT), BigintGroupByHash.GetDictionaryGroupIdsWork.class);
    Page singleBigintRlePage = new Page(bigintRleBlock);
    assertGroupByHashWork(singleBigintRlePage, ImmutableList.of(BIGINT), BigintGroupByHash.GetRunLengthEncodedGroupIdsWork.class);
    Page singleVarcharPage = new Page(varcharBlock);
    assertGroupByHashWork(singleVarcharPage, ImmutableList.of(VARCHAR), MultiChannelGroupByHash.GetNonDictionaryGroupIdsWork.class);
    Page singleVarcharDictionaryPage = new Page(varcharDictionaryBlock);
    assertGroupByHashWork(singleVarcharDictionaryPage, ImmutableList.of(VARCHAR), MultiChannelGroupByHash.GetDictionaryGroupIdsWork.class);
    Page singleVarcharRlePage = new Page(varcharRleBlock);
    assertGroupByHashWork(singleVarcharRlePage, ImmutableList.of(VARCHAR), MultiChannelGroupByHash.GetRunLengthEncodedGroupIdsWork.class);
    Page lowCardinalityDictionaryPage = new Page(bigintDictionaryBlock, varcharDictionaryBlock);
    assertGroupByHashWork(lowCardinalityDictionaryPage, ImmutableList.of(BIGINT, VARCHAR), MultiChannelGroupByHash.GetLowCardinalityDictionaryGroupIdsWork.class);
    Page highCardinalityDictionaryPage = new Page(bigintDictionaryBlock, bigintBigDictionaryBlock);
    assertGroupByHashWork(highCardinalityDictionaryPage, ImmutableList.of(BIGINT, VARCHAR), MultiChannelGroupByHash.GetNonDictionaryGroupIdsWork.class);
    // Cardinality above Short.MAX_VALUE
    Page lowCardinalityHugeDictionaryPage = new Page(bigintSingletonDictionaryBlock, bigintHugeDictionaryBlock);
    assertGroupByHashWork(lowCardinalityHugeDictionaryPage, ImmutableList.of(BIGINT, BIGINT), MultiChannelGroupByHash.GetNonDictionaryGroupIdsWork.class);
}
Also used : TypeTestUtils.getHashBlock(io.trino.type.TypeTestUtils.getHashBlock) BlockAssertions.createLongSequenceBlock(io.trino.block.BlockAssertions.createLongSequenceBlock) DictionaryBlock(io.trino.spi.block.DictionaryBlock) BlockAssertions.createStringSequenceBlock(io.trino.block.BlockAssertions.createStringSequenceBlock) Block(io.trino.spi.block.Block) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) VariableWidthBlock(io.trino.spi.block.VariableWidthBlock) BlockAssertions.createLongsBlock(io.trino.block.BlockAssertions.createLongsBlock) Page(io.trino.spi.Page) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) VariableWidthBlock(io.trino.spi.block.VariableWidthBlock) 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