Search in sources :

Example 1 with Object2LongOpenCustomHashMap

use of it.unimi.dsi.fastutil.objects.Object2LongOpenCustomHashMap in project presto by prestodb.

the class TestBlockRetainedSizeBreakdown method checkRetainedSize.

private static void checkRetainedSize(Block block, boolean getRegionCreateNewObjects) {
    AtomicLong objectSize = new AtomicLong();
    Object2LongOpenCustomHashMap<Object> trackedObjects = new Object2LongOpenCustomHashMap<>(new ObjectStrategy());
    BiConsumer<Object, Long> consumer = (object, size) -> {
        objectSize.addAndGet(size);
        trackedObjects.addTo(object, 1);
    };
    block.retainedBytesForEachPart(consumer);
    assertEquals(objectSize.get(), block.getRetainedSizeInBytes());
    Block copyBlock = block.getRegion(0, block.getPositionCount() / 2);
    copyBlock.retainedBytesForEachPart(consumer);
    assertEquals(objectSize.get(), block.getRetainedSizeInBytes() + copyBlock.getRetainedSizeInBytes());
    assertEquals(trackedObjects.getLong(block), 1);
    assertEquals(trackedObjects.getLong(copyBlock), 1);
    trackedObjects.remove(block);
    trackedObjects.remove(copyBlock);
    for (long value : trackedObjects.values()) {
        assertEquals(value, getRegionCreateNewObjects ? 1 : 2);
    }
}
Also used : Object2LongOpenCustomHashMap(it.unimi.dsi.fastutil.objects.Object2LongOpenCustomHashMap) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) TINYINT(com.facebook.presto.common.type.TinyintType.TINYINT) VARCHAR(com.facebook.presto.common.type.VarcharType.VARCHAR) TypeUtils.writeNativeValue(com.facebook.presto.common.type.TypeUtils.writeNativeValue) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) Object2LongOpenCustomHashMap(it.unimi.dsi.fastutil.objects.Object2LongOpenCustomHashMap) DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput) AtomicLong(java.util.concurrent.atomic.AtomicLong) INTEGER(com.facebook.presto.common.type.IntegerType.INTEGER) BiConsumer(java.util.function.BiConsumer) Strategy(it.unimi.dsi.fastutil.Hash.Strategy) Optional(java.util.Optional) Type(com.facebook.presto.common.type.Type) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Aggregations

BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)1 DOUBLE (com.facebook.presto.common.type.DoubleType.DOUBLE)1 INTEGER (com.facebook.presto.common.type.IntegerType.INTEGER)1 TINYINT (com.facebook.presto.common.type.TinyintType.TINYINT)1 Type (com.facebook.presto.common.type.Type)1 TypeUtils.writeNativeValue (com.facebook.presto.common.type.TypeUtils.writeNativeValue)1 VARCHAR (com.facebook.presto.common.type.VarcharType.VARCHAR)1 DynamicSliceOutput (io.airlift.slice.DynamicSliceOutput)1 Strategy (it.unimi.dsi.fastutil.Hash.Strategy)1 Object2LongOpenCustomHashMap (it.unimi.dsi.fastutil.objects.Object2LongOpenCustomHashMap)1 Optional (java.util.Optional)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 BiConsumer (java.util.function.BiConsumer)1 Assert.assertEquals (org.testng.Assert.assertEquals)1 Test (org.testng.annotations.Test)1