Search in sources :

Example 26 with RunLengthEncodedBlock

use of io.prestosql.spi.block.RunLengthEncodedBlock in project hetu-core by openlookeng.

the class TestDictionaryAwarePageProjection method testRleBlock.

@Test(dataProvider = "forceYield")
public void testRleBlock(boolean forceYield) {
    Block value = createLongSequenceBlock(42, 43);
    RunLengthEncodedBlock block = new RunLengthEncodedBlock(value, 100);
    testProject(block, RunLengthEncodedBlock.class, forceYield);
}
Also used : RunLengthEncodedBlock(io.prestosql.spi.block.RunLengthEncodedBlock) LongArrayBlock(io.prestosql.spi.block.LongArrayBlock) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) Block(io.prestosql.spi.block.Block) LazyBlock(io.prestosql.spi.block.LazyBlock) BlockAssertions.createLongSequenceBlock(io.prestosql.block.BlockAssertions.createLongSequenceBlock) RunLengthEncodedBlock(io.prestosql.spi.block.RunLengthEncodedBlock) Test(org.testng.annotations.Test)

Example 27 with RunLengthEncodedBlock

use of io.prestosql.spi.block.RunLengthEncodedBlock in project hetu-core by openlookeng.

the class OrcFileWriter method appendRows.

@Override
public void appendRows(Page dataPage) {
    if (deleteDeltaFileWriter.isPresent()) {
        // Forward to delete writer
        deleteDeltaFileWriter.get().appendRows(dataPage);
    }
    Block[] dataBlocks = new Block[fileInputColumnIndexes.length];
    for (int i = 0; i < fileInputColumnIndexes.length; i++) {
        int inputColumnIndex = fileInputColumnIndexes[i];
        if (inputColumnIndex < 0) {
            dataBlocks[i] = new RunLengthEncodedBlock(dataNullBlocks.get(i), dataPage.getPositionCount());
        } else {
            dataBlocks[i] = dataPage.getBlock(inputColumnIndex);
        }
    }
    Block[] blocks = null;
    int i = 0;
    int totalColumns;
    if (isFullAcid()) {
        Block rowIdBlock = null;
        if (HiveACIDWriteType.isRowIdNeeded(acidWriteType.get())) {
            Block block = dataPage.getBlock(dataPage.getChannelCount() - 1);
            rowIdBlock = block.getLoadedBlock();
        }
        totalColumns = 6;
        blocks = new Block[totalColumns];
        // operation
        blocks[i++] = insertOperationId(dataPage, rowIdBlock, acidWriteType.get().getOperationId());
        // originalTransactionId
        blocks[i++] = insertOriginalTransaction(dataPage, rowIdBlock, writeId);
        // bucketId
        // Bucket Id is encoded to include some extra information from options.
        blocks[i++] = insertBucketIdBlock(dataPage, rowIdBlock, encodedBucketId);
        // rowId
        // rowId is incremental within a delta file./
        blocks[i++] = insertRowIdBlock(dataPage, rowIdBlock);
        // currentTransactionId
        blocks[i++] = insertCurrentTransaction(dataPage, rowIdBlock, writeId);
        boolean isDelete = acidWriteType.get() == HiveACIDWriteType.DELETE || (acidWriteType.get() == HiveACIDWriteType.VACUUM && acidOptions.map(o -> o.isWritingDeleteDelta()).orElse(false));
        blocks[i] = !isDelete ? RowBlock.fromFieldBlocks(dataPage.getPositionCount(), Optional.empty(), dataBlocks) : new RunLengthEncodedBlock(nullBlocks.get(nullBlocks.size() - 1), dataPage.getPositionCount());
        // statistics required to read from hive-cli for historical reasons.
        if (isDelete) {
            acidStats.deletes += dataPage.getPositionCount();
        } else {
            acidStats.inserts += dataPage.getPositionCount();
        }
    } else {
        blocks = dataBlocks;
    }
    Page page = new Page(dataPage.getPositionCount(), blocks);
    try {
        orcWriter.write(page);
    } catch (IOException | UncheckedIOException e) {
        throw new PrestoException(HIVE_WRITER_DATA_ERROR, e);
    }
}
Also used : RunLengthEncodedBlock(io.prestosql.spi.block.RunLengthEncodedBlock) Block(io.prestosql.spi.block.Block) RowBlock(io.prestosql.spi.block.RowBlock) Page(io.prestosql.spi.Page) UncheckedIOException(java.io.UncheckedIOException) PrestoException(io.prestosql.spi.PrestoException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) RunLengthEncodedBlock(io.prestosql.spi.block.RunLengthEncodedBlock)

Example 28 with RunLengthEncodedBlock

use of io.prestosql.spi.block.RunLengthEncodedBlock in project hetu-core by openlookeng.

the class RcFileFileWriter 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 {
        rcFileWriter.write(page);
    } catch (IOException | UncheckedIOException e) {
        throw new PrestoException(HiveErrorCode.HIVE_WRITER_DATA_ERROR, e);
    }
}
Also used : RunLengthEncodedBlock(io.prestosql.spi.block.RunLengthEncodedBlock) Block(io.prestosql.spi.block.Block) Page(io.prestosql.spi.Page) UncheckedIOException(java.io.UncheckedIOException) PrestoException(io.prestosql.spi.PrestoException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) RunLengthEncodedBlock(io.prestosql.spi.block.RunLengthEncodedBlock)

