Search in sources :

Example 1 with DictionaryBlock

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

the class SliceDictionaryColumnWriter method writeDictionaryRowGroup.

private boolean writeDictionaryRowGroup(Block dictionary, int count, IntBigArray dictionaryIndexes, int maxDirectBytes) {
    int valueCount = count;
    int[][] segments = dictionaryIndexes.getSegments();
    for (int i = 0; valueCount > 0 && i < segments.length; i++) {
        int[] segment = segments[i];
        int positionCount = Math.min(valueCount, segment.length);
        Block block = new DictionaryBlock(positionCount, dictionary, segment);
        while (block != null) {
            int chunkPositionCount = block.getPositionCount();
            Block chunk = block.getRegion(0, chunkPositionCount);
            // avoid chunk with huge logical size
            while (chunkPositionCount > 1 && chunk.getLogicalSizeInBytes() > DIRECT_CONVERSION_CHUNK_MAX_LOGICAL_BYTES) {
                chunkPositionCount /= 2;
                chunk = chunk.getRegion(0, chunkPositionCount);
            }
            directColumnWriter.writeBlock(chunk);
            if (directColumnWriter.getBufferedBytes() > maxDirectBytes) {
                return false;
            }
            // slice block to only unconverted rows
            if (chunkPositionCount < block.getPositionCount()) {
                block = block.getRegion(chunkPositionCount, block.getPositionCount() - chunkPositionCount);
            } else {
                block = null;
            }
        }
        valueCount -= positionCount;
    }
    checkState(valueCount == 0);
    return true;
}
Also used : DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) Block(io.prestosql.spi.block.Block) BooleanStreamCheckpoint(io.prestosql.orc.checkpoint.BooleanStreamCheckpoint) LongStreamCheckpoint(io.prestosql.orc.checkpoint.LongStreamCheckpoint)

Example 2 with DictionaryBlock

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

the class TestLookupJoinPageBuilder method testDifferentPositions.

@Test
public void testDifferentPositions() {
    int entries = 100;
    BlockBuilder blockBuilder = BIGINT.createFixedSizeBlockBuilder(entries);
    for (int i = 0; i < entries; i++) {
        BIGINT.writeLong(blockBuilder, i);
    }
    Block block = blockBuilder.build();
    Page page = new Page(block);
    JoinProbeFactory joinProbeFactory = new JoinProbeFactory(new int[] { 0 }, ImmutableList.of(0), OptionalInt.empty());
    LookupSource lookupSource = new TestLookupSource(ImmutableList.of(BIGINT), page);
    LookupJoinPageBuilder lookupJoinPageBuilder = new LookupJoinPageBuilder(ImmutableList.of(BIGINT));
    // empty
    JoinProbe probe = joinProbeFactory.createJoinProbe(page);
    Page output = lookupJoinPageBuilder.build(probe);
    assertEquals(output.getChannelCount(), 2);
    assertTrue(output.getBlock(0) instanceof DictionaryBlock);
    assertEquals(output.getPositionCount(), 0);
    lookupJoinPageBuilder.reset();
    // the probe covers non-sequential positions
    probe = joinProbeFactory.createJoinProbe(page);
    for (int joinPosition = 0; probe.advanceNextPosition(); joinPosition++) {
        if (joinPosition % 2 == 1) {
            continue;
        }
        lookupJoinPageBuilder.appendRow(probe, lookupSource, joinPosition);
    }
    output = lookupJoinPageBuilder.build(probe);
    assertEquals(output.getChannelCount(), 2);
    assertTrue(output.getBlock(0) instanceof DictionaryBlock);
    assertEquals(output.getPositionCount(), entries / 2);
    for (int i = 0; i < entries / 2; i++) {
        assertEquals(output.getBlock(0).getLong(i, 0), i * 2);
        assertEquals(output.getBlock(1).getLong(i, 0), i * 2);
    }
    lookupJoinPageBuilder.reset();
    // the probe covers everything
    probe = joinProbeFactory.createJoinProbe(page);
    for (int joinPosition = 0; probe.advanceNextPosition(); joinPosition++) {
        lookupJoinPageBuilder.appendRow(probe, lookupSource, joinPosition);
    }
    output = lookupJoinPageBuilder.build(probe);
    assertEquals(output.getChannelCount(), 2);
    assertFalse(output.getBlock(0) instanceof DictionaryBlock);
    assertEquals(output.getPositionCount(), entries);
    for (int i = 0; i < entries; i++) {
        assertEquals(output.getBlock(0).getLong(i, 0), i);
        assertEquals(output.getBlock(1).getLong(i, 0), i);
    }
    lookupJoinPageBuilder.reset();
    // the probe covers some sequential positions
    probe = joinProbeFactory.createJoinProbe(page);
    for (int joinPosition = 0; probe.advanceNextPosition(); joinPosition++) {
        if (joinPosition < 10 || joinPosition >= 50) {
            continue;
        }
        lookupJoinPageBuilder.appendRow(probe, lookupSource, joinPosition);
    }
    output = lookupJoinPageBuilder.build(probe);
    assertEquals(output.getChannelCount(), 2);
    assertFalse(output.getBlock(0) instanceof DictionaryBlock);
    assertEquals(output.getPositionCount(), 40);
    for (int i = 10; i < 50; i++) {
        assertEquals(output.getBlock(0).getLong(i - 10, 0), i);
        assertEquals(output.getBlock(1).getLong(i - 10, 0), i);
    }
}
Also used : JoinProbeFactory(io.prestosql.operator.JoinProbe.JoinProbeFactory) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) Block(io.prestosql.spi.block.Block) Page(io.prestosql.spi.Page) BlockBuilder(io.prestosql.spi.block.BlockBuilder) Test(org.testng.annotations.Test)

Example 3 with DictionaryBlock

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

the class BlockAssertions method createStringDictionaryBlock.

public static Block createStringDictionaryBlock(int start, int length) {
    checkArgument(length > 5, "block must have more than 5 entries");
    int dictionarySize = length / 5;
    BlockBuilder builder = VARCHAR.createBlockBuilder(null, dictionarySize);
    for (int i = start; i < start + dictionarySize; i++) {
        VARCHAR.writeString(builder, String.valueOf(i));
    }
    int[] ids = new int[length];
    for (int i = 0; i < length; i++) {
        ids[i] = i % dictionarySize;
    }
    return new DictionaryBlock(builder.build(), ids);
}
Also used : DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) BlockBuilder(io.prestosql.spi.block.BlockBuilder) RowBlockBuilder(io.prestosql.spi.block.RowBlockBuilder)

Example 4 with DictionaryBlock

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

the class TestDictionaryBlock method testCopyPositionsNoCompaction.

@Test
public void testCopyPositionsNoCompaction() {
    Slice[] expectedValues = createExpectedValues(1);
    DictionaryBlock dictionaryBlock = createDictionaryBlock(expectedValues, 100);
    int[] positionsToCopy = new int[] { 0, 2, 4, 5 };
    DictionaryBlock copiedBlock = (DictionaryBlock) dictionaryBlock.copyPositions(positionsToCopy, 0, positionsToCopy.length);
    assertEquals(copiedBlock.getPositionCount(), positionsToCopy.length);
    assertBlock(copiedBlock.getDictionary(), TestDictionaryBlock::createBlockBuilder, expectedValues);
}
Also used : Slice(io.airlift.slice.Slice) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) Test(org.testng.annotations.Test)

Example 5 with DictionaryBlock

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

the class TestDictionaryBlock method testCopyPositionsSamePosition.

@Test
public void testCopyPositionsSamePosition() {
    Slice[] expectedValues = createExpectedValues(10);
    DictionaryBlock dictionaryBlock = createDictionaryBlock(expectedValues, 100);
    int[] positionsToCopy = new int[] { 52, 52, 52 };
    DictionaryBlock copiedBlock = (DictionaryBlock) dictionaryBlock.copyPositions(positionsToCopy, 0, positionsToCopy.length);
    assertEquals(copiedBlock.getDictionary().getPositionCount(), 1);
    assertEquals(copiedBlock.getPositionCount(), positionsToCopy.length);
    assertBlock(copiedBlock.getDictionary(), TestDictionaryBlock::createBlockBuilder, new Slice[] { expectedValues[2] });
    assertDictionaryIds(copiedBlock, 0, 0, 0);
}
Also used : Slice(io.airlift.slice.Slice) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) Test(org.testng.annotations.Test)

Aggregations

DictionaryBlock (io.prestosql.spi.block.DictionaryBlock)57 Block (io.prestosql.spi.block.Block)29 Test (org.testng.annotations.Test)29 Slice (io.airlift.slice.Slice)17 Page (io.prestosql.spi.Page)9 RunLengthEncodedBlock (io.prestosql.spi.block.RunLengthEncodedBlock)9 ColumnarTestUtils.assertBlock (io.prestosql.block.ColumnarTestUtils.assertBlock)8 PageBuilderStatus (io.prestosql.spi.block.PageBuilderStatus)8 BlockAssertions.createLongSequenceBlock (io.prestosql.block.BlockAssertions.createLongSequenceBlock)7 BlockBuilder (io.prestosql.spi.block.BlockBuilder)6 DictionaryId (io.prestosql.spi.block.DictionaryId)6 LazyBlock (io.prestosql.spi.block.LazyBlock)6 LongArrayBlock (io.prestosql.spi.block.LongArrayBlock)6 TestUnnesterUtil.createSimpleBlock (io.prestosql.operator.unnest.TestUnnesterUtil.createSimpleBlock)5 DictionaryId.randomDictionaryId (io.prestosql.spi.block.DictionaryId.randomDictionaryId)5 BlockAssertions.createLongsBlock (io.prestosql.block.BlockAssertions.createLongsBlock)4 BlockAssertions.createLongDictionaryBlock (io.prestosql.block.BlockAssertions.createLongDictionaryBlock)3 ColumnarTestUtils.createTestDictionaryBlock (io.prestosql.block.ColumnarTestUtils.createTestDictionaryBlock)3 DriverYieldSignal (io.prestosql.operator.DriverYieldSignal)3 JoinProbeFactory (io.prestosql.operator.JoinProbe.JoinProbeFactory)3