You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by GitBox <gi...@apache.org> on 2021/06/01 16:21:44 UTC

[GitHub] [drill] vvysotskyi commented on a change in pull request #2242: DRILL-7940: Fix Kafka key with avro schema can not displayed correctly

vvysotskyi commented on a change in pull request #2242:
URL: https://github.com/apache/drill/pull/2242#discussion_r643251324



##########
File path: contrib/storage-kafka/src/main/java/org/apache/drill/exec/store/kafka/decoders/AvroMessageReader.java
##########
@@ -51,6 +52,7 @@
   private KafkaAvroDeserializer deserializer;
   private ColumnConverter converter;
   private ResultSetLoader loader;
+  private Boolean keyConvert;

Review comment:
       ```suggestion
     private boolean deserializeKey;
   ```

##########
File path: contrib/storage-kafka/src/main/java/org/apache/drill/exec/store/kafka/decoders/AvroMessageReader.java
##########
@@ -85,10 +90,19 @@ public void readMessage(ConsumerRecord<?, ?> record) {
     writeValue(rowWriter, MetaDataField.KAFKA_PARTITION_ID, record.partition());
     writeValue(rowWriter, MetaDataField.KAFKA_OFFSET, record.offset());
     writeValue(rowWriter, MetaDataField.KAFKA_TIMESTAMP, record.timestamp());
-    writeValue(rowWriter, MetaDataField.KAFKA_MSG_KEY, record.key() != null ? record.key().toString() : null);
+    writeValue(rowWriter, MetaDataField.KAFKA_MSG_KEY, record.key() != null ? getKeyValue((byte[]) record.key()) : null);
     rowWriter.save();
   }
 
+  private Object getKeyValue(byte[] keyValue) {
+    if (keyConvert) {
+      GenericRecord genericRecord = (GenericRecord) deserializer.deserialize(null, keyValue);
+      return genericRecord.toString();

Review comment:
       No need to cast it to `GenericRecord`:
   ```suggestion
         deserializer.deserialize(null, keyValue).toString();
   ```




-- 
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:
users@infra.apache.org