Skip to content

Commit

Permalink
Use createFixedSizeBlockBuilder where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
dain committed Oct 16, 2024
1 parent 13906d8 commit c561d3e
Show file tree
Hide file tree
Showing 129 changed files with 196 additions and 196 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public Operator createOperator(DriverContext driverContext)
// create groupid blocks for every group
Block[] groupIdBlocks = new Block[groupingSetMappings.size()];
for (int i = 0; i < groupingSetMappings.size(); i++) {
BlockBuilder builder = BIGINT.createBlockBuilder(null, 1);
BlockBuilder builder = BIGINT.createFixedSizeBlockBuilder(1);
BIGINT.writeLong(builder, i);
groupIdBlocks[i] = builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static Block bigintUnion(@SqlType("array(bigint)") Block leftArray, @SqlT
int leftArrayCount = leftArray.getPositionCount();
int rightArrayCount = rightArray.getPositionCount();
LongSet set = new LongOpenHashSet(leftArrayCount + rightArrayCount);
BlockBuilder distinctElementBlockBuilder = BIGINT.createBlockBuilder(null, leftArrayCount + rightArrayCount);
BlockBuilder distinctElementBlockBuilder = BIGINT.createFixedSizeBlockBuilder(leftArrayCount + rightArrayCount);
AtomicBoolean containsNull = new AtomicBoolean(false);
appendBigintArray(leftArray, containsNull, set, distinctElementBlockBuilder);
appendBigintArray(rightArray, containsNull, set, distinctElementBlockBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static Double quantileAtValueBigint(@SqlType("qdigest(bigint)") Slice inp
public static Block valuesAtQuantilesDouble(@SqlType("qdigest(double)") Slice input, @SqlType("array(double)") Block percentilesArrayBlock)
{
QuantileDigest digest = new QuantileDigest(input);
BlockBuilder output = DOUBLE.createBlockBuilder(null, percentilesArrayBlock.getPositionCount());
BlockBuilder output = DOUBLE.createFixedSizeBlockBuilder(percentilesArrayBlock.getPositionCount());
for (int i = 0; i < percentilesArrayBlock.getPositionCount(); i++) {
DOUBLE.writeDouble(output, sortableLongToDouble(digest.getQuantile(DOUBLE.getDouble(percentilesArrayBlock, i))));
}
Expand All @@ -119,7 +119,7 @@ public static Block valuesAtQuantilesDouble(@SqlType("qdigest(double)") Slice in
public static Block valuesAtQuantilesReal(@SqlType("qdigest(real)") Slice input, @SqlType("array(double)") Block percentilesArrayBlock)
{
QuantileDigest digest = new QuantileDigest(input);
BlockBuilder output = REAL.createBlockBuilder(null, percentilesArrayBlock.getPositionCount());
BlockBuilder output = REAL.createFixedSizeBlockBuilder(percentilesArrayBlock.getPositionCount());
for (int i = 0; i < percentilesArrayBlock.getPositionCount(); i++) {
REAL.writeLong(output, floatToRawIntBits(sortableIntToFloat((int) digest.getQuantile(DOUBLE.getDouble(percentilesArrayBlock, i)))));
}
Expand All @@ -132,7 +132,7 @@ public static Block valuesAtQuantilesReal(@SqlType("qdigest(real)") Slice input,
public static Block valuesAtQuantilesBigint(@SqlType("qdigest(bigint)") Slice input, @SqlType("array(double)") Block percentilesArrayBlock)
{
QuantileDigest digest = new QuantileDigest(input);
BlockBuilder output = BIGINT.createBlockBuilder(null, percentilesArrayBlock.getPositionCount());
BlockBuilder output = BIGINT.createFixedSizeBlockBuilder(percentilesArrayBlock.getPositionCount());
for (int i = 0; i < percentilesArrayBlock.getPositionCount(); i++) {
BIGINT.writeLong(output, digest.getQuantile(DOUBLE.getDouble(percentilesArrayBlock, i)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static Block sequenceDateYearToMonth(

int length = checkMaxEntry(diffDate(MONTH, start, stop) / step + 1);

BlockBuilder blockBuilder = DATE.createBlockBuilder(null, length);
BlockBuilder blockBuilder = DATE.createFixedSizeBlockBuilder(length);

long value = 0;
for (int i = 0; i < length; ++i) {
Expand All @@ -112,7 +112,7 @@ private static Block fixedWidthSequence(long start, long stop, long step, FixedW

int length = getLength(start, stop, step);

BlockBuilder blockBuilder = type.createBlockBuilder(null, length);
BlockBuilder blockBuilder = type.createFixedSizeBlockBuilder(length);
for (long i = 0, value = start; i < length; ++i, value += step) {
type.writeLong(blockBuilder, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static Block valuesAtQuantiles(@SqlType(StandardTypes.TDIGEST) TDigest in
percentiles[i] = DOUBLE.getDouble(percentilesArrayBlock, i);
}
checkCondition(Ordering.natural().isOrdered(Doubles.asList(percentiles)), INVALID_FUNCTION_ARGUMENT, "percentiles must be sorted in increasing order");
BlockBuilder output = DOUBLE.createBlockBuilder(null, percentilesArrayBlock.getPositionCount());
BlockBuilder output = DOUBLE.createFixedSizeBlockBuilder(percentilesArrayBlock.getPositionCount());
double[] valuesAtPercentiles = input.valuesAt(percentiles);
for (Double value : valuesAtPercentiles) {
DOUBLE.writeDouble(output, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static Block sequence(

int length = checkMaxEntry((stop - start) / step + 1L);

BlockBuilder blockBuilder = SHORT_TYPE.createBlockBuilder(null, length);
BlockBuilder blockBuilder = SHORT_TYPE.createFixedSizeBlockBuilder(length);
for (long i = 0, value = start; i < length; ++i, value += step) {
SHORT_TYPE.writeLong(blockBuilder, value);
}
Expand All @@ -75,7 +75,7 @@ public static Block sequence(

int length = checkMaxEntry((stopMicros - startMicros) / step + 1L);

BlockBuilder blockBuilder = LONG_TYPE.createBlockBuilder(null, length);
BlockBuilder blockBuilder = LONG_TYPE.createFixedSizeBlockBuilder(length);
for (long i = 0, epochMicros = startMicros; i < length; ++i, epochMicros += step) {
writeLongTimestamp(blockBuilder, epochMicros, start.getPicosOfMicro());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static Block sequence(

int length = checkMaxEntry(DateDiff.diff(MONTH, start, stop) / step + 1);

BlockBuilder blockBuilder = SHORT_TYPE.createBlockBuilder(null, length);
BlockBuilder blockBuilder = SHORT_TYPE.createFixedSizeBlockBuilder(length);

long offset = 0;
for (int i = 0; i < length; ++i) {
Expand All @@ -77,7 +77,7 @@ public static Block sequence(

int length = checkMaxEntry(DateDiff.diff(MONTH, start, stop) / step + 1);

BlockBuilder blockBuilder = LONG_TYPE.createBlockBuilder(null, length);
BlockBuilder blockBuilder = LONG_TYPE.createFixedSizeBlockBuilder(length);

long offset = 0;
for (int i = 0; i < length; ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public Builder withColumnsAndTypes(@Nullable List<Column> columns, @Nullable Lis

public Builder withSingleBooleanValue(Column column, boolean value)
{
BlockBuilder blockBuilder = BOOLEAN.createBlockBuilder(null, 1);
BlockBuilder blockBuilder = BOOLEAN.createFixedSizeBlockBuilder(1);
BOOLEAN.writeBoolean(blockBuilder, value);
pages = ImmutableList.<Page>builder().add(new Page(blockBuilder.build()));
columns = Optional.of(combine(ImmutableList.of(column), ImmutableList.of(BOOLEAN)));
Expand Down
20 changes: 10 additions & 10 deletions core/trino-main/src/test/java/io/trino/block/BlockAssertions.java
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ public static ValueBlock createBooleansBlock(Boolean value, int count)

public static ValueBlock createBooleansBlock(Iterable<Boolean> values)
{
BlockBuilder builder = BOOLEAN.createBlockBuilder(null, 100);
BlockBuilder builder = BOOLEAN.createFixedSizeBlockBuilder(100);

for (Boolean value : values) {
if (value == null) {
Expand All @@ -507,7 +507,7 @@ public static ValueBlock createShortDecimalsBlock(String... values)
public static ValueBlock createShortDecimalsBlock(Iterable<String> values)
{
DecimalType shortDecimalType = DecimalType.createDecimalType(1);
BlockBuilder builder = shortDecimalType.createBlockBuilder(null, 100);
BlockBuilder builder = shortDecimalType.createFixedSizeBlockBuilder(100);

for (String value : values) {
if (value == null) {
Expand All @@ -531,7 +531,7 @@ public static ValueBlock createLongDecimalsBlock(String... values)
public static ValueBlock createLongDecimalsBlock(Iterable<String> values)
{
DecimalType longDecimalType = DecimalType.createDecimalType(MAX_SHORT_PRECISION + 1);
BlockBuilder builder = longDecimalType.createBlockBuilder(null, 100);
BlockBuilder builder = longDecimalType.createFixedSizeBlockBuilder(100);

for (String value : values) {
if (value == null) {
Expand All @@ -553,7 +553,7 @@ public static ValueBlock createLongTimestampBlock(TimestampType type, LongTimest

public static ValueBlock createLongTimestampBlock(TimestampType type, Iterable<LongTimestamp> values)
{
BlockBuilder builder = type.createBlockBuilder(null, 100);
BlockBuilder builder = type.createFixedSizeBlockBuilder(100);

for (LongTimestamp value : values) {
if (value == null) {
Expand Down Expand Up @@ -665,7 +665,7 @@ public static ValueBlock createEmptyLongsBlock()
// This method makes it easy to create blocks without having to add an L to every value
public static ValueBlock createLongsBlock(int... values)
{
BlockBuilder builder = BIGINT.createBlockBuilder(null, 100);
BlockBuilder builder = BIGINT.createFixedSizeBlockBuilder(100);

for (int value : values) {
BIGINT.writeLong(builder, value);
Expand Down Expand Up @@ -717,7 +717,7 @@ public static Block createLongDictionaryBlock(int start, int length, int diction
{
checkArgument(dictionarySize > 0, "dictionarySize must be greater than 0");

BlockBuilder builder = BIGINT.createBlockBuilder(null, dictionarySize);
BlockBuilder builder = BIGINT.createFixedSizeBlockBuilder(dictionarySize);
for (int i = start; i < start + dictionarySize; i++) {
BIGINT.writeLong(builder, i);
}
Expand Down Expand Up @@ -775,7 +775,7 @@ public static ValueBlock createBlockOfReals(Float... values)

public static ValueBlock createBlockOfReals(Iterable<Float> values)
{
BlockBuilder builder = REAL.createBlockBuilder(null, 100);
BlockBuilder builder = REAL.createFixedSizeBlockBuilder(100);
for (Float value : values) {
if (value == null) {
builder.appendNull();
Expand Down Expand Up @@ -895,7 +895,7 @@ public static ValueBlock createColorRepeatBlock(int value, int length)

public static ValueBlock createColorSequenceBlock(int start, int end)
{
BlockBuilder builder = COLOR.createBlockBuilder(null, end - start);
BlockBuilder builder = COLOR.createFixedSizeBlockBuilder(end - start);
for (int i = start; i < end; ++i) {
COLOR.writeLong(builder, i);
}
Expand All @@ -904,14 +904,14 @@ public static ValueBlock createColorSequenceBlock(int start, int end)

public static Block createRepeatedValuesBlock(double value, int positionCount)
{
BlockBuilder blockBuilder = DOUBLE.createBlockBuilder(null, 1);
BlockBuilder blockBuilder = DOUBLE.createFixedSizeBlockBuilder(1);
DOUBLE.writeDouble(blockBuilder, value);
return RunLengthEncodedBlock.create(blockBuilder.build(), positionCount);
}

public static Block createRepeatedValuesBlock(long value, int positionCount)
{
BlockBuilder blockBuilder = BIGINT.createBlockBuilder(null, 1);
BlockBuilder blockBuilder = BIGINT.createFixedSizeBlockBuilder(1);
BIGINT.writeLong(blockBuilder, value);
return RunLengthEncodedBlock.create(blockBuilder.build(), positionCount);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class TestBlockBuilder
@Test
public void testMultipleValuesWithNull()
{
BlockBuilder blockBuilder = BIGINT.createBlockBuilder(null, 10);
BlockBuilder blockBuilder = BIGINT.createFixedSizeBlockBuilder(10);
blockBuilder.appendNull();
BIGINT.writeLong(blockBuilder, 42);
blockBuilder.appendNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ public TableFunctionProcessorState process(List<Optional<Page>> input)
}

Page page = getOnlyElement(input).orElseThrow();
BlockBuilder builder = BIGINT.createBlockBuilder(null, page.getPositionCount());
BlockBuilder builder = BIGINT.createFixedSizeBlockBuilder(page.getPositionCount());
for (long index = processedPositions; index < processedPositions + page.getPositionCount(); index++) {
// TODO check for long overflow
BIGINT.writeLong(builder, index);
Expand Down Expand Up @@ -786,7 +786,7 @@ public TableFunctionProcessorState process(List<Optional<Page>> input)

Page page = getOnlyElement(input).orElseThrow();
if (processedRounds == 0) {
BlockBuilder builder = BIGINT.createBlockBuilder(null, page.getPositionCount());
BlockBuilder builder = BIGINT.createFixedSizeBlockBuilder(page.getPositionCount());
for (long index = processedPositions; index < processedPositions + page.getPositionCount(); index++) {
// TODO check for long overflow
BIGINT.writeLong(builder, index);
Expand Down Expand Up @@ -859,7 +859,7 @@ public TableFunctionDataProcessor getDataProcessor(ConnectorSession session, Con
private static class EmptyOutputProcessor
implements TableFunctionDataProcessor
{
private static final Page EMPTY_PAGE = new Page(BOOLEAN.createBlockBuilder(null, 0).build());
private static final Page EMPTY_PAGE = new Page(BOOLEAN.createFixedSizeBlockBuilder(0).build());

@Override
public TableFunctionProcessorState process(List<Optional<Page>> input)
Expand Down Expand Up @@ -919,8 +919,8 @@ private static class EmptyOutputWithPassThroughProcessor
{
// one proper channel, and one pass-through index channel
private static final Page EMPTY_PAGE = new Page(
BOOLEAN.createBlockBuilder(null, 0).build(),
BIGINT.createBlockBuilder(null, 0).build());
BOOLEAN.createFixedSizeBlockBuilder(0).build(),
BIGINT.createFixedSizeBlockBuilder(0).build());

@Override
public TableFunctionProcessorState process(List<Optional<Page>> input)
Expand Down Expand Up @@ -985,7 +985,7 @@ public static class TestInputsFunctionProcessorProvider
@Override
public TableFunctionDataProcessor getDataProcessor(ConnectorSession session, ConnectorTableFunctionHandle handle)
{
BlockBuilder resultBuilder = BOOLEAN.createBlockBuilder(null, 1);
BlockBuilder resultBuilder = BOOLEAN.createFixedSizeBlockBuilder(1);
BOOLEAN.writeBoolean(resultBuilder, true);

Page result = new Page(resultBuilder.build());
Expand Down Expand Up @@ -1069,15 +1069,15 @@ public TableFunctionProcessorState process(List<Optional<Page>> input)
finished = true;

// proper column input_1_present
BlockBuilder input1Builder = BOOLEAN.createBlockBuilder(null, 1);
BlockBuilder input1Builder = BOOLEAN.createFixedSizeBlockBuilder(1);
BOOLEAN.writeBoolean(input1Builder, input1Present);

// proper column input_2_present
BlockBuilder input2Builder = BOOLEAN.createBlockBuilder(null, 1);
BlockBuilder input2Builder = BOOLEAN.createFixedSizeBlockBuilder(1);
BOOLEAN.writeBoolean(input2Builder, input2Present);

// pass-through index for input_1
BlockBuilder input1PassThroughBuilder = BIGINT.createBlockBuilder(null, 1);
BlockBuilder input1PassThroughBuilder = BIGINT.createFixedSizeBlockBuilder(1);
if (input1Present) {
BIGINT.writeLong(input1PassThroughBuilder, input1EndIndex - 1);
}
Expand All @@ -1086,7 +1086,7 @@ public TableFunctionProcessorState process(List<Optional<Page>> input)
}

// pass-through index for input_2
BlockBuilder input2PassThroughBuilder = BIGINT.createBlockBuilder(null, 1);
BlockBuilder input2PassThroughBuilder = BIGINT.createFixedSizeBlockBuilder(1);
if (input2Present) {
BIGINT.writeLong(input2PassThroughBuilder, input2EndIndex - 1);
}
Expand Down Expand Up @@ -1163,7 +1163,7 @@ public TableFunctionProcessorState process(List<Optional<Page>> input)
}
if (input == null) {
finished = true;
BlockBuilder builder = BOOLEAN.createBlockBuilder(null, 1);
BlockBuilder builder = BOOLEAN.createFixedSizeBlockBuilder(1);
BOOLEAN.writeBoolean(builder, processorGotInput);
return produced(new Page(builder.build()));
}
Expand Down Expand Up @@ -1209,7 +1209,7 @@ public static class TestSingleInputFunctionProcessorProvider
@Override
public TableFunctionDataProcessor getDataProcessor(ConnectorSession session, ConnectorTableFunctionHandle handle)
{
BlockBuilder builder = BOOLEAN.createBlockBuilder(null, 1);
BlockBuilder builder = BOOLEAN.createFixedSizeBlockBuilder(1);
BOOLEAN.writeBoolean(builder, true);
Page result = new Page(builder.build());

Expand Down Expand Up @@ -1422,7 +1422,7 @@ public TableFunctionSplitProcessor getSplitProcessor(ConnectorSession session, C
public static class EmptySourceFunctionProcessor
implements TableFunctionSplitProcessor
{
private static final Page EMPTY_PAGE = new Page(BOOLEAN.createBlockBuilder(null, 0).build());
private static final Page EMPTY_PAGE = new Page(BOOLEAN.createFixedSizeBlockBuilder(0).build());

private boolean produced;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ else if (DOUBLE.equals(type)) {
@Test
public void testBigintSerializedSize()
{
BlockBuilder builder = BIGINT.createBlockBuilder(null, 5);
BlockBuilder builder = BIGINT.createFixedSizeBlockBuilder(5);

// empty page
Page page = new Page(builder.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ public void setup()
.add(BIGINT)
.build());
for (int i = 0; i < TOTAL_PAGES; i++) {
BlockBuilder bigintBlockBuilder = BIGINT.createBlockBuilder(null, ROWS_PER_PAGE);
BlockBuilder bigintBlockBuilder = BIGINT.createFixedSizeBlockBuilder(ROWS_PER_PAGE);
BlockBuilder varcharBlockBuilder = VARCHAR.createBlockBuilder(null, ROWS_PER_PAGE);
BlockBuilder doubleBlockBuilder = DOUBLE.createBlockBuilder(null, ROWS_PER_PAGE);
BlockBuilder doubleBlockBuilder = DOUBLE.createFixedSizeBlockBuilder(ROWS_PER_PAGE);

for (int j = 0; j < groupsPerPage; j++) {
long groupKey = i * groupsPerPage + j;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ private RowPagesBuilder buildPages(int currentPartitionIdentifier, List<Type> ty
RowPagesBuilder rowPagesBuilder = RowPagesBuilder.rowPagesBuilder(false, ImmutableList.of(0), typesArray);

for (int i = 0; i < TOTAL_PAGES; i++) {
BlockBuilder firstColumnBlockBuilder = BIGINT.createBlockBuilder(null, ROWS_PER_PAGE);
BlockBuilder secondColumnBlockBuilder = BIGINT.createBlockBuilder(null, ROWS_PER_PAGE);
BlockBuilder firstColumnBlockBuilder = BIGINT.createFixedSizeBlockBuilder(ROWS_PER_PAGE);
BlockBuilder secondColumnBlockBuilder = BIGINT.createFixedSizeBlockBuilder(ROWS_PER_PAGE);
int currentNumberOfRowsInPartition = 0;
int numberOfPartitionsInCurrentGroup = 0;
int currentGroupIdentifier = groupIdentifier++;
Expand Down
Loading

0 comments on commit c561d3e

Please sign in to comment.