Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import io.trino.spi.block.ArrayBlock;
import io.trino.spi.block.Block;
import io.trino.spi.block.DictionaryBlock;
import io.trino.spi.block.PageBuilderStatus;
import io.trino.spi.function.Description;
import io.trino.spi.function.ScalarFunction;
import io.trino.spi.function.SqlType;
Expand Down Expand Up @@ -61,7 +60,7 @@ public static Block combinations(

ArrayType arrayType = new ArrayType(elementType);
if (combinationLength > arrayLength) {
return arrayType.createBlockBuilder(new PageBuilderStatus().createBlockBuilderStatus(), 0).build();
return arrayType.createBlockBuilder(null, 0).build();
}

int combinationCount = combinationCount(arrayLength, combinationLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
import io.trino.spi.block.ArrayBlock;
import io.trino.spi.block.Block;
import io.trino.spi.block.BlockBuilder;
import io.trino.spi.block.BlockBuilderStatus;
import io.trino.spi.block.DictionaryBlock;
import io.trino.spi.block.PageBuilderStatus;
import io.trino.spi.block.RowBlock;
import io.trino.spi.block.RunLengthEncodedBlock;
import io.trino.spi.block.ValueBlock;
Expand Down Expand Up @@ -558,23 +556,21 @@ private static void testAppendSingle(TestType type, List<BlockView> inputs)

private static void assertBlockIsValid(Block actual, long sizeInBytes, Type type, List<BlockView> inputs)
{
PageBuilderStatus pageBuilderStatus = new PageBuilderStatus();
BlockBuilderStatus blockBuilderStatus = pageBuilderStatus.createBlockBuilderStatus();
Block expected = buildBlock(type, inputs, blockBuilderStatus);
Block expected = buildBlock(type, inputs, sizeInBytes);

assertBlockEquals(type, actual, expected);
assertThat(sizeInBytes).isEqualTo(pageBuilderStatus.getSizeInBytes());
}

private static Block buildBlock(Type type, List<BlockView> inputs, BlockBuilderStatus blockBuilderStatus)
private static Block buildBlock(Type type, List<BlockView> inputs, long sizeInBytes)
{
BlockBuilder blockBuilder = type.createBlockBuilder(blockBuilderStatus, 10);
BlockBuilder blockBuilder = type.createBlockBuilder(null, 10);
for (BlockView input : inputs) {
ValueBlock valueBlock = input.block().getUnderlyingValueBlock();
for (int position : input.positions()) {
blockBuilder.append(valueBlock, input.block().getUnderlyingValuePosition(position));
}
}
assertThat(sizeInBytes).isEqualTo(blockBuilder.getSizeInBytes());
return blockBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import io.trino.spi.block.ByteArrayBlock;
import io.trino.spi.block.IntArrayBlock;
import io.trino.spi.block.LongArrayBlock;
import io.trino.spi.block.PageBuilderStatus;
import io.trino.spi.block.RowBlock;
import io.trino.spi.block.SqlRow;
import io.trino.spi.type.RowType;
Expand Down Expand Up @@ -213,7 +212,7 @@ private ByteArrayBlock makeByteArrayBlock(int... elements)

private Block makeVarcharArrayBlock(String... elements)
{
BlockBuilder builder = VARCHAR.createBlockBuilder(new PageBuilderStatus().createBlockBuilderStatus(), elements.length);
BlockBuilder builder = VARCHAR.createBlockBuilder(null, elements.length);
for (String element : elements) {
if (element == null) {
builder.appendNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import io.trino.spi.block.Block;
import io.trino.spi.block.BlockBuilder;
import io.trino.spi.block.PageBuilderStatus;
import org.junit.jupiter.api.Test;

import java.util.Optional;
Expand All @@ -28,7 +27,7 @@ public class TestLikePatternType
@Test
public void testGetObject()
{
BlockBuilder blockBuilder = LIKE_PATTERN.createBlockBuilder(new PageBuilderStatus().createBlockBuilderStatus(), 10);
BlockBuilder blockBuilder = LIKE_PATTERN.createBlockBuilder(null, 10);
LIKE_PATTERN.writeObject(blockBuilder, LikePattern.compile("helloX_world", Optional.of('X')));
LIKE_PATTERN.writeObject(blockBuilder, LikePattern.compile("foo%_bar", Optional.empty()));
Block block = blockBuilder.build();
Expand Down
6 changes: 6 additions & 0 deletions core/trino-spi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,12 @@
<new>method void io.trino.spi.block.ShortArrayBlockEncoding::&lt;init&gt;(boolean)</new>
<justification>ShortArrayBlockEncoding need to accept a parameter to enable SIMD support</justification>
</item>
<item>
<ignore>true</ignore>
<code>java.method.removed</code>
<old>method void io.trino.spi.block.PageBuilderStatus::&lt;init&gt;()</old>
<justification>Method is unnecessary</justification>
</item>
</differences>
</revapi.differences>
</analysisConfiguration>
Expand Down
2 changes: 1 addition & 1 deletion core/trino-spi/src/main/java/io/trino/spi/PageBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class PageBuilder
* therefore it can resize frequently while appending new rows.
* <p>
* This constructor should only be used to get the initial PageBuilder.
* Once the PageBuilder is full use reset() or newPageBuilderLike() to create a new
* Once the PageBuilder is full use reset() to create a new
* PageBuilder instance with its size estimated based on previous data.
*/
public PageBuilder(List<? extends Type> types)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ public class PageBuilderStatus

private long currentSize;

public PageBuilderStatus()
{
this(DEFAULT_MAX_PAGE_SIZE_IN_BYTES);
}

public PageBuilderStatus(int maxPageSizeInBytes)
{
this.maxPageSizeInBytes = maxPageSizeInBytes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
*/
package io.trino.spi.block;

import com.google.common.collect.ImmutableList;
import io.trino.spi.PageBuilder;
import io.trino.spi.type.ArrayType;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
Expand All @@ -36,22 +39,23 @@ public class TestArrayBlockBuilder
@Test
public void testArrayBlockIsFull()
{
testIsFull(new PageBuilderStatus(THREE_INTS_ENTRY_SIZE * EXPECTED_ENTRY_COUNT));
testIsFull(PageBuilder.withMaxPageSize(THREE_INTS_ENTRY_SIZE * EXPECTED_ENTRY_COUNT, ImmutableList.of(new ArrayType(BIGINT))));
}

private void testIsFull(PageBuilderStatus pageBuilderStatus)
private void testIsFull(PageBuilder pageBuilder)
{
ArrayBlockBuilder blockBuilder = new ArrayBlockBuilder(BIGINT, pageBuilderStatus.createBlockBuilderStatus(), EXPECTED_ENTRY_COUNT);
assertThat(pageBuilderStatus.isEmpty()).isTrue();
while (!pageBuilderStatus.isFull()) {
ArrayBlockBuilder blockBuilder = (ArrayBlockBuilder) pageBuilder.getBlockBuilder(0);
assertThat(pageBuilder.isEmpty()).isTrue();
while (!pageBuilder.isFull()) {
pageBuilder.declarePosition();
blockBuilder.buildEntry(elementBuilder -> {
BIGINT.writeLong(elementBuilder, 12);
elementBuilder.appendNull();
BIGINT.writeLong(elementBuilder, 34);
});
}
assertThat(blockBuilder.getPositionCount()).isEqualTo(EXPECTED_ENTRY_COUNT);
assertThat(pageBuilderStatus.isFull()).isEqualTo(true);
assertThat(pageBuilder.isFull()).isEqualTo(true);
}

//TODO we should systematically test Block::getRetainedSizeInBytes()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import com.google.common.collect.ImmutableList;
import io.airlift.slice.Slices;
import io.trino.spi.PageBuilder;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
Expand All @@ -40,7 +41,7 @@ public class TestVariableWidthBlockBuilder
@Test
public void testFixedBlockIsFull()
{
testIsFull(new PageBuilderStatus(VARCHAR_ENTRY_SIZE * EXPECTED_ENTRY_COUNT));
testIsFull(PageBuilder.withMaxPageSize(VARCHAR_ENTRY_SIZE * EXPECTED_ENTRY_COUNT, ImmutableList.of(VARCHAR)));
}

@Test
Expand All @@ -61,15 +62,16 @@ public void testNewBlockBuilderLike()
assertThat(blockBuilder.getRetainedSizeInBytes()).isEqualTo(BLOCK_BUILDER_INSTANCE_SIZE + actualBytesSize + actualArraySize);
}

private void testIsFull(PageBuilderStatus pageBuilderStatus)
private void testIsFull(PageBuilder pageBuilder)
{
BlockBuilder blockBuilder = new VariableWidthBlockBuilder(pageBuilderStatus.createBlockBuilderStatus(), 32, 1024);
assertThat(pageBuilderStatus.isEmpty()).isTrue();
while (!pageBuilderStatus.isFull()) {
BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(0);
assertThat(pageBuilder.isEmpty()).isTrue();
while (!pageBuilder.isFull()) {
pageBuilder.declarePosition();
VARCHAR.writeSlice(blockBuilder, Slices.allocate(VARCHAR_VALUE_SIZE));
}
assertThat(blockBuilder.getPositionCount()).isEqualTo(EXPECTED_ENTRY_COUNT);
assertThat(pageBuilderStatus.isFull()).isEqualTo(true);
assertThat(pageBuilder.isFull()).isEqualTo(true);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import io.airlift.slice.Slices;
import io.trino.spi.block.Block;
import io.trino.spi.block.BlockBuilder;
import io.trino.spi.block.PageBuilderStatus;
import io.trino.spi.type.Type;
import io.trino.spi.type.VarcharType;
import org.apache.parquet.schema.PrimitiveType;
Expand Down Expand Up @@ -57,7 +56,7 @@ protected PrimitiveType getParquetType()
@Override
protected Block generateBlock(int size)
{
BlockBuilder blockBuilder = getTrinoType().createBlockBuilder(new PageBuilderStatus().createBlockBuilderStatus(), size);
BlockBuilder blockBuilder = getTrinoType().createBlockBuilder(null, size);
for (byte[] value : type.generateData(size, positionLength.getRange())) {
getTrinoType().writeSlice(blockBuilder, Slices.wrappedBuffer(value));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import io.trino.spi.block.Block;
import io.trino.spi.block.BlockBuilder;
import io.trino.spi.block.PageBuilderStatus;
import io.trino.spi.type.Type;
import org.apache.parquet.schema.PrimitiveType;
import org.apache.parquet.schema.Types;
Expand Down Expand Up @@ -52,7 +51,7 @@ protected PrimitiveType getParquetType()
@Override
protected Block generateBlock(int size)
{
BlockBuilder blockBuilder = getTrinoType().createBlockBuilder(new PageBuilderStatus().createBlockBuilderStatus(), size);
BlockBuilder blockBuilder = getTrinoType().createBlockBuilder(null, size);
for (long value : this.generateDataBatch(size)) {
getTrinoType().writeLong(blockBuilder, value);
}
Expand Down