Skip to content

Conversation

@ksobolew
Copy link
Contributor

@ksobolew ksobolew commented Oct 22, 2025

Description

This reduces code duplication - a lot - and also frees the plugin writers from guessing which objects are actually needed by the plugin. The answer this module gives is: all of them, don't worry about it.

Additional context and related issues

+201 −342

Seemingly not much, but there are also quality-of-development improvements in that (I believe).

Release notes

(x) 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.
( ) Release notes are required, with the following suggested text:

## Section
* Fix some things. ({issue}`issuenumber`)

Summary by Sourcery

Consolidate connector context bindings into a new ConnectorContextModule, simplify TypeDeserializerModule, and refactor connector factories and tests to use the new module, reducing code duplication.

Enhancements:

  • Add ConnectorContextModule to centralize binding of ConnectorContext and CatalogName in Guice modules
  • Refactor connector factories to replace repetitive manual binder lambdas with ConnectorContextModule.from
  • Simplify TypeDeserializerModule by removing its TypeManager dependency

Tests:

  • Update connector tests to use ConnectorContextModule for context and catalog name bindings

@cla-bot cla-bot bot added the cla-signed label Oct 22, 2025
@sourcery-ai
Copy link

sourcery-ai bot commented Oct 22, 2025

Reviewer's Guide

This PR introduces a new ConnectorContextModule that centralizes Guice bindings for all ConnectorContext dependencies (OpenTelemetry, Tracer, Node, NodeManager, NodeVersion, VersionEmbedder, TypeManager, MetadataProvider, PageSorter, PageIndexerFactory, and CatalogName), refactors all connector factories and tests to use it, simplifies the TypeDeserializerModule to remove its TypeManager dependency, and removes redundant binding boilerplate across plugins.

Class diagram for ConnectorContextModule and related bindings

classDiagram
    class ConnectorContextModule {
        +from(String catalogName, ConnectorContext context) Module
        +from(ConnectorContext context) Module
    }
    class CatalogNameModule
    class ConnectorContext {
        +getOpenTelemetry() OpenTelemetry
        +getTracer() Tracer
        +getCurrentNode() Node
        +getNodeManager() NodeManager
        +getVersionEmbedder() VersionEmbedder
        +getTypeManager() TypeManager
        +getMetadataProvider() MetadataProvider
        +getPageSorter() PageSorter
        +getPageIndexerFactory() PageIndexerFactory
    }
    class OpenTelemetry
    class Tracer
    class Node
    class NodeVersion
    class NodeManager
    class VersionEmbedder
    class TypeManager
    class MetadataProvider
    class PageSorter
    class PageIndexerFactory
    class CatalogName

    ConnectorContextModule ..> CatalogNameModule : uses
    ConnectorContextModule ..> ConnectorContext : uses
    ConnectorContextModule ..> CatalogName : binds
    ConnectorContextModule ..> OpenTelemetry : binds
    ConnectorContextModule ..> Tracer : binds
    ConnectorContextModule ..> Node : binds
    ConnectorContextModule ..> NodeVersion : binds
    ConnectorContextModule ..> NodeManager : binds
    ConnectorContextModule ..> VersionEmbedder : binds
    ConnectorContextModule ..> TypeManager : binds
    ConnectorContextModule ..> MetadataProvider : binds
    ConnectorContextModule ..> PageSorter : binds
    ConnectorContextModule ..> PageIndexerFactory : binds
    ConnectorContext -- Node : returns
    ConnectorContext -- NodeManager : returns
    ConnectorContext -- VersionEmbedder : returns
    ConnectorContext -- TypeManager : returns
    ConnectorContext -- MetadataProvider : returns
    ConnectorContext -- PageSorter : returns
    ConnectorContext -- PageIndexerFactory : returns
    ConnectorContext -- OpenTelemetry : returns
    ConnectorContext -- Tracer : returns
Loading

Class diagram for updated TypeDeserializerModule

classDiagram
    class TypeDeserializerModule {
        +configure(Binder binder)
    }
    class TypeDeserializer
    class Type
    class TypeManager
    TypeDeserializerModule ..> TypeDeserializer : binds
    TypeDeserializerModule ..> Type : binds
    TypeDeserializerModule --|> Module
    TypeDeserializerModule -.- TypeManager : removed dependency
Loading

File-Level Changes

Change Details Files
Introduce ConnectorContextModule to encapsulate common context bindings
  • Create ConnectorContextModule with static from(context) and from(catalogName, context) methods
  • Encapsulate binding of OpenTelemetry, Tracer, Node, NodeManager, NodeVersion, VersionEmbedder, TypeManager, MetadataProvider, PageSorter, PageIndexerFactory
  • Integrate CatalogNameModule when catalogName is provided
lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/ConnectorContextModule.java
Refactor connector factories to use ConnectorContextModule
  • Replace manual binder lambdas in each ConnectorFactory with ConnectorContextModule.from calls
  • Remove duplicated binder.bind(...) lines for context objects in all factories
  • Unify catalogName binding via CatalogNameModule
