use of io.trino.spi.block.IntArrayBlockBuilder in project trino by trinodb.
the class TestBlockBigArray method testRetainedSizeWithOverlappingBlocks.
@Test
public void testRetainedSizeWithOverlappingBlocks() {
int entries = 123;
BlockBuilder blockBuilder = new IntArrayBlockBuilder(null, entries);
for (int i = 0; i < entries; i++) {
blockBuilder.writeInt(i);
}
Block block = blockBuilder.build();
// Verify we do not over count
int arraySize = 456;
int blocks = 7890;
BlockBigArray blockBigArray = new BlockBigArray();
blockBigArray.ensureCapacity(arraySize);
for (int i = 0; i < blocks; i++) {
blockBigArray.set(i % arraySize, block.getRegion(0, entries));
}
ReferenceCountMap referenceCountMap = new ReferenceCountMap();
referenceCountMap.incrementAndGet(block);
long expectedSize = ClassLayout.parseClass(BlockBigArray.class).instanceSize() + referenceCountMap.sizeOf() + (new ObjectBigArray<>()).sizeOf() + block.getRetainedSizeInBytes() + (arraySize - 1) * ClassLayout.parseClass(block.getClass()).instanceSize();
assertEquals(blockBigArray.sizeOf(), expectedSize);
}
use of io.trino.spi.block.IntArrayBlockBuilder in project trino by trinodb.
the class TestRealType method testNaNHash.
@Test
public void testNaNHash() {
BlockBuilder blockBuilder = new IntArrayBlockBuilder(null, 4);
blockBuilder.writeInt(floatToIntBits(Float.NaN));
blockBuilder.writeInt(floatToRawIntBits(Float.NaN));
// the following two are the integer values of a float NaN
blockBuilder.writeInt(-0x400000);
blockBuilder.writeInt(0x7fc00000);
BlockPositionHashCode hashCodeOperator = blockTypeOperators.getHashCodeOperator(REAL);
assertEquals(hashCodeOperator.hashCode(blockBuilder, 0), hashCodeOperator.hashCode(blockBuilder, 1));
assertEquals(hashCodeOperator.hashCode(blockBuilder, 0), hashCodeOperator.hashCode(blockBuilder, 2));
assertEquals(hashCodeOperator.hashCode(blockBuilder, 0), hashCodeOperator.hashCode(blockBuilder, 3));
}
use of io.trino.spi.block.IntArrayBlockBuilder in project trino by trinodb.
the class TestRunLengthEncodedBlock method testBuildingFromIntArrayBlockBuilder.
@Test
public void testBuildingFromIntArrayBlockBuilder() {
IntArrayBlockBuilder blockBuilder = new IntArrayBlockBuilder(null, 100);
populateNullValues(blockBuilder, 100);
assertEquals(blockBuilder.build().getEncodingName(), RunLengthBlockEncoding.NAME);
}
use of io.trino.spi.block.IntArrayBlockBuilder in project trino by trinodb.
the class TestIntArrayBlock method testLazyBlockBuilderInitialization.
@Test
public void testLazyBlockBuilderInitialization() {
Slice[] expectedValues = createTestValue(100);
BlockBuilder emptyBlockBuilder = new IntArrayBlockBuilder(null, 0);
BlockBuilder blockBuilder = new IntArrayBlockBuilder(null, expectedValues.length);
assertEquals(blockBuilder.getSizeInBytes(), emptyBlockBuilder.getSizeInBytes());
assertEquals(blockBuilder.getRetainedSizeInBytes(), emptyBlockBuilder.getRetainedSizeInBytes());
writeValues(expectedValues, blockBuilder);
assertTrue(blockBuilder.getSizeInBytes() > emptyBlockBuilder.getSizeInBytes());
assertTrue(blockBuilder.getRetainedSizeInBytes() > emptyBlockBuilder.getRetainedSizeInBytes());
blockBuilder = blockBuilder.newBlockBuilderLike(null);
assertEquals(blockBuilder.getSizeInBytes(), emptyBlockBuilder.getSizeInBytes());
assertEquals(blockBuilder.getRetainedSizeInBytes(), emptyBlockBuilder.getRetainedSizeInBytes());
}
use of io.trino.spi.block.IntArrayBlockBuilder in project trino by trinodb.
the class TestIntArrayBlock method createBlockBuilderWithValues.
private static BlockBuilder createBlockBuilderWithValues(Slice[] expectedValues) {
IntArrayBlockBuilder blockBuilder = new IntArrayBlockBuilder(null, expectedValues.length);
writeValues(expectedValues, blockBuilder);
return blockBuilder;
}
Aggregations