Search in sources :

Example 1 with IntArrayBlockBuilder

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);
}
Also used : IntArrayBlockBuilder(io.trino.spi.block.IntArrayBlockBuilder) Block(io.trino.spi.block.Block) IntArrayBlockBuilder(io.trino.spi.block.IntArrayBlockBuilder) BlockBuilder(io.trino.spi.block.BlockBuilder) Test(org.testng.annotations.Test)

Example 2 with IntArrayBlockBuilder

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));
}
Also used : IntArrayBlockBuilder(io.trino.spi.block.IntArrayBlockBuilder) BlockPositionHashCode(io.trino.type.BlockTypeOperators.BlockPositionHashCode) IntArrayBlockBuilder(io.trino.spi.block.IntArrayBlockBuilder) BlockBuilder(io.trino.spi.block.BlockBuilder) Test(org.testng.annotations.Test)

Example 3 with IntArrayBlockBuilder

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);
}
Also used : IntArrayBlockBuilder(io.trino.spi.block.IntArrayBlockBuilder) Test(org.testng.annotations.Test)

Example 4 with IntArrayBlockBuilder

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());
}
Also used : IntArrayBlockBuilder(io.trino.spi.block.IntArrayBlockBuilder) Slice(io.airlift.slice.Slice) IntArrayBlockBuilder(io.trino.spi.block.IntArrayBlockBuilder) BlockBuilder(io.trino.spi.block.BlockBuilder) Test(org.testng.annotations.Test)

Example 5 with IntArrayBlockBuilder

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;
}
Also used : IntArrayBlockBuilder(io.trino.spi.block.IntArrayBlockBuilder)

Aggregations

IntArrayBlockBuilder (io.trino.spi.block.IntArrayBlockBuilder)6 Test (org.testng.annotations.Test)4 BlockBuilder (io.trino.spi.block.BlockBuilder)3 Slice (io.airlift.slice.Slice)1 Page (io.trino.spi.Page)1 Block (io.trino.spi.block.Block)1 BlockPositionHashCode (io.trino.type.BlockTypeOperators.BlockPositionHashCode)1