Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-3046

avrogen does not map inner record namespaces

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.10.1
    • None
    • csharp
    • None

    Description

      The avrogen tool for C# fails to map the namespaces of inner records.

      Example:

      {
        "type": "record",
        "name": "ExampleRecord",
        "namespace": "com.example",
        "fields": [
          {
            "name": "Id",
            "type": "string",
            "logicalType": "UUID"
          },
          {
            "name": "InnerRecord",
            "type": {
              "type": "record",
              "name": "InnerRecord",
              "fields": [
                {
                  "name": "Id",
                  "type": "string",
                  "logicalType": "UUID"
                }
              ]
            }
          }
        ]
      }
      

      Command:

      avrogen -s ./example.avsc ./dotnet --namespace "com.example:Example" 
      

      Result:

      // ------------------------------------------------------------------------------
      // <auto-generated>
      //    Generated by avrogen, version 1.10.0.0
      //    Changes to this file may cause incorrect behavior and will be lost if code
      //    is regenerated
      // </auto-generated>
      // ------------------------------------------------------------------------------
      namespace Example
      {
         using System;
         using System.Collections.Generic;
         using System.Text;
         using Avro;
         using Avro.Specific;
         
         public partial class ExampleRecord : ISpecificRecord
         {
            public static Schema _SCHEMA = Avro.Schema.Parse("{\"type\":\"record\",\"name\":\"ExampleRecord\",\"namespace\":\"com.example\",\"fields\":[{\"nam" +
                  "e\":\"Id\",\"type\":\"string\"},{\"name\":\"InnerRecord\",\"type\":{\"type\":\"record\",\"name\":\"I" +
                  "nnerRecord\",\"namespace\":\"com.example\",\"fields\":[{\"name\":\"Id\",\"type\":\"string\"}]}}" +
                  "]}");
            private string _Id;
            private com.example.InnerRecord _InnerRecord;
            public virtual Schema Schema
            {
               get
               {
                  return ExampleRecord._SCHEMA;
               }
            }
            public string Id
            {
               get
               {
                  return this._Id;
               }
               set
               {
                  this._Id = value;
               }
            }
            public com.example.InnerRecord InnerRecord
            {
               get
               {
                  return this._InnerRecord;
               }
               set
               {
                  this._InnerRecord = value;
               }
            }
            public virtual object Get(int fieldPos)
            {
               switch (fieldPos)
               {
               case 0: return this.Id;
               case 1: return this.InnerRecord;
               default: throw new AvroRuntimeException("Bad index " + fieldPos + " in Get()");
               };
            }
            public virtual void Put(int fieldPos, object fieldValue)
            {
               switch (fieldPos)
               {
               case 0: this.Id = (System.String)fieldValue; break;
               case 1: this.InnerRecord = (com.example.InnerRecord)fieldValue; break;
               default: throw new AvroRuntimeException("Bad index " + fieldPos + " in Put()");
               };
            }
         }
      }
      
      

       

      In this case the InnerRecord is referenced via "com.Example.InnerRecord", but it should be "Example.InnerRecord".

      Attachments

        Activity

          People

            Unassigned Unassigned
            PSanetra Philip Sanetra
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: