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);
}
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());
}
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());
}
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);
}
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());
}
Aggregations