You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2021/07/07 18:53:56 UTC

[GitHub] [beam] chamikaramj commented on a change in pull request #15090: [BEAM-12008] Add New Coder for KafkaIO.Read() to Deal with Null Key

chamikaramj commented on a change in pull request #15090:
URL: https://github.com/apache/beam/pull/15090#discussion_r665626264



##########
File path: sdks/java/io/kafka/src/main/java/org/apache/beam/sdk/io/kafka/KafkaIO.java
##########
@@ -838,6 +850,16 @@ public void setTimestampPolicy(String timestampPolicy) {
       }
     }
 
+    /**
+     * Sets nullKeyFlag for present of null keys
+     *
+     * <p>By default, nullKeyFlag is {@code false} and will invoke {@link KafkaRecordCoder} when
+     * nullKeyFlag is {@code true}, it invokes {@link NullableKeyKafkaRecordCoder}
+     */
+    public Read<K, V> withNullKeyFlag() {

Review comment:
       I think this change will be more usable if we can make the default coder support null values instead of asking users to explicitly decide whether keys will be nullable or not during pipeline submission.

##########
File path: sdks/java/io/kafka/src/main/java/org/apache/beam/sdk/io/kafka/NullableKeyKafkaRecordCoder.java
##########
@@ -0,0 +1,160 @@
+/*
+ * 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 java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import org.apache.beam.sdk.coders.BooleanCoder;
+import org.apache.beam.sdk.coders.ByteArrayCoder;
+import org.apache.beam.sdk.coders.Coder;
+import org.apache.beam.sdk.coders.IterableCoder;
+import org.apache.beam.sdk.coders.KvCoder;
+import org.apache.beam.sdk.coders.StringUtf8Coder;
+import org.apache.beam.sdk.coders.StructuredCoder;
+import org.apache.beam.sdk.coders.VarIntCoder;
+import org.apache.beam.sdk.coders.VarLongCoder;
+import org.apache.beam.sdk.values.KV;
+import org.apache.kafka.clients.consumer.ConsumerRecord;
+import org.apache.kafka.common.header.Header;
+import org.apache.kafka.common.header.Headers;
+
+/** {@link Coder} for {@link KafkaRecord}. */
+@SuppressWarnings({
+  "rawtypes", // TODO(https://issues.apache.org/jira/browse/BEAM-10556)
+  "nullness" // TODO(https://issues.apache.org/jira/browse/BEAM-10402)
+})
+public class NullableKeyKafkaRecordCoder<K, V> extends StructuredCoder<KafkaRecord<K, V>> {

Review comment:
       Have you considered using the standard NullableCoder ? https://github.com/apache/beam/blob/master/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/NullableCoder.java
   
   This will also make it easy to make existing external Kafka transforms support null keys as well (we have to make a NullableCoder a standard coder).
   
   This was discussed in the mailing list as well. https://lists.apache.org/thread.html/r1740cb29e46644a08b2d1755900dd6dcd5c62b937da1a01148edfcb9%40%3Cdev.beam.apache.org%3E




-- 
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.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org