Search in sources :

Example 6 with VariableWidthBlockBuilder

use of io.trino.spi.block.VariableWidthBlockBuilder in project trino by trinodb.

the class TestVariableWidthBlock method testGetSizeInBytes.

@Test
public void testGetSizeInBytes() {
    int numEntries = 1000;
    VarcharType unboundedVarcharType = createUnboundedVarcharType();
    VariableWidthBlockBuilder blockBuilder = new VariableWidthBlockBuilder(null, numEntries, 20 * numEntries);
    for (int i = 0; i < numEntries; i++) {
        unboundedVarcharType.writeString(blockBuilder, String.valueOf(ThreadLocalRandom.current().nextLong()));
    }
    Block block = blockBuilder.build();
    List<Block> splitQuarter = splitBlock(block, 4);
    long sizeInBytes = block.getSizeInBytes();
    long quarter1size = splitQuarter.get(0).getSizeInBytes();
    long quarter2size = splitQuarter.get(1).getSizeInBytes();
    long quarter3size = splitQuarter.get(2).getSizeInBytes();
    long quarter4size = splitQuarter.get(3).getSizeInBytes();
    double expectedQuarterSizeMin = sizeInBytes * 0.2;
    double expectedQuarterSizeMax = sizeInBytes * 0.3;
    assertTrue(quarter1size > expectedQuarterSizeMin && quarter1size < expectedQuarterSizeMax, format("quarter1size is %s, should be between %s and %s", quarter1size, expectedQuarterSizeMin, expectedQuarterSizeMax));
    assertTrue(quarter2size > expectedQuarterSizeMin && quarter2size < expectedQuarterSizeMax, format("quarter2size is %s, should be between %s and %s", quarter2size, expectedQuarterSizeMin, expectedQuarterSizeMax));
    assertTrue(quarter3size > expectedQuarterSizeMin && quarter3size < expectedQuarterSizeMax, format("quarter3size is %s, should be between %s and %s", quarter3size, expectedQuarterSizeMin, expectedQuarterSizeMax));
    assertTrue(quarter4size > expectedQuarterSizeMin && quarter4size < expectedQuarterSizeMax, format("quarter4size is %s, should be between %s and %s", quarter4size, expectedQuarterSizeMin, expectedQuarterSizeMax));
    assertEquals(quarter1size + quarter2size + quarter3size + quarter4size, sizeInBytes);
}
Also used : VariableWidthBlockBuilder(io.trino.spi.block.VariableWidthBlockBuilder) VarcharType.createUnboundedVarcharType(io.trino.spi.type.VarcharType.createUnboundedVarcharType) VarcharType(io.trino.spi.type.VarcharType) VariableWidthBlock(io.trino.spi.block.VariableWidthBlock) Block(io.trino.spi.block.Block) Test(org.testng.annotations.Test)

Example 7 with VariableWidthBlockBuilder

use of io.trino.spi.block.VariableWidthBlockBuilder in project trino by trinodb.

the class TestInt128ArrayBlock method testLazyBlockBuilderInitialization.

