[
https://issues.apache.org/jira/browse/AVRO-3540?focusedWorklogId=783482&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-783482
]
ASF GitHub Bot logged work on AVRO-3540:
----------------------------------------
Author: ASF GitHub Bot
Created on: 21/Jun/22 17:05
Start Date: 21/Jun/22 17:05
Worklog Time Spent: 10m
Work Description: github-code-scanning[bot] commented on code in PR #1728:
URL: https://github.com/apache/avro/pull/1728#discussion_r902864008
##########
lang/csharp/src/apache/test/Reflect/TestReflect.cs:
##########
@@ -21,12 +21,75 @@
using NUnit.Framework;
using Avro.IO;
using Avro.Reflect;
+using System.Collections.Generic;
+using System;
+using Avro.Specific;
+using System.Linq;
+
+
namespace Avro.Test
{
[TestFixture]
class TestReflect
{
+ public class DictionaryTestClass
+ {
+ public Dictionary<int, int> p { get; set; }
+ public NestedTestClass ntc { get; set; }
+
+
+ public class NestedTestClass
+ {
+ public int NestedTestClassInt { get; set; }
+ }
+ }
+
+ public class DictionaryTestClass2
+ {
+ public Dictionary<int, string> p { get; set; }
+
+ }
+ class TestMapConverter : IAvroFieldConverter
+ {
+ public object FromAvroType(object o, Schema s) =>
+ ((Dictionary<string, int>)o).ToDictionary(x =>
int.Parse(x.Key), y=>y.Value);
+
+
+ public Type GetAvroType() => typeof(IDictionary<string, int>);
+ public Type GetPropertyType() => typeof(Dictionary<int, int>);
+ public object ToAvroType(object o, Schema s) =>
+ ((Dictionary<int, int>)o).ToDictionary(x => x.Key.ToString(),
y => y.Value);
+ }
+
+ [TestCase]
+ public void TestMapWithConverterSucceeds()
+ {
+ ClassCache.AddDefaultConverter(new TestMapConverter());
+
+ var schemaJson =
"{\"fields\":[{\"name\":\"ntc\",\"type\":{\"type\":\"record\",\"name\":\"NestedTestClass\",\"fields\":[{\"name\":\"NestedTestClassInt\",\"type\":\"int\"}]}},{\"type\":{\"values\":\"int\",\"type\":\"map\"},\"name\":\"p\"}],\"type\":\"record\",\"name\":\"DictionaryTestClass\",\"namespace\":\"Avro.Test.TestReflect\\u002B\"}";
+ var schema = Schema.Parse(schemaJson);
+ DictionaryTestClass expected = new DictionaryTestClass() { p = new
Dictionary<int, int>() { { 1, 1 }, { 2, 4 }, { 3, 5 } } , ntc = new
DictionaryTestClass.NestedTestClass() { NestedTestClassInt = 1 } };
+
+ using Stream stream = serialize(schema, expected);
+ var avroReader = new ReflectReader<DictionaryTestClass>(schema,
schema);
+ stream.Position = 0;
+ var actual = avroReader.Read(null, new BinaryDecoder(stream));
+
+ CollectionAssert.AreEquivalent(expected.p, actual.p);
+ }
+
+ [TestCase]
+ public void TestMapWithoutConverterFails()
+ {
+ var schemaJson =
"{\"fields\":[{\"type\":{\"values\":\"string\",\"type\":\"map\"},\"name\":\"p\"}],\"type\":\"record\",\"name\":\"DictionaryTestClass\",\"namespace\":\"Avro.Test.TestReflect\\u002B\"}";
+ var schema = Schema.Parse(schemaJson);
+ DictionaryTestClass2 expected = new DictionaryTestClass2() { p =
new Dictionary<int, string>() { { 1, "1" }, { 2, "4" }, { 3, "5" } } };
Review Comment:
## Useless assignment to local variable
This assignment to [expected](1) is useless, since its value is never read.
[Show more
details](https://github.com/apache/avro/security/code-scanning/2723)
##########
lang/csharp/src/apache/main/Reflect/DotnetProperty.cs:
##########
@@ -19,6 +19,7 @@
using System;
using System.Reflection;
using System.Collections;
+using System.Collections.Generic;
Review Comment:
## Compilation message
Hidden CS8019 Unnecessary using directive.
[Show more
details](https://github.com/apache/avro/security/code-scanning/2724)
Issue Time Tracking
-------------------
Worklog Id: (was: 783482)
Time Spent: 40m (was: 0.5h)
> .NET/C# Allow Reflect reader/writer to support Dictionaries keyed by
> something other than string
> ------------------------------------------------------------------------------------------------
>
> Key: AVRO-3540
> URL: https://issues.apache.org/jira/browse/AVRO-3540
> Project: Apache Avro
> Issue Type: Improvement
> Components: csharp
> Reporter: Christopher Fingar
> Priority: Major
> Labels: pull-request-available
> Time Spent: 40m
> Remaining Estimate: 0h
>
> Currently the existing reflect code does not support converting other key
> types to string.
> My change provides an opt-in functionality using the default converters.
> This allows users to keep there existing code instead of converting types to
> use string keys.
>
>
--
This message was sent by Atlassian Jira
(v8.20.7#820007)