plugin/*/src/main/java/io/trino/plugin/*/*ConnectorFactory.java
Simplify TypeDeserializerModule to no-arg
  • Remove TypeManager field and constructor
  • Convert TypeDeserializerModule to no-arg Module
  • Update all factories to instantiate new TypeDeserializerModule() without parameters
lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/TypeDeserializerModule.java
plugin/*/src/main/java/io/trino/plugin/*/ConnectorFactory.java
Update tests to leverage ConnectorContextModule
  • Replace manual context bindings in test setup with ConnectorContextModule.from
  • Reduce boilerplate in TestDeltaLakeMetadata and other connector tests
plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/TestDeltaLakeMetadata.java
plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/TestDeltaLakeGlueMetastore.java
Clean up CatalogName binding in HdfsFileSystemManager
  • Add CatalogNameModule to HdfsFileSystemManager modules
  • Remove redundant binder.bind(CatalogName) call
lib/trino-hdfs/src/main/java/io/trino/filesystem/hdfs/HdfsFileSystemManager.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 hudi Hudi connector iceberg Iceberg connector delta-lake Delta Lake connector hive Hive connector bigquery BigQuery connector mongodb MongoDB connector cassandra Cassandra connector elasticsearch Elasticsearch connector google-sheets Google Sheets connector kafka Kafka connector loki Loki connector opensearch OpenSearch connector pinot Pinot connector prometheus Prometheus connector redis Redis connector redshift Redshift connector lakehouse labels Oct 22, 2025
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!


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.

@ksobolew ksobolew force-pushed the kudi/connector-context-module branch from 10f089c to d27b8b6 Compare October 22, 2025 17:41
modules.add(new CatalogNameModule(catalogName));
modules.add(binder -> {
binder.bind(OpenTelemetry.class).toInstance(openTelemetry);
binder.bind(CatalogName.class).toInstance(new CatalogName(catalogName));
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems not relates to the change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not strictly related, yes. This is a follow-up cleanup.

This is something that can be genuinely useful for all plugins.
It is a common pattern to bind object extracted from the
`ConnectorContext` in a surrounding module. This binding is added to
others like that, where applicable. In at least one plugin it was
already bound (which would be an error in Guice if it wasn't able to
deduplicate simple bindings like that).
Seems like this can be a quite common requirement.
@ksobolew ksobolew force-pushed the kudi/connector-context-module branch from d27b8b6 to 6992cab Compare October 23, 2025 14:27
@ksobolew ksobolew requested a review from wendigo October 23, 2025 14:28
Copy link
Member

@kokosing kokosing left a comment

Choose a reason for hiding this comment

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

Nice cleanup!

@ksobolew ksobolew force-pushed the kudi/connector-context-module branch from 6992cab to d75b2e2 Compare October 23, 2025 14:42
Copy link
Contributor

@ssheikin ssheikin left a comment

Choose a reason for hiding this comment

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

❤️

@ksobolew ksobolew force-pushed the kudi/connector-context-module branch from d75b2e2 to 788eafa Compare October 23, 2025 15:54
@ksobolew
Copy link
Contributor Author

Oops, broke Hive 🤦 It's initialized using reflection so I missed a signature change.

This reduces code duplication - a lot - and also frees the plugin
writers from guessing which objects are actually needed by the plugin.
The answer this module gives is: all of them, don't worry about it.

The biggest issue is with testing, because while the
`TestingConnectorContext` does implement all methods (with stubbed
implementations), there are some tests that may want to customize that.
Because `TestingConnectorContext` is `final`, it's not easily
extensible, so there's a temptation to implement `ConnectorContext`
directly. With this change this will no longer work (well) because such
a test will have to implement all of the methods instead of just one or
two.
There are some places where this binding is used in a different context
than as a way to pass the catalog name to the connector plugin; in those
places the module is inlined, so that we can remove it entirely.
@ksobolew ksobolew force-pushed the kudi/connector-context-module branch from 788eafa to b6d1361 Compare October 23, 2025 17:18
@ksobolew
Copy link
Contributor Author

TestDirectTrinoClient.testDirectTrinoClientLongQuery seems to be slightly flaky...

@ksobolew
Copy link
Contributor Author

TestDirectTrinoClient.testDirectTrinoClientLongQuery seems to be slightly flaky...

#27082

@kokosing kokosing merged commit cad659d into trinodb:master Oct 24, 2025
201 of 203 checks passed
@kokosing
Copy link
Member

Thanks!

@github-actions github-actions bot added this to the 478 milestone Oct 24, 2025
@ksobolew ksobolew deleted the kudi/connector-context-module branch October 24, 2025 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bigquery BigQuery connector cassandra Cassandra connector cla-signed delta-lake Delta Lake connector elasticsearch Elasticsearch connector google-sheets Google Sheets connector hive Hive connector hudi Hudi connector iceberg Iceberg connector kafka Kafka connector lakehouse loki Loki connector mongodb MongoDB connector opensearch OpenSearch connector pinot Pinot connector prometheus Prometheus connector redis Redis connector redshift Redshift connector

Development

Successfully merging this pull request may close these issues.

5 participants