Skip to content

refactor: Prepare TableFunction SPI for C++#27365

Merged
aditi-pandit merged 1 commit intoprestodb:masterfrom
aditi-pandit:tvf_update_api
Mar 19, 2026
Merged

refactor: Prepare TableFunction SPI for C++#27365
aditi-pandit merged 1 commit intoprestodb:masterfrom
aditi-pandit:tvf_update_api

Conversation

@aditi-pandit
Copy link
Copy Markdown
Contributor

@aditi-pandit aditi-pandit commented Mar 18, 2026

Add the JSON annotations to prepare the TableFunction SPI classes for C++ serialization

== NO RELEASE NOTE ==

Summary by Sourcery

Annotate table function SPI types for JSON serialization and split table return type variants into dedicated classes to support polymorphic handling, updating callers and validation logic accordingly.

Enhancements:

  • Introduce dedicated GenericTable, OnlyPassThrough, and DescribedTable return type specification classes and replace legacy nested implementations.
  • Add Jackson type and property annotations to table function SPI classes and argument specifications to enable JSON-based transport and C++ interoperability.
  • Extend ConnectorTableFunctionHandle with a default getSplits method and expose additional table argument metadata for external consumers.

Tests:

  • Update table function tests and Arrow Flight connector tests to use the new return type specification classes.

@prestodb-ci prestodb-ci added the from:IBM PR from IBM label Mar 18, 2026
@prestodb-ci prestodb-ci requested review from a team, ScrapCodes and infvg and removed request for a team March 18, 2026 06:55
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Mar 18, 2026

Reviewer's Guide

Refactors the table function SPI to use Jackson-serializable polymorphic types for arguments and return type specifications, introduces dedicated return type specification classes, and wires them through analyzers, registry, and tests in preparation for C++ interop.

Class diagram for new ReturnTypeSpecification hierarchy

classDiagram
    class ReturnTypeSpecification {
        <<abstract>>
        +String getReturnType()
    }

    class GenericTableReturnTypeSpecification {
        +GenericTableReturnTypeSpecification GENERIC_TABLE
        -String returnType
        +GenericTableReturnTypeSpecification(String returnType)
        +boolean equals(Object o)
        +int hashCode()
        +String getReturnType()
    }

    class DescribedTableReturnTypeSpecification {
        -Descriptor descriptor
        -String returnType
        +DescribedTableReturnTypeSpecification(Descriptor descriptor)
        +Descriptor getDescriptor()
        +String getReturnType()
    }

    class OnlyPassThroughReturnTypeSpecification {
        +OnlyPassThroughReturnTypeSpecification ONLY_PASS_THROUGH
        -String returnType
        +OnlyPassThroughReturnTypeSpecification(String returnType)
        +String getReturnType()
    }

    ReturnTypeSpecification <|-- GenericTableReturnTypeSpecification
    ReturnTypeSpecification <|-- DescribedTableReturnTypeSpecification
    ReturnTypeSpecification <|-- OnlyPassThroughReturnTypeSpecification
Loading

Class diagram for ArgumentSpecification polymorphic hierarchy

classDiagram
    class ArgumentSpecification {
        <<abstract>>
        -String name
        -boolean required
        -Object defaultValue
        +ArgumentSpecification(String name, boolean required, Object defaultValue)
        +String getName()
        +boolean isRequired()
        +Object getDefaultValue()
    }

    class TableArgumentSpecification {
        -boolean rowSemantics
        -boolean pruneWhenEmpty
        -boolean passThroughColumns
        +TableArgumentSpecification(String name, boolean rowSemantics, boolean pruneWhenEmpty, boolean passThroughColumns)
        +boolean isRowSemantics()
        +boolean isPruneWhenEmpty()
        +boolean isPassThroughColumns()
    }

    class DescriptorArgumentSpecification {
        +DescriptorArgumentSpecification(String name, boolean required, Descriptor defaultValue)
    }

    class ScalarArgumentSpecification {
        -Type type
        +ScalarArgumentSpecification(String name, Type type, boolean required, Object defaultValue)
        +Type getType()
    }

    ArgumentSpecification <|-- TableArgumentSpecification
    ArgumentSpecification <|-- DescriptorArgumentSpecification
    ArgumentSpecification <|-- ScalarArgumentSpecification
Loading

Class diagram for table function SPI integration points

