Search in sources :

Example 71 with DictionaryBlock

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

the class TestDictionaryBlock method testDictionarySizeMethods.

@Test
public void testDictionarySizeMethods() {
    // fixed width block
    Block fixedWidthBlock = new IntArrayBlock(100, Optional.empty(), IntStream.range(0, 100).toArray());
    assertDictionarySizeMethods(fixedWidthBlock);
    // variable width block
    Block variableWidthBlock = createSlicesBlock(createExpectedValues(fixedWidthBlock.getPositionCount()));
    assertDictionarySizeMethods(variableWidthBlock);
    // sparse dictionary block from getPositions
    assertDictionarySizeMethods(fixedWidthBlock.getPositions(IntStream.range(0, 50).toArray(), 0, 50));
    assertDictionarySizeMethods(variableWidthBlock.getPositions(IntStream.range(0, 50).toArray(), 0, 50));
    // nested sparse dictionary block via constructor
    assertDictionarySizeMethods(new DictionaryBlock(fixedWidthBlock, IntStream.range(0, 50).toArray()));
    assertDictionarySizeMethods(new DictionaryBlock(variableWidthBlock, IntStream.range(0, 50).toArray()));
    // compact dictionary block via getPositions
    int[] positions = createCompactRepeatingIdsRange(fixedWidthBlock.getPositionCount());
    assertDictionarySizeMethods(fixedWidthBlock.getPositions(positions, 0, positions.length));
    assertDictionarySizeMethods(variableWidthBlock.getPositions(positions, 0, positions.length));
    // nested compact dictionary block via constructor
    assertDictionarySizeMethods(new DictionaryBlock(fixedWidthBlock, createCompactRepeatingIdsRange(fixedWidthBlock.getPositionCount())));
    assertDictionarySizeMethods(new DictionaryBlock(variableWidthBlock, createCompactRepeatingIdsRange(variableWidthBlock.getPositionCount())));
}
Also used : IntArrayBlock(com.facebook.presto.common.block.IntArrayBlock) BlockAssertions.createRandomDictionaryBlock(com.facebook.presto.block.BlockAssertions.createRandomDictionaryBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) BlockAssertions.createRandomDictionaryBlock(com.facebook.presto.block.BlockAssertions.createRandomDictionaryBlock) BlockAssertions.createSlicesBlock(com.facebook.presto.block.BlockAssertions.createSlicesBlock) BlockAssertions.createRandomLongsBlock(com.facebook.presto.block.BlockAssertions.createRandomLongsBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) IntArrayBlock(com.facebook.presto.common.block.IntArrayBlock) BlockAssertions.createRLEBlock(com.facebook.presto.block.BlockAssertions.createRLEBlock) Block(com.facebook.presto.common.block.Block) Test(org.testng.annotations.Test)

Example 72 with DictionaryBlock

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

the class TestDictionaryBlock method testBasicGetPositions.

