htran1 commented on a change in pull request #2682: [GOBBLIN-820] Add keyed
write capability to Kafka writer
URL: https://github.com/apache/incubator-gobblin/pull/2682#discussion_r301404509
##########
File path:
gobblin-modules/gobblin-kafka-common/src/main/java/org/apache/gobblin/kafka/writer/KafkaWriterHelper.java
##########
@@ -90,4 +94,32 @@ public static Object getKafkaProducer(Properties props) {
throw Throwables.propagate(e);
}
}
+
+ public static <K, D> K getKey(D record, KafkaWriterCommonConfig commonConfig)
+ throws FieldMappingException {
+ if (commonConfig.isKeyed()) {
+ return (K) commonConfig.getTypeMapper().getField(record,
commonConfig.getKeyField());
+ } else {
+ return null;
+ }
+ }
+
+ public static <D> D getValue(D record, KafkaWriterCommonConfig commonConfig)
+ throws FieldMappingException {
+ return (D) commonConfig.getTypeMapper().getField(record,
commonConfig.getValueField());
+ }
+
+ public static <V, K> Pair<K,V> getKeyValuePair(V record,
KafkaWriterCommonConfig commonConfig)
+ throws FieldMappingException {
+ K key = null;
+ TypeMapper typeMapper = commonConfig.getTypeMapper();
Review comment:
Why not call `getKey` and `getValue` to avoid code duplication? Is this to
be a little more efficient?
----------------------------------------------------------------
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]
With regards,
Apache Git Services