classDiagram
    class AbstractConnectorTableFunction {
        -String schema
        -String name
        -List~ArgumentSpecification~ arguments
        -ReturnTypeSpecification returnTypeSpecification
        +AbstractConnectorTableFunction(String schema, String name, List~ArgumentSpecification~ arguments, ReturnTypeSpecification returnTypeSpecification)
        +String getSchema()
        +String getName()
        +List~ArgumentSpecification~ getArguments()
        +ReturnTypeSpecification getReturnTypeSpecification()
    }

    class ConnectorTableFunctionHandle {
        <<interface>>
        +ConnectorSplitSource getSplits(ConnectorTransactionHandle transaction, ConnectorSession session, NodeManager nodeManager, Object functionAndTypeManager)
    }

    class TableArgument {
        -RowType rowType
        +RowType getRowType()
        +List~RowType.Field~ getFields()
        +List~String~ getPartitionBy()
    }

    class DescriptorArgument {
        -Optional~Descriptor~ descriptor
        +DescriptorArgument(Optional~Descriptor~ descriptor)
        +Optional~Descriptor~ getDescriptor()
    }

    AbstractConnectorTableFunction --> ReturnTypeSpecification
    AbstractConnectorTableFunction --> ArgumentSpecification
    TableArgument --> RowType
    DescriptorArgument --> Descriptor
    ConnectorTableFunctionHandle ..> ConnectorSplitSource
    ConnectorTableFunctionHandle ..> ConnectorTransactionHandle
    ConnectorTableFunctionHandle ..> ConnectorSession
    ConnectorTableFunctionHandle ..> NodeManager
Loading

File-Level Changes

Change Details Files
Make ReturnTypeSpecification and ArgumentSpecification hierarchies Jackson-polymorphic and introduce concrete return type spec classes.
  • Annotate ReturnTypeSpecification and ArgumentSpecification with JsonTypeInfo/JsonSubTypes to enable polymorphic JSON serialization.
  • Replace former inner subclasses of ReturnTypeSpecification (GenericTable, OnlyPassThrough, DescribedTable) with top-level GenericTableReturnTypeSpecification, OnlyPassThroughReturnTypeSpecification, and DescribedTableReturnTypeSpecification classes.
  • Change ReturnTypeSpecification.getReturnType() to abstract and implement it in each concrete subclass using string enums like GENERIC, PASSTRHOUGH, DESCRIBED.
presto-spi/src/main/java/com/facebook/presto/spi/function/table/ReturnTypeSpecification.java
presto-spi/src/main/java/com/facebook/presto/spi/function/table/ArgumentSpecification.java
presto-spi/src/main/java/com/facebook/presto/spi/function/table/GenericTableReturnTypeSpecification.java
presto-spi/src/main/java/com/facebook/presto/spi/function/table/DescribedTableReturnTypeSpecification.java
presto-spi/src/main/java/com/facebook/presto/spi/function/table/OnlyPassThroughReturnTypeSpecification.java
Make SPI argument specification implementations JSON-serializable and expose needed properties.
  • Add JsonCreator/JsonProperty annotations to TableArgumentSpecification, DescriptorArgumentSpecification, and ScalarArgumentSpecification constructors.
  • Expose getters with JsonProperty where necessary (e.g., type and table argument flags).
  • Relax DescriptorArgument constructor visibility from private to public for deserialization.
presto-spi/src/main/java/com/facebook/presto/spi/function/table/TableArgumentSpecification.java
presto-spi/src/main/java/com/facebook/presto/spi/function/table/DescriptorArgumentSpecification.java
presto-spi/src/main/java/com/facebook/presto/spi/function/table/ScalarArgumentSpecification.java
presto-spi/src/main/java/com/facebook/presto/spi/function/table/DescriptorArgument.java
Make AbstractConnectorTableFunction and related SPI types JSON-friendly and adjust downstream usage.
  • Annotate AbstractConnectorTableFunction constructor and getters with JsonCreator/JsonProperty for full object round-trip via JSON.
  • Expose TableArgument row type fields via a new getFields() method annotated with JsonProperty.
  • Extend ConnectorTableFunctionHandle with a default getSplits(...) method throwing UnsupportedOperationException for future extension.
