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_r215858084
 
 

 ##########
 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:
   So I don't get why we need this logic here?  If the schema is not explicitly 
set by the user, can't we just use SchemaType.Auto?  Don't we already have 
logic here to detect the schema of a topic:
   
   
https://github.com/apache/incubator-pulsar/blob/master/pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarClientImpl.java#L396

----------------------------------------------------------------
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