Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avro1363 C# union schema can now contain multiple entries with the same name and different namespace #131

Merged
merged 11 commits into from
Dec 3, 2018
2 changes: 1 addition & 1 deletion lang/csharp/src/apache/main/Schema/NamedSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public string Namespace
/// <summary>
/// Namespace.Name of the schema
/// </summary>
public string Fullname
public override string Fullname

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the override?

{
get { return SchemaName.Fullname; }
}
Expand Down
12 changes: 10 additions & 2 deletions lang/csharp/src/apache/main/Schema/Schema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion lang/csharp/src/apache/main/Schema/UnionSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion lang/csharp/src/apache/test/Schema/SchemaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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\"}",
Expand Down