jerrypeng commented on a change in pull request #2537: [schema] enable 
Schema.AUTO if functions or connectors are using GenericRecord
URL: https://github.com/apache/incubator-pulsar/pull/2537#discussion_r215860896
 
 

 ##########
 File path: 
pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/source/TopicSchema.java
 ##########
 @@ -68,24 +69,31 @@ public TopicSchema(PulsarClient client) {
     }
 
     public Schema<?> getSchema(String topic, Class<?> clazz, SchemaType 
schemaType) {
-        return cachedSchemas.computeIfAbsent(topic, t -> extractSchema(clazz, 
schemaType));
+        return cachedSchemas.computeIfAbsent(topic, t -> 
newSchemaInstance(clazz, schemaType));
     }
 
     /**
      * If the topic is already created, we should be able to fetch the schema 
type (avro, json, ...)
      */
     private SchemaType getSchemaTypeOrDefault(String topic, Class<?> clazz) {
-        Optional<SchemaInfo> schema = ((PulsarClientImpl) 
client).getSchema(topic).join();
-        if (schema.isPresent()) {
-            return schema.get().getType();
+        if (GenericRecord.class.isAssignableFrom(clazz)) {
+            return SchemaType.AUTO;
         } else {
-            return getDefaultSchemaType(clazz);
+            Optional<SchemaInfo> schema = ((PulsarClientImpl) 
client).getSchema(topic).join();
 
 Review comment:
   Gotcha.  The name might be a little misleading.  Should we have a schema 
type that indicates that we want to use the schema of the topic if it exists, 
if it doesn't exist then use a default. We can have this logic in the pulsar 
client so we don't need to that logic of schema detection here?  I am not sure 
if its appropriate to put that logic here.  I would suspect users using the 
producer or consumer API might want to be able to do something similar.  What 
do you think? Though this does not really pertain to this PR

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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

Reply via email to