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

avro aliases support for C# ReflectReader

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Patch Available
    • Major
    • Resolution: Unresolved
    • 1.11.0
    • None
    • csharp
    • None
    • Added support for Alias function in ReflectReader.

    Description

      Currently, AvroC # ReflectReader does not support avro aliases.

              public class SampleOld
              {
                  public string OldValue { set; get; }
              }
              public static string SampleOldSchema => "{" +
                                                    "    \"type\":\"record\"," +
                                                    "    \"name\":\"Sample\"," +
                                                    "    \"fields\":[" +
                                                    "        {" +
                                                    "            \"name\":\"OldValue\"," +
                                                    "            \"type\":\"string\"" +
                                                    "        }" +
                                                    "    ]" +
                                                    "}";        
      
              public class SampleNew
              {
                  public string NewValue { set; get; } = "";
              }
              public static string SampleNewSchema => "{" +
                                                    "    \"type\":\"record\"," +
                                                    "    \"name\":\"Sample\"," +
                                                    "    \"fields\":[" +
                                                    "        {" +
                                                    "            \"name\":\"NewValue\"," +
                                                    "            \"aliases\":[\"OldValue\"]," +
                                                    "            \"type\":\"string\"" +
                                                    "        }" +
                                                    "    ]" +
                                                    "}";   
          
              static void Main(string[] args)
              {
                  using var stream = new MemoryStream();            
                  var sample = new SampleOld()
                  {
                      OldValue = "TestValue"
                  };
      
                  var writerSchema = Schema.Parse(SampleOldSchema);
                  var avroWriter = new ReflectWriter<SampleOld>(writerSchema);
                  avroWriter.Write(sample, new BinaryEncoder(stream));
      
                  stream.Position = 0;            
      
                  var readerSchema = Schema.Parse(SampleNewSchema);
                  var avroReader = new ReflectReader<SampleNew>(writerSchema, readerSchema);
                  var Result = avroReader.Read(new BinaryDecoder(stream));            
                  
                  // Read Function is Success
                  // NewValue does not contain the OldValue value
                  Console.WriteLine($"Read Value = {Result.NewValue}");
              } 

      Attachments

        1. AVRO-3379.patch
          5 kB
          makoto nakano
        2. AvroReflectSample.zip
          2 kB
          makoto nakano

        Activity

          People

            Unassigned Unassigned
            otonowa-naka makoto nakano
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: