You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by GitBox <gi...@apache.org> on 2022/10/14 09:32:48 UTC

[GitHub] [incubator-seatunnel] TaoZex commented on a diff in pull request #3085: [Feature][Connector-V2] Support extract partition from SeaTunnelRow fields

TaoZex commented on code in PR #3085:
URL: https://github.com/apache/incubator-seatunnel/pull/3085#discussion_r995556541


##########
seatunnel-connectors-v2/connector-kafka/src/main/java/org/apache/seatunnel/connectors/seatunnel/kafka/sink/KafkaSinkWriter.java:
##########
@@ -63,7 +66,28 @@ public class KafkaSinkWriter implements SinkWriter<SeaTunnelRow, KafkaCommitInfo
     // check config
     @Override
     public void write(SeaTunnelRow element) {
-        ProducerRecord<byte[], byte[]> producerRecord = seaTunnelRowSerializer.serializeRow(element);
+        ProducerRecord<byte[], byte[]> producerRecord = null;
+        //Determine the partition of the kafka send message based on the field name
+        if (pluginConfig.hasPath(PARTITION_KEY)){
+            String keyField = pluginConfig.getString(PARTITION_KEY);
+            List<String> fields = Arrays.asList(seaTunnelRowType.getFieldNames());
+            String key;
+            if (fields.contains(keyField)) {
+                Object field = element.getField(fields.indexOf(keyField));
+                //If the field is null, send the message to the same partition
+                if (field == null) {
+                    key = "null";

Review Comment:
   It' s a good way, thanks for your advice.



-- 
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: commits-unsubscribe@seatunnel.apache.org

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