Example 29 with RunLengthEncodedBlock

use of io.prestosql.spi.block.RunLengthEncodedBlock in project hetu-core by openlookeng.

the class DictionaryAwarePageFilter method filter.

@Override
public SelectedPositions filter(ConnectorSession session, Page page) {
    Block block = page.getBlock(0).getLoadedBlock();
    if (block instanceof RunLengthEncodedBlock) {
        Block value = ((RunLengthEncodedBlock) block).getValue();
        Optional<boolean[]> selectedPosition = processDictionary(session, value);
        // in that case we fallback and process again so the correct error message sent
        if (selectedPosition.isPresent()) {
            return SelectedPositions.positionsRange(0, selectedPosition.get()[0] ? page.getPositionCount() : 0);
        }
    }
    if (block instanceof DictionaryBlock) {
        DictionaryBlock dictionaryBlock = (DictionaryBlock) block;
        // Attempt to process the dictionary.  If dictionary is processing has not been considered effective, an empty response will be returned
        Optional<boolean[]> selectedDictionaryPositions = processDictionary(session, dictionaryBlock.getDictionary());
        // record the usage count regardless of dictionary processing choice, so we have stats for next time
        lastDictionaryUsageCount += page.getPositionCount();
        // if dictionary was processed, produce a dictionary block; otherwise do normal processing
        if (selectedDictionaryPositions.isPresent()) {
            return selectDictionaryPositions(dictionaryBlock, selectedDictionaryPositions.get());
        }
    }
    return filter.filter(session, new Page(block));
}
Also used : DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) RunLengthEncodedBlock(io.prestosql.spi.block.RunLengthEncodedBlock) Block(io.prestosql.spi.block.Block) Page(io.prestosql.spi.Page) RunLengthEncodedBlock(io.prestosql.spi.block.RunLengthEncodedBlock)

Example 30 with RunLengthEncodedBlock

use of io.prestosql.spi.block.RunLengthEncodedBlock in project hetu-core by openlookeng.

the class TestPageProcessorCompiler method testSanityRLE.

@Test
public void testSanityRLE() {
    PageProcessor processor = compiler.compilePageProcessor(Optional.empty(), ImmutableList.of(field(0, BIGINT), field(1, VARCHAR)), MAX_BATCH_SIZE).get();
    Slice varcharValue = Slices.utf8Slice("hello");
    Page page = new Page(RunLengthEncodedBlock.create(BIGINT, 123L, 100), RunLengthEncodedBlock.create(VARCHAR, varcharValue, 100));
    Page outputPage = getOnlyElement(processor.process(null, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)).orElseThrow(() -> new AssertionError("page is not present"));
    assertEquals(outputPage.getPositionCount(), 100);
    assertTrue(outputPage.getBlock(0) instanceof RunLengthEncodedBlock);
    assertTrue(outputPage.getBlock(1) instanceof RunLengthEncodedBlock);
    RunLengthEncodedBlock rleBlock = (RunLengthEncodedBlock) outputPage.getBlock(0);
    assertEquals(BIGINT.getLong(rleBlock.getValue(), 0), 123L);
    RunLengthEncodedBlock rleBlock1 = (RunLengthEncodedBlock) outputPage.getBlock(1);
    assertEquals(VARCHAR.getSlice(rleBlock1.getValue(), 0), varcharValue);
}
Also used : PageProcessor(io.prestosql.operator.project.PageProcessor) Slice(io.airlift.slice.Slice) DriverYieldSignal(io.prestosql.operator.DriverYieldSignal) Page(io.prestosql.spi.Page) RunLengthEncodedBlock(io.prestosql.spi.block.RunLengthEncodedBlock) Test(org.testng.annotations.Test)

Aggregations

RunLengthEncodedBlock (io.prestosql.spi.block.RunLengthEncodedBlock)37 Block (io.prestosql.spi.block.Block)24 Page (io.prestosql.spi.Page)17 Test (org.testng.annotations.Test)9 BlockBuilder (io.prestosql.spi.block.BlockBuilder)8 PrestoException (io.prestosql.spi.PrestoException)6 LazyBlock (io.prestosql.spi.block.LazyBlock)6 RowBlock (io.prestosql.spi.block.RowBlock)6 IOException (java.io.IOException)6 Slice (io.airlift.slice.Slice)5 LongArrayBlock (io.prestosql.spi.block.LongArrayBlock)4 UncheckedIOException (java.io.UncheckedIOException)4 DictionaryBlock (io.prestosql.spi.block.DictionaryBlock)3 BlockAssertions.createLongSequenceBlock (io.prestosql.block.BlockAssertions.createLongSequenceBlock)2 DriverYieldSignal (io.prestosql.operator.DriverYieldSignal)2 PageProcessor (io.prestosql.operator.project.PageProcessor)2 RcFileCorruptionException (io.prestosql.rcfile.RcFileCorruptionException)2 RowBlockBuilder (io.prestosql.spi.block.RowBlockBuilder)2 Type (io.prestosql.spi.type.Type)2 ByteArrayOmniBlock (nova.hetu.olk.block.ByteArrayOmniBlock)2