Search in sources :

Example 81 with DictionaryBlock

use of com.facebook.presto.common.block.DictionaryBlock in project urban-eureka by errir503.

the class SliceDictionaryBatchStreamReader method readBlock.

@Override
public Block readBlock() throws IOException {
    if (!rowGroupOpen) {
        openRowGroup();
    }
    if (readOffset > 0) {
        if (presentStream != null) {
            // skip ahead the present bit reader, but count the set bits
            // and use this as the skip size for the length reader
            readOffset = presentStream.countBitsSet(readOffset);
        }
        if (readOffset > 0) {
            if (dataStream == null) {
                throw new OrcCorruptionException(streamDescriptor.getOrcDataSourceId(), "Value is not null but data stream is not present");
            }
            if (inDictionaryStream != null) {
                inDictionaryStream.skip(readOffset);
            }
            dataStream.skip(readOffset);
        }
    }
    int[] idsVector = new int[nextBatchSize];
    if (presentStream == null) {
        // Data doesn't have nulls
        if (dataStream == null) {
            throw new OrcCorruptionException(streamDescriptor.getOrcDataSourceId(), "Value is not null but data stream is not present");
        }
        if (inDictionaryStream == null) {
            dataStream.next(idsVector, nextBatchSize);
        } else {
            for (int i = 0; i < nextBatchSize; i++) {
                idsVector[i] = toIntExact(dataStream.next());
                if (!inDictionaryStream.nextBit()) {
                    // row group dictionary elements are after the main dictionary
                    idsVector[i] += stripeDictionarySize;
                }
            }
        }
    } else {
        // Data has nulls
        if (dataStream == null) {
            // The only valid case for dataStream is null when data has nulls is that all values are nulls.
            // In that case the only element in the dictionaryBlock is null and the ids in idsVector should
            // be all 0's, so we don't need to update idVector again.
            int nullValues = presentStream.getUnsetBits(nextBatchSize);
            if (nullValues != nextBatchSize) {
                throw new OrcCorruptionException(streamDescriptor.getOrcDataSourceId(), "Value is not null but data stream is not present");
            }
        } else {
            for (int i = 0; i < nextBatchSize; i++) {
                if (!presentStream.nextBit()) {
                    // null is the last entry in the slice dictionary
                    idsVector[i] = dictionaryBlock.getPositionCount() - 1;
                } else {
                    idsVector[i] = toIntExact(dataStream.next());
                    if (inDictionaryStream != null && !inDictionaryStream.nextBit()) {
                        // row group dictionary elements are after the main dictionary
                        idsVector[i] += stripeDictionarySize;
                    }
                }
            }
        }
    }
    Block block = new DictionaryBlock(nextBatchSize, dictionaryBlock, idsVector);
    readOffset = 0;
    nextBatchSize = 0;
    return block;
}
Also used : DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) VariableWidthBlock(com.facebook.presto.common.block.VariableWidthBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) Block(com.facebook.presto.common.block.Block) OrcCorruptionException(com.facebook.presto.orc.OrcCorruptionException)

Example 82 with DictionaryBlock

use of com.facebook.presto.common.block.DictionaryBlock in project urban-eureka by errir503.

the class SliceDictionarySelectiveReader method getBlockView.

@Override
public BlockLease getBlockView(int[] positions, int positionCount) {
    checkArgument(outputPositionCount > 0, "outputPositionCount must be greater than zero");
    checkState(outputRequired, "This stream reader doesn't produce output");
    checkState(positionCount <= outputPositionCount, "Not enough values");
    checkState(!valuesInUse, "BlockLease hasn't been closed yet");
    if (allNulls) {
        return newLease(new RunLengthEncodedBlock(outputType.createBlockBuilder(null, 1).appendNull().build(), positionCount));
    }
    if (positionCount < outputPositionCount) {
        compactValues(positions, positionCount);
    }
    wrapDictionaryIfNecessary();
    return newLease(new DictionaryBlock(positionCount, dictionary, values));
}
Also used : DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock)

Example 83 with DictionaryBlock

use of com.facebook.presto.common.block.DictionaryBlock in project urban-eureka by errir503.

the class TestPageProcessorCompiler method testSanityColumnarDictionary.

@Test
public void testSanityColumnarDictionary() {
    PageProcessor processor = compiler.compilePageProcessor(TEST_SESSION.getSqlFunctionProperties(), Optional.empty(), ImmutableList.of(field(0, VARCHAR)), false, MAX_BATCH_SIZE).get();
    Page page = new Page(createDictionaryBlock(createExpectedValues(10), 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 DictionaryBlock);
    DictionaryBlock dictionaryBlock = (DictionaryBlock) outputPage.getBlock(0);
    assertEquals(dictionaryBlock.getDictionary().getPositionCount(), 10);
}
Also used : PageProcessor(com.facebook.presto.operator.project.PageProcessor) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) BlockAssertions.createLongDictionaryBlock(com.facebook.presto.block.BlockAssertions.createLongDictionaryBlock) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) Page(com.facebook.presto.common.Page) Test(org.testng.annotations.Test)

Example 84 with DictionaryBlock

use of com.facebook.presto.common.block.DictionaryBlock in project urban-eureka by errir503.

the class TestPageProcessorCompiler method testSanityFilterOnDictionary.

