[
https://issues.apache.org/jira/browse/AVRO-3376?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
makoto nakano updated AVRO-3376:
--------------------------------
Description:
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}
was:Currently, AvroC # ReflectReader does not support avro aliases.
> 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
> Reporter: makoto nakano
> Priority: Major
> Attachments: 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.1#820001)