@Test
public void testBasicGetPositions() {
    Slice[] expectedValues = createExpectedValues(10);
    Block dictionaryBlock = new DictionaryBlock(createSlicesBlock(expectedValues), new int[] { 0, 1, 2, 3, 4, 5 });
    assertBlock(dictionaryBlock, TestDictionaryBlock::createBlockBuilder, new Slice[] { expectedValues[0], expectedValues[1], expectedValues[2], expectedValues[3], expectedValues[4], expectedValues[5] });
    DictionaryId dictionaryId = ((DictionaryBlock) dictionaryBlock).getDictionarySourceId();
    // first getPositions
    dictionaryBlock = dictionaryBlock.getPositions(new int[] { 0, 8, 1, 2, 4, 5, 7, 9 }, 2, 4);
    assertBlock(dictionaryBlock, TestDictionaryBlock::createBlockBuilder, new Slice[] { expectedValues[1], expectedValues[2], expectedValues[4], expectedValues[5] });
    assertEquals(((DictionaryBlock) dictionaryBlock).getDictionarySourceId(), dictionaryId);
    // second getPositions
    dictionaryBlock = dictionaryBlock.getPositions(new int[] { 0, 1, 3, 0, 0 }, 0, 3);
    assertBlock(dictionaryBlock, TestDictionaryBlock::createBlockBuilder, new Slice[] { expectedValues[1], expectedValues[2], expectedValues[5] });
    assertEquals(((DictionaryBlock) dictionaryBlock).getDictionarySourceId(), dictionaryId);
    // third getPositions; we do not validate if -1 is an invalid position
    dictionaryBlock = dictionaryBlock.getPositions(new int[] { -1, -1, 0, 1, 2 }, 2, 3);
    assertBlock(dictionaryBlock, TestDictionaryBlock::createBlockBuilder, new Slice[] { expectedValues[1], expectedValues[2], expectedValues[5] });
    assertEquals(((DictionaryBlock) dictionaryBlock).getDictionarySourceId(), dictionaryId);
    // mixed getPositions
    dictionaryBlock = dictionaryBlock.getPositions(new int[] { 0, 2, 2 }, 0, 3);
    assertBlock(dictionaryBlock, TestDictionaryBlock::createBlockBuilder, new Slice[] { expectedValues[1], expectedValues[5], expectedValues[5] });
    assertEquals(((DictionaryBlock) dictionaryBlock).getDictionarySourceId(), dictionaryId);
    // duplicated getPositions
    dictionaryBlock = dictionaryBlock.getPositions(new int[] { 1, 1, 1, 1, 1 }, 0, 5);
    assertBlock(dictionaryBlock, TestDictionaryBlock::createBlockBuilder, new Slice[] { expectedValues[5], expectedValues[5], expectedValues[5], expectedValues[5], expectedValues[5] });
    assertEquals(((DictionaryBlock) dictionaryBlock).getDictionarySourceId(), dictionaryId);
    // out of range
    for (int position : ImmutableList.of(-1, 6)) {
        try {
            dictionaryBlock.getPositions(new int[] { position }, 0, 1);
            fail("Expected to fail");
        } catch (IllegalArgumentException e) {
            assertTrue(e.getMessage().startsWith("Invalid position"));
        }
    }
    for (int offset : ImmutableList.of(-1, 6)) {
        try {
            dictionaryBlock.getPositions(new int[] { 0 }, offset, 1);
            fail("Expected to fail");
        } catch (IndexOutOfBoundsException e) {
            assertTrue(e.getMessage().startsWith("Invalid offset"));
        }
    }
    for (int length : ImmutableList.of(-1, 6)) {
        try {
            dictionaryBlock.getPositions(new int[] { 0 }, 0, length);
            fail("Expected to fail");
        } catch (IndexOutOfBoundsException e) {
            assertTrue(e.getMessage().startsWith("Invalid offset"));
        }
    }
}
Also used : Slice(io.airlift.slice.Slice) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) DictionaryId(com.facebook.presto.common.block.DictionaryId) BlockAssertions.createRandomDictionaryBlock(com.facebook.presto.block.BlockAssertions.createRandomDictionaryBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) BlockAssertions.createRandomDictionaryBlock(com.facebook.presto.block.BlockAssertions.createRandomDictionaryBlock) BlockAssertions.createSlicesBlock(com.facebook.presto.block.BlockAssertions.createSlicesBlock) BlockAssertions.createRandomLongsBlock(com.facebook.presto.block.BlockAssertions.createRandomLongsBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) IntArrayBlock(com.facebook.presto.common.block.IntArrayBlock) BlockAssertions.createRLEBlock(com.facebook.presto.block.BlockAssertions.createRLEBlock) Block(com.facebook.presto.common.block.Block) Test(org.testng.annotations.Test)

Example 73 with DictionaryBlock

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

the class TestDictionaryBlock method testCopyPositionsWithCompactionsAndReorder.

@Test
public void testCopyPositionsWithCompactionsAndReorder() {
    Slice[] expectedValues = createExpectedValues(10);
    DictionaryBlock dictionaryBlock = createDictionaryBlock(expectedValues, 100);
    int[] positionsToCopy = new int[] { 50, 55, 40, 45, 60 };
    DictionaryBlock copiedBlock = (DictionaryBlock) dictionaryBlock.copyPositions(positionsToCopy, 0, positionsToCopy.length);
    assertEquals(copiedBlock.getDictionary().getPositionCount(), 2);
    assertEquals(copiedBlock.getPositionCount(), positionsToCopy.length);
    assertBlock(copiedBlock.getDictionary(), TestDictionaryBlock::createBlockBuilder, new Slice[] { expectedValues[0], expectedValues[5] });
    assertDictionaryIds(copiedBlock, 0, 1, 0, 1, 0);
}
Also used : Slice(io.airlift.slice.Slice) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) BlockAssertions.createRandomDictionaryBlock(com.facebook.presto.block.BlockAssertions.createRandomDictionaryBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) Test(org.testng.annotations.Test)

Example 74 with DictionaryBlock

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

the class TestBlockEncodingBuffers method buildDictionaryBlockStatus.

private BlockStatus buildDictionaryBlockStatus(BlockStatus dictionary, int positionCount) {
    DictionaryBlock dictionaryBlock = createRandomDictionaryBlock(dictionary.block, positionCount);
    int[] mappedExpectedRowSizes = IntStream.range(0, positionCount).map(i -> dictionary.expectedRowSizes[dictionaryBlock.getId(i)]).toArray();
    return new BlockStatus(dictionaryBlock, mappedExpectedRowSizes);
}
Also used : MapBlock.fromKeyValueBlock(com.facebook.presto.common.block.MapBlock.fromKeyValueBlock) Page(com.facebook.presto.common.Page) Arrays(java.util.Arrays) BlockAssertions.createRandomLongsBlock(com.facebook.presto.block.BlockAssertions.createRandomLongsBlock) GRACE_FACTOR_FOR_MAX_BUFFER_CAPACITY(com.facebook.presto.operator.repartition.AbstractBlockEncodingBuffer.GRACE_FACTOR_FOR_MAX_BUFFER_CAPACITY) Test(org.testng.annotations.Test) SIZE_OF_BYTE(io.airlift.slice.SizeOf.SIZE_OF_BYTE) DICTIONARY(com.facebook.presto.block.BlockAssertions.Encoding.DICTIONARY) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) AbstractBlockEncodingBuffer.createBlockEncodingBuffers(com.facebook.presto.operator.repartition.AbstractBlockEncodingBuffer.createBlockEncodingBuffers) HASH_MULTIPLIER(com.facebook.presto.operator.repartition.MapBlockEncodingBuffer.HASH_MULTIPLIER) BlockAssertions.assertBlockEquals(com.facebook.presto.block.BlockAssertions.assertBlockEquals) OptimizedPartitionedOutputOperator.decodeBlock(com.facebook.presto.operator.repartition.OptimizedPartitionedOutputOperator.decodeBlock) BlockAssertions.createRandomDictionaryBlock(com.facebook.presto.block.BlockAssertions.createRandomDictionaryBlock) SIZE_OF_INT(io.airlift.slice.SizeOf.SIZE_OF_INT) BlockAssertions.createRandomSmallintsBlock(com.facebook.presto.block.BlockAssertions.createRandomSmallintsBlock) ArrayBlock.fromElementBlock(com.facebook.presto.common.block.ArrayBlock.fromElementBlock) UncheckedStackArrayAllocator(com.facebook.presto.operator.UncheckedStackArrayAllocator) Encoding(com.facebook.presto.block.BlockAssertions.Encoding) BlockAssertions.createAllNullsBlock(com.facebook.presto.block.BlockAssertions.createAllNullsBlock) String.format(java.lang.String.format) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) INTEGER(com.facebook.presto.common.type.IntegerType.INTEGER) Optional(java.util.Optional) BlockAssertions.createRandomBooleansBlock(com.facebook.presto.block.BlockAssertions.createRandomBooleansBlock) BlockAssertions.createRandomStringBlock(com.facebook.presto.block.BlockAssertions.createRandomStringBlock) IntStream(java.util.stream.IntStream) MapType(com.facebook.presto.common.type.MapType) DecimalType(com.facebook.presto.common.type.DecimalType) SliceOutput(io.airlift.slice.SliceOutput) RowType.withDefaultFieldNames(com.facebook.presto.common.type.RowType.withDefaultFieldNames) VARCHAR(com.facebook.presto.common.type.VarcharType.VARCHAR) Assert.assertEquals(org.testng.Assert.assertEquals) MAX_SHORT_PRECISION(com.facebook.presto.common.type.Decimals.MAX_SHORT_PRECISION) DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput) ImmutableList(com.google.common.collect.ImmutableList) Closer(com.google.common.io.Closer) BlockEncodingManager(com.facebook.presto.common.block.BlockEncodingManager) BlockAssertions.createRLEBlock(com.facebook.presto.block.BlockAssertions.createRLEBlock) BlockAssertions.createRandomShortDecimalsBlock(com.facebook.presto.block.BlockAssertions.createRandomShortDecimalsBlock) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) RowBlock.fromFieldBlocks(com.facebook.presto.common.block.RowBlock.fromFieldBlocks) Objects.requireNonNull(java.util.Objects.requireNonNull) BOOLEAN(com.facebook.presto.common.type.BooleanType.BOOLEAN) ArrayType(com.facebook.presto.common.type.ArrayType) StructuralTestUtil.mapType(com.facebook.presto.util.StructuralTestUtil.mapType) RUN_LENGTH(com.facebook.presto.block.BlockAssertions.Encoding.RUN_LENGTH) Math.toIntExact(java.lang.Math.toIntExact) BlockAssertions.createRleBlockWithRandomValue(com.facebook.presto.block.BlockAssertions.createRleBlockWithRandomValue) Type(com.facebook.presto.common.type.Type) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) BlockAssertions.createMapType(com.facebook.presto.block.BlockAssertions.createMapType) BlockFlattener(com.facebook.presto.common.block.BlockFlattener) IOException(java.io.IOException) BlockAssertions.createStringsBlock(com.facebook.presto.block.BlockAssertions.createStringsBlock) BlockAssertions.wrapBlock(com.facebook.presto.block.BlockAssertions.wrapBlock) BlockSerdeUtil.readBlock(com.facebook.presto.common.block.BlockSerdeUtil.readBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) SMALLINT(com.facebook.presto.common.type.SmallintType.SMALLINT) SIZE_OF_LONG(io.airlift.slice.SizeOf.SIZE_OF_LONG) BlockAssertions.createRandomIntsBlock(com.facebook.presto.block.BlockAssertions.createRandomIntsBlock) Block(com.facebook.presto.common.block.Block) BlockAssertions.createRandomLongDecimalsBlock(com.facebook.presto.block.BlockAssertions.createRandomLongDecimalsBlock) RowType(com.facebook.presto.common.type.RowType) DecimalType.createDecimalType(com.facebook.presto.common.type.DecimalType.createDecimalType) BlockAssertions.createRandomDictionaryBlock(com.facebook.presto.block.BlockAssertions.createRandomDictionaryBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock)

Example 75 with DictionaryBlock

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

the class TestDictionaryAwarePageFilter method createDictionaryBlock.

private static DictionaryBlock createDictionaryBlock(int dictionarySize, int blockSize) {
    Block dictionary = createLongSequenceBlock(0, dictionarySize);
    int[] ids = new int[blockSize];
    Arrays.setAll(ids, index -> index % dictionarySize);
    return new DictionaryBlock(dictionary, ids);
}
Also used : DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) BlockAssertions.createLongsBlock(com.facebook.presto.block.BlockAssertions.createLongsBlock) LongArrayBlock(com.facebook.presto.common.block.LongArrayBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) Block(com.facebook.presto.common.block.Block) LazyBlock(com.facebook.presto.common.block.LazyBlock) BlockAssertions.createLongSequenceBlock(com.facebook.presto.block.BlockAssertions.createLongSequenceBlock)

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