Search in sources :

Example 1 with Encoding

use of com.facebook.presto.block.BlockAssertions.Encoding in project presto by prestodb.

the class TestBlockEncodingBuffers method buildMapBlockStatus.

private BlockStatus buildMapBlockStatus(MapType mapType, int positionCount, boolean isView, Optional<boolean[]> isNull, int[] offsets, float primitiveNullRate, float nestedNullRate, List<Encoding> wrappings) {
    BlockStatus blockStatus;
    BlockStatus keyBlockStatus = buildBlockStatusWithType(mapType.getKeyType(), offsets[positionCount], isView, 0.0f, 0.0f, wrappings);
    BlockStatus valueBlockStatus = buildBlockStatusWithType(mapType.getValueType(), offsets[positionCount], isView, primitiveNullRate, nestedNullRate, wrappings);
    int[] expectedKeySizes = keyBlockStatus.expectedRowSizes;
    int[] expectedValueSizes = valueBlockStatus.expectedRowSizes;
    // Use expectedKeySizes for the total size for both key and values
    Arrays.setAll(expectedKeySizes, i -> expectedKeySizes[i] + expectedValueSizes[i]);
    int[] expectedRowSizes = IntStream.range(0, positionCount).map(i -> MapBlockEncodingBuffer.POSITION_SIZE + Arrays.stream(expectedKeySizes, offsets[i], offsets[i + 1]).sum()).toArray();
    Type keyType = mapType.getKeyType();
    blockStatus = new BlockStatus(fromKeyValueBlock(positionCount, isNull, offsets, keyBlockStatus.block, valueBlockStatus.block), expectedRowSizes);
    return blockStatus;
}
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) MapType(com.facebook.presto.common.type.MapType) DecimalType(com.facebook.presto.common.type.DecimalType) ArrayType(com.facebook.presto.common.type.ArrayType) StructuralTestUtil.mapType(com.facebook.presto.util.StructuralTestUtil.mapType) Type(com.facebook.presto.common.type.Type) BlockAssertions.createMapType(com.facebook.presto.block.BlockAssertions.createMapType) RowType(com.facebook.presto.common.type.RowType) DecimalType.createDecimalType(com.facebook.presto.common.type.DecimalType.createDecimalType)

Aggregations

Encoding (com.facebook.presto.block.BlockAssertions.Encoding)1 DICTIONARY (com.facebook.presto.block.BlockAssertions.Encoding.DICTIONARY)1 RUN_LENGTH (com.facebook.presto.block.BlockAssertions.Encoding.RUN_LENGTH)1 BlockAssertions.assertBlockEquals (com.facebook.presto.block.BlockAssertions.assertBlockEquals)1 BlockAssertions.createAllNullsBlock (com.facebook.presto.block.BlockAssertions.createAllNullsBlock)1 BlockAssertions.createMapType (com.facebook.presto.block.BlockAssertions.createMapType)1 BlockAssertions.createRLEBlock (com.facebook.presto.block.BlockAssertions.createRLEBlock)1 BlockAssertions.createRandomBooleansBlock (com.facebook.presto.block.BlockAssertions.createRandomBooleansBlock)1 BlockAssertions.createRandomDictionaryBlock (com.facebook.presto.block.BlockAssertions.createRandomDictionaryBlock)1 BlockAssertions.createRandomIntsBlock (com.facebook.presto.block.BlockAssertions.createRandomIntsBlock)1 BlockAssertions.createRandomLongDecimalsBlock (com.facebook.presto.block.BlockAssertions.createRandomLongDecimalsBlock)1 BlockAssertions.createRandomLongsBlock (com.facebook.presto.block.BlockAssertions.createRandomLongsBlock)1 BlockAssertions.createRandomShortDecimalsBlock (com.facebook.presto.block.BlockAssertions.createRandomShortDecimalsBlock)1 BlockAssertions.createRandomSmallintsBlock (com.facebook.presto.block.BlockAssertions.createRandomSmallintsBlock)1 BlockAssertions.createRandomStringBlock (com.facebook.presto.block.BlockAssertions.createRandomStringBlock)1 BlockAssertions.createRleBlockWithRandomValue (com.facebook.presto.block.BlockAssertions.createRleBlockWithRandomValue)1 BlockAssertions.createStringsBlock (com.facebook.presto.block.BlockAssertions.createStringsBlock)1 BlockAssertions.wrapBlock (com.facebook.presto.block.BlockAssertions.wrapBlock)1 Page (com.facebook.presto.common.Page)1 ArrayBlock.fromElementBlock (com.facebook.presto.common.block.ArrayBlock.fromElementBlock)1