greyp9 commented on code in PR #6131:
URL: https://github.com/apache/nifi/pull/6131#discussion_r921579179


##########
nifi-nar-bundles/nifi-kafka-bundle/nifi-kafka-2-6-processors/src/main/java/org/apache/nifi/processors/kafka/pubsub/PublisherLease.java:
##########
@@ -193,10 +196,24 @@ void publish(final FlowFile flowFile, final RecordSet 
recordSet, final RecordSet
                     additionalAttributes = writeResult.getAttributes();
                     writer.flush();
                 }
-
                 final byte[] messageContent = baos.toByteArray();
-                final String key = messageKeyField == null ? null : 
record.getAsString(messageKeyField);
-                final byte[] messageKey = (key == null) ? null : 
key.getBytes(StandardCharsets.UTF_8);
+
+                final byte[] messageKey;
+                if ((recordKeyWriterFactory == null) || (messageKeyField == 
null)) {
+                    messageKey = 
Optional.ofNullable(record.getAsString(messageKeyField))
+                            .map(s -> 
s.getBytes(StandardCharsets.UTF_8)).orElse(null);
+                } else {
+                    try (final ByteArrayOutputStream os = new 
ByteArrayOutputStream(1024)) {
+                        final Record keyRecord = 
Optional.ofNullable(record.getValue(messageKeyField))
+                                
.filter(Record.class::isInstance).map(Record.class::cast)
+                                .orElseThrow(() ->  new IOException("The 
property 'Record Key Writer' is defined, but the record key is not a record"));

Review Comment:
   So we should examine `record.getSchema().getDataType(messageKeyField)`, 
rather than branch based on the `recordKeyWriterFactory`, is that right?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to