Skip to content

Conversation

raunaqmorarka
Copy link
Member

@raunaqmorarka raunaqmorarka commented Oct 12, 2025

Description

Migrates all existing usages to io.trino.spi.block.BlockBuilder#append
This simplifies the Type API and the building of blocks from block positions

Additional context and related issues

Release notes

( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
(x) Release notes are required, with the following suggested text:

## SPI
* Deprecate `io.trino.spi.type.Type#appendTo`. ({issue}`26922`)

Summary by Sourcery

Deprecate the SPI Type.appendTo method and migrate all call sites to BlockBuilder.append for streamlined block construction.

Enhancements:

  • Mark Type.appendTo as deprecated in the SPI and remove its concrete implementations from built-in types
  • Replace all calls to Type.appendTo with BlockBuilder.append using block.getUnderlyingValueBlock() and getUnderlyingValuePosition()
  • Simplify code paths and generated methods by removing appendTo parameters and unused type fields in PagesHashStrategy, PagesIndex, spatial index, and related classes
  • Update benchmarks and test code to use the new append approach and adjust BenchmarkMapCopy annotations

@cla-bot cla-bot bot added the cla-signed label Oct 12, 2025
Copy link

sourcery-ai bot commented Oct 12, 2025

Reviewer's Guide

This PR deprecates the Type#appendTo SPI, removing all custom appendTo implementations and migrating every appendTo call site to use BlockBuilder#append with underlying blocks and positions. Code generation routines (JoinCompiler, MergeSortedPages) and various core operators have been updated to drop type parameters and stored Type fields where possible, streamlining the API and reducing boilerplate.

Class diagram for deprecated Type#appendTo and migration to BlockBuilder#append

classDiagram
    class Type {
        +writeObject(BlockBuilder blockBuilder, Object value)
        +getObject(Block block, int position)
        +getObjectValue(Block block, int position)
        +getFlatFixedSize()
        +getTypeOperatorDeclaration(TypeOperators typeOperators)
        +createBlockBuilder(BlockBuilderStatus blockBuilderStatus, int expectedEntries)
        +createBlockBuilder(BlockBuilderStatus blockBuilderStatus, int expectedEntries, int expectedBytesPerEntry)
        +@Deprecated appendTo(Block block, int position, BlockBuilder blockBuilder)
    }
    class BlockBuilder {
        +append(ValueBlock valueBlock, int valuePosition)
        +appendNull()
        +build()
    }
    Type <|-- AbstractIntType
    Type <|-- AbstractLongType
    Type <|-- AbstractVariableWidthType
    Type <|-- ArrayType
    Type <|-- MapType
    Type <|-- RowType
    Type <|-- DoubleType
    Type <|-- LongDecimalType
    Type <|-- LongTimeWithTimeZoneType
    Type <|-- LongTimestampType
    Type <|-- LongTimestampWithTimeZoneType
    Type <|-- UuidType
    Type <|-- BooleanType
    Type <|-- ShortDecimalType
    Type <|-- ShortTimeWithTimeZoneType
    Type <|-- ShortTimestampType
    Type <|-- ShortTimestampWithTimeZoneType
    Type <|-- SmallintType
    Type <|-- TinyintType
    Type <|-- IpAddressType
    Type <|-- FunctionType
    Type <|-- UnknownType
    AbstractIntType --|> Type
    AbstractLongType --|> Type
    AbstractVariableWidthType --|> Type
    ArrayType --|> Type
    MapType --|> Type
    RowType --|> Type
    DoubleType --|> Type
    LongDecimalType --|> Type
    LongTimeWithTimeZoneType --|> Type
    LongTimestampType --|> Type
    LongTimestampWithTimeZoneType --|> Type
    UuidType --|> Type
    BooleanType --|> Type
    ShortDecimalType --|> Type
    ShortTimeWithTimeZoneType --|> Type
    ShortTimestampType --|> Type
    ShortTimestampWithTimeZoneType --|> Type
    SmallintType --|> Type
    TinyintType --|> Type
    IpAddressType --|> Type
    FunctionType --|> Type
    UnknownType --|> Type
    BlockBuilder <.. Type : uses
    BlockBuilder o-- ValueBlock
Loading

Class diagram for BlockSet constructor and usage changes

classDiagram
    class BlockSet {
        -BlockPositionIsIdentical elementIdenticalOperator
        -BlockPositionHashCode elementHashCodeOperator
        -int maximumSize
        +BlockSet(BlockPositionIsIdentical elementIdenticalOperator, BlockPositionHashCode elementHashCodeOperator, int maximumSize)
        +add(ValueBlock valueBlock, int valuePosition)
        +contains(ValueBlock valueBlock, int valuePosition)
        +getAllWithSizeLimit(BlockBuilder blockBuilder, String functionName, DataSize maxFunctionMemory)
    }
    BlockSet o-- BlockPositionIsIdentical
    BlockSet o-- BlockPositionHashCode
    BlockSet o-- BlockBuilder
    BlockSet o-- ValueBlock
Loading

File-Level Changes

Change Details Files
Deprecate appendTo in the SPI and remove concrete overrides
  • Mark appendTo in Type interface as @deprecated with a default throwing implementation
  • Remove custom appendTo implementations from all built-in Type classes
core/trino-spi/src/main/java/io/trino/spi/type/Type.java
core/trino-spi/src/main/java/io/trino/spi/type/AbstractVariableWidthType.java
core/trino-spi/src/main/java/io/trino/spi/type/MapType.java
core/trino-spi/src/main/java/io/trino/spi/type/ArrayType.java
core/trino-spi/src/main/java/io/trino/spi/type/RowType.java
core/trino-spi/src/main/java/io/trino/spi/type/DoubleType.java
core/trino-spi/src/main/java/io/trino/spi/type/LongDecimalType.java
core/trino-spi/src/main/java/io/trino/spi/type/LongTimeWithTimeZoneType.java
core/trino-spi/src/main/java/io/trino/spi/type/LongTimestampType.java
core/trino-spi/src/main/java/io/trino/spi/type/LongTimestampWithTimeZoneType.java
core/trino-spi/src/main/java/io/trino/spi/type/UuidType.java
core/trino-spi/src/main/java/io/trino/spi/type/AbstractIntType.java
core/trino-spi/src/main/java/io/trino/spi/type/AbstractLongType.java
core/trino-spi/src/main/java/io/trino/spi/type/BooleanType.java
core/trino-spi/src/main/java/io/trino/spi/type/ShortDecimalType.java
core/trino-spi/src/main/java/io/trino/spi/type/ShortTimeWithTimeZoneType.java
core/trino-spi/src/main/java/io/trino/spi/type/ShortTimestampType.java
core/trino-spi/src/main/java/io/trino/spi/type/ShortTimestampWithTimeZoneType.java
core/trino-spi/src/main/java/io/trino/spi/type/SmallintType.java
core/trino-spi/src/main/java/io/trino/spi/type/TinyintType.java
core/trino-spi/src/main/java/io/trino/spi/type/FunctionType.java
core/trino-main/src/main/java/io/trino/type/UnknownType.java
Migrate all appendTo invocations to BlockBuilder.append
  • Replace every type.appendTo(block, pos, builder) with builder.append(block.getUnderlyingValueBlock(), block.getUnderlyingValuePosition(pos))
  • Introduce local ValueBlock variables where beneficial
  • Update tests and benchmarks accordingly
core/trino-main/src/**/*.java
core/trino-spi/src/**/*.java
core/trino-main/src/test/**/*.java
plugin/**/src/**/*.java
lib/**/src/**/*.java
Simplify generated append methods in codegen
  • Change JoinCompiler.generateAppendToMethod signature to drop Type and CallSiteBinder args
  • Update MergeSortedPages.PageWithPosition.appendTo to drop outputTypes argument
core/trino-main/src/main/java/io/trino/sql/gen/JoinCompiler.java
core/trino-main/src/main/java/io/trino/util/MergeSortedPages.java
Remove stored Type fields and constructor parameters
  • Drop Type arrays/fields from hashing, indexing, and operator classes
  • Adjust constructors and appendTo loops to work without Type references
core/trino-main/src/main/java/io/trino/operator/scalar/SimplePagesHashStrategy.java
core/trino-main/src/main/java/io/trino/operator/PagesIndex.java
core/trino-main/src/main/java/io/trino/operator/PagesRTreeIndex.java
core/trino-main/src/main/java/io/trino/operator/PagesSpatialIndexSupplier.java
core/trino-main/src/main/java/io/trino/operator/SpatialJoinOperator.java
core/trino-main/src/main/java/io/trino/operator/index/StreamingIndexedData.java
core/trino-main/src/main/java/io/trino/spiller/GenericPartitioningSpiller.java
core/trino-main/src/main/java/io/trino/operator/window/pattern/ProjectingPagesWindowIndex.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions github-actions bot added hive Hive connector kafka Kafka connector labels Oct 12, 2025
@raunaqmorarka raunaqmorarka requested review from dain and martint October 12, 2025 18:42
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `core/trino-main/src/main/java/io/trino/operator/scalar/ArraySortFunction.java:82-83` </location>
<code_context>
         return arrayValueBuilder.build(arrayLength, elementBuilder -> {
+            ValueBlock valueBlock = block.getUnderlyingValueBlock();
             for (int i = 0; i < arrayLength; i++) {
-                type.appendTo(block, positions.getInt(i), elementBuilder);
+                elementBuilder.append(valueBlock, block.getUnderlyingValuePosition(positions.getInt(i)));
             }
         });
</code_context>

<issue_to_address>
**issue:** Switch from type.appendTo to BlockBuilder.append may affect null handling.

Please verify that BlockBuilder.append correctly handles null values in arrays, as its behavior may differ from type.appendTo.
</issue_to_address>

### Comment 2
<location> `core/trino-main/src/main/java/io/trino/operator/PagesIndex.java:319-321` </location>
<code_context>
             // append the row
             pageBuilder.declarePosition();
             for (int channel = 0; channel < channels.length; channel++) {
-                Type type = types.get(channel);
                 Block block = channels[channel].get(blockIndex);
-                type.appendTo(block, blockPosition, pageBuilder.getBlockBuilder(channel));
+                pageBuilder.getBlockBuilder(channel).append(block.getUnderlyingValueBlock(), block.getUnderlyingValuePosition(blockPosition));
             }
</code_context>

<issue_to_address>
**issue (bug_risk):** Removal of type usage in appendTo may impact type-specific logic.

Verify that BlockBuilder.append correctly supports all relevant types, including custom and complex ones, since type-specific handling in appendTo is no longer applied.
</issue_to_address>

### Comment 3
<location> `core/trino-main/src/main/java/io/trino/operator/scalar/ZipFunction.java:120` </location>
<code_context>
                     fieldBuilders.get(fieldIndex).appendNull();
                 }
                 else {
-                    types.get(fieldIndex).appendTo(arrays[fieldIndex], outputPosition, fieldBuilders.get(fieldIndex));
+                    Block block = arrays[fieldIndex];
+                    fieldBuilders.get(fieldIndex).append(block.getUnderlyingValueBlock(), block.getUnderlyingValuePosition(outputPosition));
                 }