@Test
public void testLazyBlockBuilderInitialization() {
    Slice[] expectedValues = createTestValue(100);
    BlockBuilder emptyBlockBuilder = new VariableWidthBlockBuilder(null, 0, 0);
    BlockBuilder blockBuilder = new VariableWidthBlockBuilder(null, expectedValues.length, 32 * 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 : VariableWidthBlockBuilder(io.trino.spi.block.VariableWidthBlockBuilder) Slice(io.airlift.slice.Slice) BlockBuilder(io.trino.spi.block.BlockBuilder) Int128ArrayBlockBuilder(io.trino.spi.block.Int128ArrayBlockBuilder) VariableWidthBlockBuilder(io.trino.spi.block.VariableWidthBlockBuilder) Test(org.testng.annotations.Test)

Example 8 with VariableWidthBlockBuilder

use of io.trino.spi.block.VariableWidthBlockBuilder in project trino by trinodb.

the class TestInt96ArrayBlock method testLazyBlockBuilderInitialization.

@Test
public void testLazyBlockBuilderInitialization() {
    Slice[] expectedValues = createTestValue(100);
    BlockBuilder emptyBlockBuilder = new VariableWidthBlockBuilder(null, 0, 0);
    BlockBuilder blockBuilder = new VariableWidthBlockBuilder(null, expectedValues.length, 32 * 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 : VariableWidthBlockBuilder(io.trino.spi.block.VariableWidthBlockBuilder) Slice(io.airlift.slice.Slice) Int96ArrayBlockBuilder(io.trino.spi.block.Int96ArrayBlockBuilder) BlockBuilder(io.trino.spi.block.BlockBuilder) VariableWidthBlockBuilder(io.trino.spi.block.VariableWidthBlockBuilder) Test(org.testng.annotations.Test)

Example 9 with VariableWidthBlockBuilder

use of io.trino.spi.block.VariableWidthBlockBuilder in project trino by trinodb.

the class TestListaggAggregationFunction method testInputEmptyState.

@Test
public void testInputEmptyState() {
    SingleListaggAggregationState state = new SingleListaggAggregationState(VARCHAR);
    String s = "value1";
    Block value = createStringsBlock(s);
    Slice separator = utf8Slice(",");
    Slice overflowFiller = utf8Slice("...");
    ListaggAggregationFunction.input(VARCHAR, state, value, separator, false, overflowFiller, true, 0);
    assertFalse(state.isEmpty());
    assertEquals(state.getSeparator(), separator);
    assertFalse(state.isOverflowError());
    assertEquals(state.getOverflowFiller(), overflowFiller);
    assertTrue(state.showOverflowEntryCount());
    BlockBuilder out = new VariableWidthBlockBuilder(null, 16, 128);
    state.forEach((block, position) -> {
        block.writeBytesTo(position, 0, block.getSliceLength(position), out);
        return true;
    });
    out.closeEntry();
    String result = (String) BlockAssertions.getOnlyValue(VARCHAR, out);
    assertEquals(result, s);
}
Also used : VariableWidthBlockBuilder(io.trino.spi.block.VariableWidthBlockBuilder) Slice(io.airlift.slice.Slice) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) Block(io.trino.spi.block.Block) BlockAssertions.createStringsBlock(io.trino.block.BlockAssertions.createStringsBlock) VariableWidthBlockBuilder(io.trino.spi.block.VariableWidthBlockBuilder) BlockBuilder(io.trino.spi.block.BlockBuilder) Test(org.testng.annotations.Test)

Example 10 with VariableWidthBlockBuilder

use of io.trino.spi.block.VariableWidthBlockBuilder in project trino by trinodb.

the class TestListaggAggregationFunction method testOutputStateWithOverflowError.

@Test
public void testOutputStateWithOverflowError() {
    SingleListaggAggregationState state = createListaggAggregationState("", true, "...", false, "overflowvalue1", "overflowvalue2");
    BlockBuilder out = new VariableWidthBlockBuilder(null, 16, 128);
    assertThatThrownBy(() -> ListaggAggregationFunction.outputState(state, out, 20)).isInstanceOf(TrinoException.class).matches(throwable -> ((TrinoException) throwable).getErrorCode() == EXCEEDED_FUNCTION_MEMORY_LIMIT.toErrorCode());
}
Also used : VariableWidthBlockBuilder(io.trino.spi.block.VariableWidthBlockBuilder) TrinoException(io.trino.spi.TrinoException) VariableWidthBlockBuilder(io.trino.spi.block.VariableWidthBlockBuilder) BlockBuilder(io.trino.spi.block.BlockBuilder) Test(org.testng.annotations.Test)

Aggregations

VariableWidthBlockBuilder (io.trino.spi.block.VariableWidthBlockBuilder)10 BlockBuilder (io.trino.spi.block.BlockBuilder)8 Test (org.testng.annotations.Test)8 Slice (io.airlift.slice.Slice)5 Block (io.trino.spi.block.Block)3 LongArrayBlockBuilder (io.trino.spi.block.LongArrayBlockBuilder)3 Slices.utf8Slice (io.airlift.slice.Slices.utf8Slice)1 BlockAssertions.createStringsBlock (io.trino.block.BlockAssertions.createStringsBlock)1 KafkaColumnHandle (io.trino.plugin.kafka.KafkaColumnHandle)1 EncoderColumnHandle (io.trino.plugin.kafka.encoder.EncoderColumnHandle)1 RowEncoder (io.trino.plugin.kafka.encoder.RowEncoder)1 TrinoException (io.trino.spi.TrinoException)1 ByteArrayBlockBuilder (io.trino.spi.block.ByteArrayBlockBuilder)1 Int128ArrayBlockBuilder (io.trino.spi.block.Int128ArrayBlockBuilder)1 Int96ArrayBlockBuilder (io.trino.spi.block.Int96ArrayBlockBuilder)1 IntArrayBlockBuilder (io.trino.spi.block.IntArrayBlockBuilder)1 ShortArrayBlockBuilder (io.trino.spi.block.ShortArrayBlockBuilder)1 VariableWidthBlock (io.trino.spi.block.VariableWidthBlock)1 VarcharType (io.trino.spi.type.VarcharType)1 VarcharType.createUnboundedVarcharType (io.trino.spi.type.VarcharType.createUnboundedVarcharType)1