presto-spi/src/main/java/com/facebook/presto/spi/function/table/AbstractConnectorTableFunction.java
presto-spi/src/main/java/com/facebook/presto/spi/function/table/TableArgument.java
presto-spi/src/main/java/com/facebook/presto/spi/function/table/ConnectorTableFunctionHandle.java
Update engine code and tests to use the new return type specification classes and string tags.
  • Replace usages of ReturnTypeSpecification.GenericTable / OnlyPassThrough / DescribedTable with the new *ReturnTypeSpecification classes across engine code and tests.
  • Adjust StatementAnalyzer and TableFunctionRegistry to work with the new returnType string values and concrete DescribedTableReturnTypeSpecification.
  • Update Arrow Flight and operator table functions (e.g., Sequence) and testing table functions to construct the new return type spec classes.
presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java
presto-main-base/src/main/java/com/facebook/presto/metadata/TableFunctionRegistry.java
presto-main-base/src/test/java/com/facebook/presto/connector/tvf/TestingTableFunctions.java
presto-base-arrow-flight/src/test/java/com/facebook/plugin/arrow/testingConnector/tvf/QueryFunctionProvider.java
presto-main-base/src/main/java/com/facebook/presto/operator/table/Sequence.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

Copy link
Copy Markdown
Contributor

@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 - I've found 2 issues, and left some high level feedback:

  • The OnlyPassThroughReturnTypeSpecification return type string is spelled "PASSTRHOUGH" and the switch in StatementAnalyzer.verifyProperColumnsDescriptor matches that value; if this is intended to be "PASSTHROUGH" (or to match any existing external contract), both the constant and switch cases should be corrected consistently.
  • The GenericTableReturnTypeSpecification and OnlyPassThroughReturnTypeSpecification @JsonCreator constructors accept a returnType parameter that is ignored; consider either removing the parameter or validating it to avoid confusing, unused input in the serialized form.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `OnlyPassThroughReturnTypeSpecification` return type string is spelled `"PASSTRHOUGH"` and the switch in `StatementAnalyzer.verifyProperColumnsDescriptor` matches that value; if this is intended to be `"PASSTHROUGH"` (or to match any existing external contract), both the constant and switch cases should be corrected consistently.
- The `GenericTableReturnTypeSpecification` and `OnlyPassThroughReturnTypeSpecification` `@JsonCreator` constructors accept a `returnType` parameter that is ignored; consider either removing the parameter or validating it to avoid confusing, unused input in the serialized form.

## Individual Comments

### Comment 1
<location path="presto-spi/src/main/java/com/facebook/presto/spi/function/table/OnlyPassThroughReturnTypeSpecification.java" line_range="26" />
<code_context>
+        extends ReturnTypeSpecification
+{
+    public static final OnlyPassThroughReturnTypeSpecification ONLY_PASS_THROUGH = new OnlyPassThroughReturnTypeSpecification("");
+    private static final String returnType = "PASSTRHOUGH";
+
+    @JsonCreator
</code_context>
<issue_to_address>
**issue (typo):** The return type string value appears to contain a typo that may leak into external behavior or configuration.

The constant value is spelled `"PASSTRHOUGH"` but should likely be `"PASSTHROUGH"`. Because this value is used in `StatementAnalyzer.verifyProperColumnsDescriptor` and may be persisted/serialized, the misspelling becomes part of the external contract. Unless this is intentional for backward compatibility, please correct it now to avoid locking in the typo.

```suggestion
    private static final String returnType = "PASSTHROUGH";
```
</issue_to_address>

### Comment 2
<location path="presto-spi/src/main/java/com/facebook/presto/spi/function/table/GenericTableReturnTypeSpecification.java" line_range="31-32" />
<code_context>
     private final ReturnTypeSpecification returnTypeSpecification;

-    public AbstractConnectorTableFunction(String schema, String name, List<ArgumentSpecification> arguments, ReturnTypeSpecification returnTypeSpecification)
+    @JsonCreator
+    public AbstractConnectorTableFunction(
+            @JsonProperty("schema") String schema,
</code_context>
<issue_to_address>
**suggestion (bug_risk):** The JsonCreator argument is unused, which is confusing for both readers and Jackson configuration.

The constructor declares `@JsonProperty("returnType") String returnType` but ignores it and instead uses a static constant. This means the JSON field is effectively a no-op. If you want a singleton, consider a no-arg `@JsonCreator`; otherwise, either remove the parameter or validate that its value matches the expected constant to avoid surprising deserialization behavior.
</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.

@aditi-pandit aditi-pandit force-pushed the tvf_update_api branch 2 times, most recently from 1342620 to b92e6ba Compare March 18, 2026 07:06
@aditi-pandit aditi-pandit merged commit 5022f6b into prestodb:master Mar 19, 2026
113 of 116 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

from:IBM PR from IBM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants