You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2020/11/12 14:44:54 UTC

[GitHub] [pulsar] michaelkux commented on issue #8510: AVRO Schema with modified whitespaces uploaded via API is incompatible with Schema generated from Record (IncompatibleSchema)

michaelkux commented on issue #8510:
URL: https://github.com/apache/pulsar/issues/8510#issuecomment-726121702


   I tried it now with java also: Same/similar issue. Uploading the generated schema leads to an IncompatibleSchema Exception. I hope the way how I upload the schema is correct.
   
   SimpleAvroRecord Pojo:
   
   `public class SimpleAvroRecord {
   
       public String data;
   
       public SimpleAvroRecord() {
   
       }
   
       public SimpleAvroRecord(String data) {
           this.data = data;
       }
   
       public String getData() {
           return data;
       }
   
       public void setData(String data) {
           this.data = data;
       }
   }`
   
   If I use the API (CLI) version "admin.schemas().createSchema(TOPIC_TEST_AVRO, new PostSchemaPayload..." its the same
   
   `@PostConstruct
       public void initPulsar() throws Exception {
           client = PulsarClient.builder()
                   .serviceUrl(pulsarServiceUrl)
                   .build();
   
           admin = PulsarAdmin.builder().serviceHttpUrl(pulsarAdminUrl).build();
   
           admin.schemas().deleteSchema(TOPIC_TEST_AVRO);
           admin.topics().delete(TOPIC_TEST_AVRO, true);
   
           NamespaceName namespaceName = NamespaceName.get("public", "default");
   
           admin.namespaces().setIsAllowAutoUpdateSchema(namespaceName.toString(), false);
           admin.namespaces().setSchemaValidationEnforced(namespaceName.toString(), true);
           admin.namespaces().setSchemaCompatibilityStrategy(namespaceName.toString(), SchemaCompatibilityStrategy.FULL);
           admin.topics().createNonPartitionedTopic(TOPIC_TEST_AVRO);
   
           // admin.schemas().createSchema(TOPIC_TEST_AVRO, Schema.AVRO(SimpleAvroRecord.class).getSchemaInfo());
   
           Map<String, String> prop = new HashMap<>();
           prop.put("__alwaysAllowNull", "true");
           prop.put("__jsr310ConversionEnabled", "false");
           admin.schemas().createSchema(TOPIC_TEST_AVRO,
                   new PostSchemaPayload("AVRO", "\n{\n  \"type\" : \"record\",\n  \"name\" : \"SimpleAvroRecord\",\n  " +
                           "\"fields\" : [ {\n    \"name\" : \"data\",\n    \"type\" : [ \"null\", \"string\" ],\n    \"default\" : null\n  } ]\n}", prop));
   
           Producer<SimpleAvroRecord> producer = client.newProducer(AvroSchema.of(SimpleAvroRecord.class))
                   .topic(TOPIC_TEST_AVRO)
                   .create();
   
           producer.send(new SimpleAvroRecord("test"));
   
           producer.close();
   
           System.out.println("Done");
   
          // testUploadedSchema();
       }`
   
   Throws the following exception:
   
   Caused by: org.apache.pulsar.client.api.PulsarClientException$IncompatibleSchemaException: org.apache.pulsar.broker.service.schema.exceptions.IncompatibleSchemaException: Schema not found and schema auto updating is disabled.
   	at org.apache.pulsar.client.api.PulsarClientException.unwrap(PulsarClientException.java:862) ~[pulsar-client-api-2.6.1.jar:2.6.1]
   	at org.apache.pulsar.client.impl.ProducerBuilderImpl.create(ProducerBuilderImpl.java:93) ~[pulsar-client-admin-2.6.1.jar:2.6.1]
   
   The uploaded schema is equal to that one that is generated by "admin.schemas().createSchema(TOPIC_TEST_AVRO, Schema.AVRO(SimpleAvroRecord.class).getSchemaInfo()).
   
   Here the output via pulsar admin: 
   
   ./bin/pulsar-admin schemas get persistent://public/default/test_avro
   {
     "version": 102,
     "schemaInfo": {
       "name": "test_avro",
       "schema": {
         "type": "record",
         "name": "SimpleAvroRecord",
         "fields": [
           {
             "name": "data",
             "type": [
               "null",
               "string"
             ]
           }
         ]
       },
       "type": "AVRO",
       "properties": {
         "__alwaysAllowNull": "true",
         "__jsr310ConversionEnabled": "false"
       }
     }
   }
   
   


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