From b5bec5ca18901507f6fc01d635f10465fd3edcdf Mon Sep 17 00:00:00 2001 From: Simon24601 Date: Mon, 3 Dec 2018 20:13:34 +0000 Subject: [PATCH] Avro1363 C# union schema can now contain multiple entries with the same name and different namespace (#131) * AVRO-1849 Fix the issue where converting the schema of a record with no fields produced an invalid JSON * Fix style issues in the code. * Fix the build scripts; build.sh requires the :z addition to work on SELinux (see Jira 1925). lang/c++/build.sh refers to the lang/c++/build directory which is empty. These are now fixed. * Update to use BOOST_TEST_CHECKPOINT * AVRO-1926 Revert changes to the lang/c++/build.sh script and add the SchemaTests to the list of tests. Also revert SELinux changes to build.sh as these should be committed separately * AVRO-1363 Fix the parsing of a union schema with duplicate names but different namespaces. In Java, this works, but not in C# * Remove c++ changes from the AVRO1363 branch --- lang/csharp/src/apache/main/Schema/NamedSchema.cs | 2 +- lang/csharp/src/apache/main/Schema/Schema.cs | 12 ++++++++++-- lang/csharp/src/apache/main/Schema/UnionSchema.cs | 2 +- lang/csharp/src/apache/test/Schema/SchemaTests.cs | 3 ++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lang/csharp/src/apache/main/Schema/NamedSchema.cs b/lang/csharp/src/apache/main/Schema/NamedSchema.cs index e0bfab0aafb..69632388580 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 /// /// Namespace.Name of the schema /// - 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 a9de8774e58..676cce90928 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; } + /// + /// If this is a record, enum or fixed, returns its name, otherwise the name the primitive type. + /// + public abstract string Name { get; } + /// /// 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. /// - public abstract string Name { get; } - + public virtual string Fullname + { + get { return Name; } + } + /// /// Static class to return new instance of schema object /// diff --git a/lang/csharp/src/apache/main/Schema/UnionSchema.cs b/lang/csharp/src/apache/main/Schema/UnionSchema.cs index df2c37fcefa..bc2ab5b9bc7 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 7931d405b0d..a1c3f3c92b7 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\"}",