[
https://issues.apache.org/jira/browse/BEAM-9364?focusedWorklogId=391845&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-391845
]
ASF GitHub Bot logged work on BEAM-9364:
----------------------------------------
Author: ASF GitHub Bot
Created on: 24/Feb/20 17:20
Start Date: 24/Feb/20 17:20
Worklog Time Spent: 10m
Work Description: aromanenko-dev commented on pull request #10947:
[BEAM-9364] Refactor KafkaIO to use DeserializerProviders
URL: https://github.com/apache/beam/pull/10947#discussion_r383395273
##########
File path:
sdks/java/io/kafka/src/main/java/org/apache/beam/sdk/io/kafka/LocalDeserializerProvider.java
##########
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.beam.sdk.io.kafka;
+
+import static
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkArgument;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.Map;
+import org.apache.beam.sdk.coders.CannotProvideCoderException;
+import org.apache.beam.sdk.coders.CoderRegistry;
+import org.apache.beam.sdk.coders.NullableCoder;
+import org.apache.kafka.common.serialization.Deserializer;
+
+class LocalDeserializerProvider<T> implements DeserializerProvider<T> {
+ private Class<? extends Deserializer<T>> deserializer;
+
+ private LocalDeserializerProvider(Class<? extends Deserializer<T>>
deserializer) {
+ checkArgument(deserializer != null, "You should provide a deserializer.");
+ this.deserializer = deserializer;
+ }
+
+ static <T> LocalDeserializerProvider<T> of(Class<? extends Deserializer<T>>
deserializer) {
+ return new LocalDeserializerProvider<>(deserializer);
+ }
+
+ @Override
+ public Deserializer<T> getDeserializer(Map<String, ?> configs, boolean
isKey) {
+ try {
+ Deserializer<T> deserializer =
this.deserializer.getDeclaredConstructor().newInstance();
+ deserializer.configure(configs, isKey);
+ return deserializer;
+ } catch (InstantiationException
+ | IllegalAccessException
+ | InvocationTargetException
+ | NoSuchMethodException e) {
+ throw new RuntimeException("Could not instantiate deserializers", e);
+ }
+ }
+
+ @Override
+ public NullableCoder<T> getCoder(CoderRegistry coderRegistry) {
Review comment:
Please, add a Javadoc from "old" `inferCoder()` method here.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 391845)
Time Spent: 1h 20m (was: 1h 10m)
> Refactor KafkaIO to use DeserializerProviders
> ---------------------------------------------
>
> Key: BEAM-9364
> URL: https://issues.apache.org/jira/browse/BEAM-9364
> Project: Beam
> Issue Type: Improvement
> Components: io-java-kafka
> Reporter: Ismaël Mejía
> Assignee: Ismaël Mejía
> Priority: Major
> Fix For: 2.20.0
>
> Time Spent: 1h 20m
> Remaining Estimate: 0h
>
> BEAM-7310 introduced support for Confluent Schema Registry, even if the API
> did not explicitly mention DeserializerProviders it opened the option to use
> multiple providers of Deserializers. The goal of this ticket is to refactor
> the KafkaIO API to reflect this new concept both for local Deserializer
> resolution and Confluent Schema Registry based (notice that this one becomes
> better isolated).
--
This message was sent by Atlassian Jira
(v8.3.4#803005)