You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "makoto nakano (Jira)" <ji...@apache.org> on 2022/06/12 14:08:00 UTC
[jira] [Updated] (AVRO-3376) avro aliases support for C# ReflectReader
[ https://issues.apache.org/jira/browse/AVRO-3376?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
makoto nakano updated AVRO-3376:
--------------------------------
Attachment: AVRO-3379.patch
Release Note: aliases support for C#
Affects Version/s: 1.11.0
Status: Patch Available (was: Open)
> avro aliases support for C# ReflectReader
> ------------------------------------------
>
> Key: AVRO-3376
> URL: https://issues.apache.org/jira/browse/AVRO-3376
> Project: Apache Avro
> Issue Type: Improvement
> Components: csharp
> Affects Versions: 1.11.0
> Reporter: makoto nakano
> Priority: Major
> Attachments: AVRO-3379.patch, AvroReflectSample.zip
>
>
> Currently, AvroC # ReflectReader does not support avro aliases.
> {code:java}
> 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}");
> } {code}
--
This message was sent by Atlassian Jira
(v8.20.7#820007)