[ 
https://issues.apache.org/jira/browse/AVRO-1363?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16710271#comment-16710271
 ] 

ASF GitHub Bot commented on AVRO-1363:
--------------------------------------

dkulp closed pull request #156: AVRO-1363 Fix the C# parsing of a union schema 
URL: https://github.com/apache/avro/pull/156
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/lang/csharp/src/apache/main/Schema/NamedSchema.cs 
b/lang/csharp/src/apache/main/Schema/NamedSchema.cs
index 02beb7984..b75483f84 100644
--- a/lang/csharp/src/apache/main/Schema/NamedSchema.cs
+++ b/lang/csharp/src/apache/main/Schema/NamedSchema.cs
@@ -52,7 +52,7 @@ public string Namespace
         /// <summary>
         /// Namespace.Name of the schema
         /// </summary>
-        public string Fullname
+        public override string Fullname
         {
             get { return SchemaName.Fullname; }
         }
diff --git a/lang/csharp/src/apache/main/Schema/Schema.cs 
b/lang/csharp/src/apache/main/Schema/Schema.cs
index fc0e23792..d2d2f079c 100644
--- a/lang/csharp/src/apache/main/Schema/Schema.cs
+++ b/lang/csharp/src/apache/main/Schema/Schema.cs
@@ -70,12 +70,20 @@ protected Schema(Type type, PropertyMap props)
             this.Props = props;
         }
 
+        /// <summary>
+        /// If this is a record, enum or fixed, returns its name, otherwise 
the name the primitive type. 
+        /// </summary>
+        public abstract string Name { get; }
+        
         /// <summary>
         /// The name of this schema. If this is a named schema such as an 
enum, it returns the fully qualified
         /// name for the schema. For other schemas, it returns the type of the 
schema.
         /// </summary>
-        public abstract string Name { get; }
-
+        public virtual string Fullname 
+        {
+            get { return Name; }
+        }
+        
         /// <summary>
         /// Static class to return new instance of schema object
         /// </summary>
diff --git a/lang/csharp/src/apache/main/Schema/UnionSchema.cs 
b/lang/csharp/src/apache/main/Schema/UnionSchema.cs
index df2c37fce..bc2ab5b9b 100644
--- a/lang/csharp/src/apache/main/Schema/UnionSchema.cs
+++ b/lang/csharp/src/apache/main/Schema/UnionSchema.cs
@@ -56,7 +56,7 @@ internal static UnionSchema NewInstance(JArray jarr, 
PropertyMap props, SchemaNa
                 if (null == unionType)
                     throw new SchemaParseException("Invalid JSON in union" + 
jvalue.ToString());
 
-                string name = unionType.Name;
+                string name = unionType.Fullname;
                 if (uniqueSchemas.ContainsKey(name))
                     throw new SchemaParseException("Duplicate type in union: " 
+ name);
 
diff --git a/lang/csharp/src/apache/test/Schema/SchemaTests.cs 
b/lang/csharp/src/apache/test/Schema/SchemaTests.cs
index b12483187..885b5a40b 100644
--- a/lang/csharp/src/apache/test/Schema/SchemaTests.cs
+++ b/lang/csharp/src/apache/test/Schema/SchemaTests.cs
@@ -69,7 +69,8 @@ public class SchemaTests
             Description = "No fields", ExpectedException = 
typeof(SchemaParseException))]
         [TestCase("{\"type\":\"record\",\"name\":\"LongList\", \"fields\": 
\"hi\"}",
             Description = "Fields not an array", ExpectedException = 
typeof(SchemaParseException))]
-
+        [TestCase("[{\"type\": \"record\",\"name\": 
\"Test\",\"namespace\":\"ns1\",\"fields\": [{\"name\": \"f\",\"type\": 
\"long\"}]}," + 
+                   "{\"type\": \"record\",\"name\": 
\"Test\",\"namespace\":\"ns2\",\"fields\": [{\"name\": \"f\",\"type\": 
\"long\"}]}]")]
         // Enum
         [TestCase("{\"type\": \"enum\", \"name\": \"Test\", \"symbols\": 
[\"A\", \"B\"]}")]
         [TestCase("{\"type\": \"enum\", \"name\": \"Status\", \"symbols\": 
\"Normal Caution Critical\"}",


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> C# UnionSchema fails to parse the the unions with same type names with 
> different namespaces
> -------------------------------------------------------------------------------------------
>
>                 Key: AVRO-1363
>                 URL: https://issues.apache.org/jira/browse/AVRO-1363
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: csharp
>    Affects Versions: 1.7.4
>            Reporter: Ramana Suvarapu
>            Priority: Major
>         Attachments: reader.avpr
>
>
> C# Union schema is unable to handle same type names with different 
> namespaces. It's throwing "SchemaParseException("Duplicate type in union: 
> "...) exception.
> In the below code, key of uniqueSchemas should be FullName of the type which 
> is similar to Java implementation. 
> internal static UnionSchema NewInstance(JArray jarr, PropertyMap props, 
> SchemaNames names, string encspace)
>         {
>             List<Schema> schemas = new List<Schema>();
>             IDictionary<string, string> uniqueSchemas = new 
> Dictionary<string, string>();
>             foreach (JToken jvalue in jarr)
>             {
>                 Schema unionType = Schema.ParseJson(jvalue, names, encspace);
>                 if (null == unionType)
>                     throw new SchemaParseException("Invalid JSON in union" + 
> jvalue.ToString());
>                 string name = unionType.Name;
>                 if (uniqueSchemas.ContainsKey(name))
>                     throw new SchemaParseException("Duplicate type in union: 
> " + name);
>                 uniqueSchemas.Add(name, name);
>                 schemas.Add(unionType);
>             }
>             return new UnionSchema(schemas, props);
>         }
> See the attachement to recreate the issue



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to