@Test
public void testSanityFilterOnDictionary() {
    FunctionAndTypeManager functionAndTypeManager = createTestMetadataManager().getFunctionAndTypeManager();
    CallExpression lengthVarchar = new CallExpression("length", functionAndTypeManager.lookupFunction("length", fromTypes(VARCHAR)), BIGINT, ImmutableList.of(field(0, VARCHAR)));
    FunctionHandle lessThan = functionAndTypeManager.resolveOperator(LESS_THAN, fromTypes(BIGINT, BIGINT));
    CallExpression filter = new CallExpression(LESS_THAN.name(), lessThan, BOOLEAN, ImmutableList.of(lengthVarchar, constant(10L, BIGINT)));
    PageProcessor processor = compiler.compilePageProcessor(TEST_SESSION.getSqlFunctionProperties(), Optional.of(filter), ImmutableList.of(field(0, VARCHAR)), false, MAX_BATCH_SIZE).get();
    Page page = new Page(createDictionaryBlock(createExpectedValues(10), 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 DictionaryBlock);
    DictionaryBlock dictionaryBlock = (DictionaryBlock) outputPage.getBlock(0);
    assertEquals(dictionaryBlock.getDictionary().getPositionCount(), 10);
    // test filter caching
    Page outputPage2 = getOnlyElement(processor.process(null, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)).orElseThrow(() -> new AssertionError("page is not present"));
    assertEquals(outputPage2.getPositionCount(), 100);
    assertTrue(outputPage2.getBlock(0) instanceof DictionaryBlock);
    DictionaryBlock dictionaryBlock2 = (DictionaryBlock) outputPage2.getBlock(0);
    // both output pages must have the same dictionary
    assertEquals(dictionaryBlock2.getDictionary(), dictionaryBlock.getDictionary());
}
Also used : PageProcessor(com.facebook.presto.operator.project.PageProcessor) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) BlockAssertions.createLongDictionaryBlock(com.facebook.presto.block.BlockAssertions.createLongDictionaryBlock) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) Page(com.facebook.presto.common.Page) CallExpression(com.facebook.presto.spi.relation.CallExpression) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle) Test(org.testng.annotations.Test)

Example 85 with DictionaryBlock

use of com.facebook.presto.common.block.DictionaryBlock in project urban-eureka by errir503.

the class FilterFunction method filterWithDictionary.

private int filterWithDictionary(Page page, int[] positions, int positionCount, RuntimeException[] errors) {
    int outputCount = 0;
    DictionaryBlock block = (DictionaryBlock) page.getBlock(0);
    Block dictionary = block.getDictionary();
    if (dictionary != previousDictionary) {
        previousDictionary = dictionary;
        int numEntries = dictionary.getPositionCount();
        dictionaryPage = new Page(numEntries, dictionary);
        dictionaryResults = ensureCapacity(dictionaryResults, numEntries);
        fill(dictionaryResults, 0, numEntries, FILTER_NOT_EVALUATED);
    }
    for (int i = 0; i < positionCount; i++) {
        int position = positions[i];
        int dictionaryPosition = block.getId(position);
        byte result = dictionaryResults[dictionaryPosition];
        switch(result) {
            case FILTER_FAILED:
                continue;
            case FILTER_PASSED:
                positions[outputCount] = position;
                errors[outputCount] = errors[i];
                outputCount++;
                continue;
            case FILTER_NOT_EVALUATED:
                try {
                    if (predicate.evaluate(properties, dictionaryPage, dictionaryPosition)) {
                        positions[outputCount] = position;
                        errors[outputCount] = errors[i];
                        outputCount++;
                        dictionaryResults[dictionaryPosition] = FILTER_PASSED;
                    } else {
                        dictionaryResults[dictionaryPosition] = FILTER_FAILED;
                    }
                } catch (RuntimeException e) {
                    // We do not record errors in the dictionary results.
                    positions[outputCount] = position;
                    // keep last error
                    errors[outputCount] = e;
                    outputCount++;
                }
                break;
            default:
                verify(false, "Unexpected filter result: " + result);
        }
    }
    return outputCount;
}
Also used : DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) Block(com.facebook.presto.common.block.Block) Page(com.facebook.presto.common.Page)

Aggregations

DictionaryBlock (com.facebook.presto.common.block.DictionaryBlock)125 Test (org.testng.annotations.Test)66 Block (com.facebook.presto.common.block.Block)65 BlockAssertions.createRandomDictionaryBlock (com.facebook.presto.block.BlockAssertions.createRandomDictionaryBlock)32 RunLengthEncodedBlock (com.facebook.presto.common.block.RunLengthEncodedBlock)28 Slice (io.airlift.slice.Slice)26 Page (com.facebook.presto.common.Page)25 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)22 Slices.utf8Slice (io.airlift.slice.Slices.utf8Slice)22 BlockAssertions.createLongSequenceBlock (com.facebook.presto.block.BlockAssertions.createLongSequenceBlock)14 LongArrayBlock (com.facebook.presto.common.block.LongArrayBlock)14 DictionaryId (com.facebook.presto.common.block.DictionaryId)12 LazyBlock (com.facebook.presto.common.block.LazyBlock)12 BlockAssertions.createLongsBlock (com.facebook.presto.block.BlockAssertions.createLongsBlock)10 BlockAssertions.createRLEBlock (com.facebook.presto.block.BlockAssertions.createRLEBlock)10 BlockAssertions.createRandomLongsBlock (com.facebook.presto.block.BlockAssertions.createRandomLongsBlock)10 BlockAssertions.createSlicesBlock (com.facebook.presto.block.BlockAssertions.createSlicesBlock)10 DictionaryId.randomDictionaryId (com.facebook.presto.common.block.DictionaryId.randomDictionaryId)10 IntArrayBlock (com.facebook.presto.common.block.IntArrayBlock)8 Type (com.facebook.presto.common.type.Type)8