-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Add support for custom connector-provided serialization codecs (OVERVIEW) #26026
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
base: master
Are you sure you want to change the base?
Changes from all commits
63ecedb
41a80bf
e2a8dc3
d890fa6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,10 +13,12 @@ | |
| */ | ||
| package com.facebook.presto.connector; | ||
|
|
||
| import com.facebook.airlift.json.JsonCodec; | ||
| import com.facebook.airlift.log.Logger; | ||
| import com.facebook.airlift.node.NodeInfo; | ||
| import com.facebook.presto.common.CatalogSchemaName; | ||
| import com.facebook.presto.common.block.BlockEncodingSerde; | ||
| import com.facebook.presto.common.predicate.TupleDomain; | ||
| import com.facebook.presto.common.type.TypeManager; | ||
| import com.facebook.presto.connector.informationSchema.InformationSchemaConnector; | ||
| import com.facebook.presto.connector.system.DelegatingSystemTablesProvider; | ||
|
|
@@ -33,6 +35,7 @@ | |
| import com.facebook.presto.metadata.InternalNodeManager; | ||
| import com.facebook.presto.metadata.MetadataManager; | ||
| import com.facebook.presto.security.AccessControlManager; | ||
| import com.facebook.presto.spi.ColumnHandle; | ||
| import com.facebook.presto.spi.ConnectorId; | ||
| import com.facebook.presto.spi.ConnectorSystemConfig; | ||
| import com.facebook.presto.spi.PageIndexerFactory; | ||
|
|
@@ -122,6 +125,7 @@ public class ConnectorManager | |
| private final BlockEncodingSerde blockEncodingSerde; | ||
| private final ConnectorSystemConfig connectorSystemConfig; | ||
| private final ConnectorCodecManager connectorCodecManager; | ||
| private final JsonCodec<TupleDomain<ColumnHandle>> tupleDomainJsonCodec; | ||
|
|
||
| @GuardedBy("this") | ||
| private final ConcurrentMap<String, ConnectorFactory> connectorFactories = new ConcurrentHashMap<>(); | ||
|
|
@@ -156,7 +160,8 @@ public ConnectorManager( | |
| FilterStatsCalculator filterStatsCalculator, | ||
| BlockEncodingSerde blockEncodingSerde, | ||
| FeaturesConfig featuresConfig, | ||
| ConnectorCodecManager connectorCodecManager) | ||
| ConnectorCodecManager connectorCodecManager, | ||
| JsonCodec<TupleDomain<ColumnHandle>> tupleDomainCodec) | ||
| { | ||
| this.metadataManager = requireNonNull(metadataManager, "metadataManager is null"); | ||
| this.catalogManager = requireNonNull(catalogManager, "catalogManager is null"); | ||
|
|
@@ -182,6 +187,7 @@ public ConnectorManager( | |
| this.blockEncodingSerde = requireNonNull(blockEncodingSerde, "blockEncodingSerde is null"); | ||
| this.connectorSystemConfig = () -> featuresConfig.isNativeExecutionEnabled(); | ||
| this.connectorCodecManager = requireNonNull(connectorCodecManager, "connectorThriftCodecManager is null"); | ||
| this.tupleDomainJsonCodec = requireNonNull(tupleDomainCodec, "tupleDomainCodec is null"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For my own learning, why treat tupledomain as a special case and why having its serde in connector context instead of providing its serde from connector codec provider? Thanks
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TupleDomain values are serialized as blocks, which don't have a generic means to be serialized. The runtime must provide that code. |
||
| } | ||
|
|
||
| @PreDestroy | ||
|
|
@@ -386,13 +392,24 @@ private Connector createConnector(ConnectorId connectorId, ConnectorFactory fact | |
| new RowExpressionFormatter(metadataManager.getFunctionAndTypeManager())), | ||
| new ConnectorFilterStatsCalculatorService(filterStatsCalculator), | ||
| blockEncodingSerde, | ||
| connectorSystemConfig); | ||
| connectorSystemConfig, | ||
| tupleDomainJsonCodec); | ||
|
|
||
| try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(factory.getClass().getClassLoader())) { | ||
| return factory.create(connectorId.getCatalogName(), properties, context); | ||
| } | ||
| } | ||
|
|
||
| public Optional<ConnectorCodecProvider> getConnectorCodecProvider(ConnectorId connectorId) | ||
| { | ||
| requireNonNull(connectorId, "connectorId is null"); | ||
| MaterializedConnector materializedConnector = connectors.get(connectorId); | ||
| if (materializedConnector == null) { | ||
| return Optional.empty(); | ||
| } | ||
| return materializedConnector.getConnectorCodecProvider(); | ||
| } | ||
|
|
||
| private static class MaterializedConnector | ||
| { | ||
| private final ConnectorId connectorId; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.facebook.presto.connector; | ||
|
|
||
| import com.facebook.airlift.json.JsonCodec; | ||
| import com.facebook.presto.common.predicate.TupleDomain; | ||
| import com.facebook.presto.spi.ColumnHandle; | ||
| import com.facebook.presto.spi.TupleDomainSerde; | ||
|
|
||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| class JsonCodecTupleDomainSerde | ||
| implements TupleDomainSerde | ||
| { | ||
| private final JsonCodec<TupleDomain<ColumnHandle>> tupleDomainJsonCodec; | ||
|
|
||
| public JsonCodecTupleDomainSerde(JsonCodec<TupleDomain<ColumnHandle>> tupleDomainJsonCodec) | ||
| { | ||
| this.tupleDomainJsonCodec = requireNonNull(tupleDomainJsonCodec, "tupleDomainJsonCodec is null"); | ||
| } | ||
|
|
||
| @Override | ||
| public String serialize(TupleDomain<ColumnHandle> tupleDomain) | ||
| { | ||
| return tupleDomainJsonCodec.toJson(tupleDomain); | ||
| } | ||
|
|
||
| @Override | ||
| public TupleDomain<ColumnHandle> deserialize(String serialized) | ||
| { | ||
| return tupleDomainJsonCodec.fromJson(serialized); | ||
| } | ||
| } |
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.