-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Introduce ConnectorContextModule #27054
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce ConnectorContextModule #27054
Conversation
Reviewer's GuideThis 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 bindingsclassDiagram
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
Class diagram for updated TypeDeserializerModuleclassDiagram
class TypeDeserializerModule {
+configure(Binder binder)
}
class TypeDeserializer
class Type
class TypeManager
TypeDeserializerModule ..> TypeDeserializer : binds
TypeDeserializerModule ..> Type : binds
TypeDeserializerModule --|> Module
TypeDeserializerModule -.- TypeManager : removed dependency
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10f089c to
d27b8b6
Compare
lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/ConnectorContextModule.java
Outdated
Show resolved
Hide resolved
| modules.add(new CatalogNameModule(catalogName)); | ||
| modules.add(binder -> { | ||
| binder.bind(OpenTelemetry.class).toInstance(openTelemetry); | ||
| binder.bind(CatalogName.class).toInstance(new CatalogName(catalogName)); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
d27b8b6 to
6992cab
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice cleanup!
lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/ConnectorContextModule.java
Outdated
Show resolved
Hide resolved
plugin/trino-ai-functions/src/main/java/io/trino/plugin/ai/functions/AiConnectorFactory.java
Outdated
Show resolved
Hide resolved
6992cab to
d75b2e2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
d75b2e2 to
788eafa
Compare
|
Oops, broke Hive 🤦 It's initialized using reflection so I missed a signature change. |
Preparation for further work.
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.
788eafa to
b6d1361
Compare
|
|
|
|
Thanks! |
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
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:
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:
Tests: