Search in sources :

Example 1 with VariableWidthBlockBuilder

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

the class TestLongArrayBlock 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) LongArrayBlockBuilder(io.trino.spi.block.LongArrayBlockBuilder) BlockBuilder(io.trino.spi.block.BlockBuilder) VariableWidthBlockBuilder(io.trino.spi.block.VariableWidthBlockBuilder) Test(org.testng.annotations.Test)

Example 2 with VariableWidthBlockBuilder

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

the class TestListaggAggregationFunction method getOutputStateOnlyValue.

private static String getOutputStateOnlyValue(SingleListaggAggregationState state, int maxOutputLengthInBytes) {
    BlockBuilder out = new VariableWidthBlockBuilder(null, 32, 256);
    ListaggAggregationFunction.outputState(state, out, maxOutputLengthInBytes);
    return (String) BlockAssertions.getOnlyValue(VARCHAR, out);
}
Also used : VariableWidthBlockBuilder(io.trino.spi.block.VariableWidthBlockBuilder) VariableWidthBlockBuilder(io.trino.spi.block.VariableWidthBlockBuilder) BlockBuilder(io.trino.spi.block.BlockBuilder)

Example 3 with VariableWidthBlockBuilder

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

the class TestRawEncoderMapping method testMapping.

@Test
public void testMapping() {
    EncoderColumnHandle col1 = new KafkaColumnHandle("test1", BIGINT, "0", "LONG", null, false, false, false);
    EncoderColumnHandle col2 = new KafkaColumnHandle("test2", createUnboundedVarcharType(), "8:14", "BYTE", null, false, false, false);
    EncoderColumnHandle col3 = new KafkaColumnHandle("test3", BIGINT, "14", "LONG", null, false, false, false);
    EncoderColumnHandle col4 = new KafkaColumnHandle("test4", createUnboundedVarcharType(), "22:28", "BYTE", null, false, false, false);
    EncoderColumnHandle col5 = new KafkaColumnHandle("test5", BIGINT, "28", "LONG", null, false, false, false);
    EncoderColumnHandle col6 = new KafkaColumnHandle("test6", createVarcharType(6), "36:42", "BYTE", null, false, false, false);
    EncoderColumnHandle col7 = new KafkaColumnHandle("test7", createVarcharType(6), "42:48", "BYTE", null, false, false, false);
    RowEncoder rowEncoder = ENCODER_FACTORY.create(TestingConnectorSession.SESSION, Optional.empty(), ImmutableList.of(col1, col2, col3, col4, col5, col6, col7));
    ByteBuffer buf = ByteBuffer.allocate(48);
    // 0-8
    buf.putLong(123456789);
    // 8-14
    buf.put("abcdef".getBytes(StandardCharsets.UTF_8));
    // 14-22
    buf.putLong(123456789);
    // 22-28
    buf.put("abcdef".getBytes(StandardCharsets.UTF_8));
    // 28-36
    buf.putLong(123456789);
    // 36-42
    buf.put("abcdef".getBytes(StandardCharsets.UTF_8));
    // 42-48
    buf.put("abcdef".getBytes(StandardCharsets.UTF_8));
    Block longArrayBlock = new LongArrayBlockBuilder(null, 1).writeLong(123456789).closeEntry().build();
    Block varArrayBlock = new VariableWidthBlockBuilder(null, 1, 6).writeBytes(Slices.wrappedBuffer("abcdef".getBytes(StandardCharsets.UTF_8)), 0, 6).closeEntry().build();
    rowEncoder.appendColumnValue(longArrayBlock, 0);
    rowEncoder.appendColumnValue(varArrayBlock, 0);
    rowEncoder.appendColumnValue(longArrayBlock, 0);
    rowEncoder.appendColumnValue(varArrayBlock, 0);
    rowEncoder.appendColumnValue(longArrayBlock, 0);
    rowEncoder.appendColumnValue(varArrayBlock, 0);
    rowEncoder.appendColumnValue(varArrayBlock, 0);
    assertEquals(buf.array(), rowEncoder.toByteArray());
}
Also used : VariableWidthBlockBuilder(io.trino.spi.block.VariableWidthBlockBuilder) EncoderColumnHandle(io.trino.plugin.kafka.encoder.EncoderColumnHandle) KafkaColumnHandle(io.trino.plugin.kafka.KafkaColumnHandle) Block(io.trino.spi.block.Block) RowEncoder(io.trino.plugin.kafka.encoder.RowEncoder) LongArrayBlockBuilder(io.trino.spi.block.LongArrayBlockBuilder) ByteBuffer(java.nio.ByteBuffer) Test(org.testng.annotations.Test)

Example 4 with VariableWidthBlockBuilder

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

the class TestRunLengthEncodedBlock method createSingleValueBlock.

private static Block createSingleValueBlock(Slice expectedValue) {
    BlockBuilder blockBuilder = new VariableWidthBlockBuilder(null, 1, expectedValue.length());
    blockBuilder.writeBytes(expectedValue, 0, expectedValue.length()).closeEntry();
    return blockBuilder.build();
}
Also used : VariableWidthBlockBuilder(io.trino.spi.block.VariableWidthBlockBuilder) ShortArrayBlockBuilder(io.trino.spi.block.ShortArrayBlockBuilder) IntArrayBlockBuilder(io.trino.spi.block.IntArrayBlockBuilder) VariableWidthBlockBuilder(io.trino.spi.block.VariableWidthBlockBuilder) ByteArrayBlockBuilder(io.trino.spi.block.ByteArrayBlockBuilder) LongArrayBlockBuilder(io.trino.spi.block.LongArrayBlockBuilder) BlockBuilder(io.trino.spi.block.BlockBuilder)

Example 5 with VariableWidthBlockBuilder

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

the class TestVariableWidthBlock method testLazyBlockBuilderInitialization.

@Test
public void testLazyBlockBuilderInitialization() {
    Slice[] expectedValues = createExpectedValues(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) 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