Search code examples
javamongodbmavenavro

Maven avro plugin gives schema not yet supported error


In my maven project, I use maven avro plugin to create Java classes from avro schema files. This is the avro file I got from schema registry.

{
   "type":"record",
   "name":"Envelope",
   "namespace":"mongodb.company.price_service_company_calc_logs",
   "fields":[
      {
         "name":"after",
         "type":[
            null,
            {
               "type":"string",
               "connect.version":1,
               "connect.name":"io.debezium.data.Json"
            }
         ],
         "default":null
      },
      {
         "name":"patch",
         "type":[
            null,
            {
               "type":"string",
               "connect.version":1,
               "connect.name":"io.debezium.data.Json"
            }
         ],
         "default":null
      },
      {
         "name":"filter",
         "type":[
            null,
            {
               "type":"string",
               "connect.version":1,
               "connect.name":"io.debezium.data.Json"
            }
         ],
         "default":null
      },
      {
         "name":"source",
         "type":{
            "type":"record",
            "name":"Source",
            "namespace":"io.debezium.connector.mongo",
            "fields":[
               {
                  "name":"version",
                  "type":"string"
               },
               {
                  "name":"connector",
                  "type":"string"
               },
               {
                  "name":"name",
                  "type":"string"
               },
               {
                  "name":"ts_ms",
                  "type":"long"
               },
               {
                  "name":"snapshot",
                  "type":[
                     {
                        "type":"string",
                        "connect.version":1,
                        "connect.parameters":{
                           "allowed":true,
                           "last":false
                        },
                        "connect.default":false,
                        "connect.name":"io.debezium.data.Enum"
                     },
                     null
                  ],
                  "default":false
               },
               {
                  "name":"db",
                  "type":"string"
               },
               {
                  "name":"rs",
                  "type":"string"
               },
               {
                  "name":"collection",
                  "type":"string"
               },
               {
                  "name":"ord",
                  "type":"int"
               },
               {
                  "name":"h",
                  "type":[
                     null,
                     "long"
                  ],
                  "default":null
               },
               {
                  "name":"tord",
                  "type":[
                     null,
                     "long"
                  ],
                  "default":null
               }
            ],
            "connect.name":"io.debezium.connector.mongo.Source"
         }
      },
      {
         "name":"op",
         "type":[
            null,
            "string"
         ],
         "default":null
      },
      {
         "name":"ts_ms",
         "type":[
            null,
            "long"
         ],
         "default":null
      }
   ],
   "connect.name":"mongodb.company.price_service_company_calc_logs.Envelope"
}

Whenever I run mvn package it gives me the following error:

Execution default of goal org.apache.avro:avro-maven-plugin:1.9.2:schema failed: Schema not yet supported: null

Is there any way I get more information about the exact root of the problem? Obviously maven -e or -X switches do not help much.


Solution

  • It turned out the avro file is not correct. All null values for types must be in double-quotes.

    {
       "type":"record",
       "name":"Envelope",
       "namespace":"mongodb.company.price_service_company_calc_logs",
       "fields":[
          {
             "name":"after",
             "type":[
                "null",
                {
                   "type":"string",
                   "connect.version":1,
                   "connect.name":"io.debezium.data.Json"
                }
             ],
             "default":null
          },
          {
             "name":"patch",
             "type":[
                "null",
                {
                   "type":"string",
                   "connect.version":1,
                   "connect.name":"io.debezium.data.Json"
                }
             ],
             "default":null
          },
          {
             "name":"filter",
             "type":[
                "null",
                {
                   "type":"string",
                   "connect.version":1,
                   "connect.name":"io.debezium.data.Json"
                }
             ],
             "default":null
          },
          {
             "name":"source",
             "type":{
                "type":"record",
                "name":"Source",
                "namespace":"io.debezium.connector.mongo",
                "fields":[
                   {
                      "name":"version",
                      "type":"string"
                   },
                   {
                      "name":"connector",
                      "type":"string"
                   },
                   {
                      "name":"name",
                      "type":"string"
                   },
                   {
                      "name":"ts_ms",
                      "type":"long"
                   },
                   {
                      "name":"snapshot",
                      "type":[
                         {
                            "type":"string",
                            "connect.version":1,
                            "connect.parameters":{
                               "allowed":true,
                               "last":false
                            },
                            "connect.default":false,
                            "connect.name":"io.debezium.data.Enum"
                         },
                         "null"
                      ],
                      "default":false
                   },
                   {
                      "name":"db",
                      "type":"string"
                   },
                   {
                      "name":"rs",
                      "type":"string"
                   },
                   {
                      "name":"collection",
                      "type":"string"
                   },
                   {
                      "name":"ord",
                      "type":"int"
                   },
                   {
                      "name":"h",
                      "type":[
                         "null",
                         "long"
                      ],
                      "default":null
                   },
                   {
                      "name":"tord",
                      "type":[
                         "null",
                         "long"
                      ],
                      "default":null
                   }
                ],
                "connect.name":"io.debezium.connector.mongo.Source"
             }
          },
          {
             "name":"op",
             "type":[
                "null",
                "string"
             ],
             "default":null
          },
          {
             "name":"ts_ms",
             "type":[
                "null",
                "long"
             ],
             "default":null
          }
       ],
       "connect.name":"mongodb.company.price_service_company_calc_logs.Envelope"
    }