AHeise commented on code in PR #130:
URL: 
https://github.com/apache/flink-connector-kafka/pull/130#discussion_r1815659513


##########
flink-connector-kafka/src/main/java/org/apache/flink/connector/kafka/sink/KafkaRecordSerializationSchemaBuilder.java:
##########
@@ -369,5 +416,43 @@ public ProducerRecord<byte[], byte[]> serialize(
                     value,
                     headerProvider != null ? 
headerProvider.getHeaders(element) : null);
         }
+
+        @Override
+        public Optional<KafkaDatasetFacet> getKafkaDatasetFacet() {
+            if (!(topicSelector instanceof KafkaDatasetIdentifierProvider)) {
+                LOG.warn("Cannot identify topics. Not an 
TopicsIdentifierProvider");
+                return Optional.empty();
+            }
+
+            Optional<KafkaDatasetIdentifier> topicsIdentifier =
+                    ((KafkaDatasetIdentifierProvider) 
(topicSelector)).getDatasetIdentifier();
+
+            if (!topicsIdentifier.isPresent()) {
+                LOG.warn("No topics' identifiers provided");
+                return Optional.empty();
+            }
+
+            TypeInformation typeInformation;
+            if (this.valueSerializationSchema instanceof ResultTypeQueryable) {
+                typeInformation =
+                        ((ResultTypeQueryable<?>) 
this.valueSerializationSchema).getProducedType();
+            } else {
+                // gets type information from serialize method signature
+                typeInformation =
+                        
Arrays.stream(this.valueSerializationSchema.getClass().getMethods())
+                                .map(m -> Invokable.from(m))
+                                .filter(m -> 
"serialize".equalsIgnoreCase(m.getName()))
+                                .map(m -> m.getParameters().get(0))
+                                .filter(p -> 
!p.getType().equals(TypeToken.of(Object.class)))
+                                .findFirst()
+                                .map(p -> p.getType())
+                                .map(t -> TypeInformation.of(t.getRawType()))
+                                .orElse(null);

Review Comment:
   This looks way more complicated as it should be. Here is what I had in mind.
   
   ```
   TypeToken<? extends SerializationSchema> serializationSchemaType = 
TypeToken.of(valueSerializationSchema.getClass());
   Class<?> parameterType = 
serializationSchemaType.resolveType(SerializationSchema.class.getTypeParameters()[0]).getRawType();
   if (parameterType != Object.class) {
       typeInformation = TypeInformation.of(parameterType);
   }
   ```



-- 
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: issues-unsubscr...@flink.apache.org

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

Reply via email to