</code_context>

<issue_to_address>
**issue:** Type-specific appendTo replaced with BlockBuilder.append; check for semantic changes.

Please verify that handling of nulls and type conversions remains consistent, and that the output row structure is correct for all types after this change.
</issue_to_address>

### Comment 4
<location> `core/trino-main/src/main/java/io/trino/operator/scalar/ArrayFlattenFunction.java:79-81` </location>
<code_context>
                 Block subArray = (Block) arrayType.getObject(array, i);
+                ValueBlock subArrayValueBlock = subArray.getUnderlyingValueBlock();
                 for (int j = 0; j < subArray.getPositionCount(); j++) {
-                    type.appendTo(subArray, j, builder);
+                    builder.append(subArrayValueBlock, subArray.getUnderlyingValuePosition(j));
                 }
             }
</code_context>

<issue_to_address>
**issue (bug_risk):** Direct append may not handle type-specific conversions.

Verify that builder.append performs necessary conversions and validations for all element types, including nested and custom arrays.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@wendigo
Copy link
Contributor

wendigo commented Oct 12, 2025

@raunaqmorarka I suppose that it doesn't affect performance

@raunaqmorarka raunaqmorarka force-pushed the raunaq/remove-type-append branch from 95907da to 61e1984 Compare October 12, 2025 18:45
@raunaqmorarka
Copy link
Member Author

@raunaqmorarka I suppose that it doesn't affect performance

I don't expect it to make a significant difference

@starburstdata-automation
Copy link

starburstdata-automation commented Oct 12, 2025

Started benchmark workflow for this PR with test type = iceberg/sf1000_parquet_part.

Building Trino finished with status: success
Benchmark finished with status: success
Comparing results to the static baseline values, follow above workflow link for more details/logs.
Status message: NO Regression found.
Benchmark Comparison to the closest run from Master: Report

@starburstdata-automation
Copy link

starburstdata-automation commented Oct 12, 2025

Started benchmark workflow for this PR with test type = iceberg/sf1000_parquet_unpart.

Building Trino finished with status: success
Benchmark finished with status: success
Comparing results to the static baseline values, follow above workflow link for more details/logs.
Status message: NO Regression found.
Benchmark Comparison to the closest run from Master: Report

Replaced all usages with io.trino.spi.block.BlockBuilder#append
This simplifies block building operations by removing the need
to go through the Type interface
Removes all the unused implementations and marks
the API for removal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed hive Hive connector kafka Kafka connector

Development

Successfully merging this pull request may close these issues.

3 participants