diff --git a/src/HDInsight/Microsoft.Hadoop.Avro.Tests/SchemaTests/JsonSchemaBuilderTests.cs b/src/HDInsight/Microsoft.Hadoop.Avro.Tests/SchemaTests/JsonSchemaBuilderTests.cs index e566cc7c4ffc3..68f977115c307 100644 --- a/src/HDInsight/Microsoft.Hadoop.Avro.Tests/SchemaTests/JsonSchemaBuilderTests.cs +++ b/src/HDInsight/Microsoft.Hadoop.Avro.Tests/SchemaTests/JsonSchemaBuilderTests.cs @@ -21,6 +21,7 @@ namespace Microsoft.Hadoop.Avro.Tests using System.Runtime.Serialization; using Microsoft.Hadoop.Avro.Schema; using Microsoft.VisualStudio.TestTools.UnitTesting; + using ProtoBuf; [TestClass] public sealed class JsonSchemaTests @@ -58,6 +59,16 @@ public void JsonSchemaBuilder_BuildLongSchema() CollectionAssert.AreEqual(this.emptyAttributes.ToList(), schema.Attributes.ToList()); } + [TestMethod] + [TestCategory("CheckIn")] + public void JsonSchemaBuilder_ClassOfGuidWriterSchema() + { + var settings = new AvroSerializerSettings { Resolver = new AvroDataContractResolver(false) }; + IAvroSerializer serializer = AvroSerializer.Create(settings); + string writerSchema = serializer.WriterSchema.ToString(); + AvroSerializer.CreateDeserializerOnly(writerSchema, settings); + } + [TestMethod] [TestCategory("CheckIn")] public void JsonSchemaBuilder_BuildFloatSchema() diff --git a/src/HDInsight/Microsoft.Hadoop.Avro.Tests/TestClasses/TestClasses.cs b/src/HDInsight/Microsoft.Hadoop.Avro.Tests/TestClasses/TestClasses.cs index ef8ae19c936d1..a4ef4ff688ea1 100644 --- a/src/HDInsight/Microsoft.Hadoop.Avro.Tests/TestClasses/TestClasses.cs +++ b/src/HDInsight/Microsoft.Hadoop.Avro.Tests/TestClasses/TestClasses.cs @@ -103,9 +103,12 @@ public class ClassOfGuid : IEquatable [DataMember] public Guid PrimitiveGuid; + [DataMember] + public Guid PrimitiveGuid2; + public static ClassOfGuid Create(bool nullablesAreNulls) { - return new ClassOfGuid { PrimitiveGuid = Utilities.GetRandom(nullablesAreNulls), }; + return new ClassOfGuid { PrimitiveGuid = Utilities.GetRandom(nullablesAreNulls), PrimitiveGuid2 = Utilities.GetRandom(nullablesAreNulls) }; } public override bool Equals(object obj) @@ -119,12 +122,12 @@ public bool Equals(ClassOfGuid other) { return false; } - return this.PrimitiveGuid == other.PrimitiveGuid; + return this.PrimitiveGuid == other.PrimitiveGuid && this.PrimitiveGuid2 == other.PrimitiveGuid2; } public override int GetHashCode() { - return this.PrimitiveGuid.GetHashCode(); + return this.PrimitiveGuid.GetHashCode() ^ this.PrimitiveGuid2.GetHashCode(); } } diff --git a/src/HDInsight/Microsoft.Hadoop.Avro/Schema/JsonSchemaBuilder.cs b/src/HDInsight/Microsoft.Hadoop.Avro/Schema/JsonSchemaBuilder.cs index 6ad801a5493d7..896f3eb6559a9 100644 --- a/src/HDInsight/Microsoft.Hadoop.Avro/Schema/JsonSchemaBuilder.cs +++ b/src/HDInsight/Microsoft.Hadoop.Avro/Schema/JsonSchemaBuilder.cs @@ -145,7 +145,7 @@ private TypeSchema ParseJsonObject(JObject token, NamedSchema parent, Dictionary case Token.Map: return this.ParseMapType(token, parent, namedSchemas); case Token.Fixed: - return this.ParseFixedType(token, parent); + return this.ParseFixedType(token, parent, namedSchemas); default: throw new SerializationException( string.Format(CultureInfo.InvariantCulture, "Invalid type specified: '{0}'.", type)); @@ -415,7 +415,7 @@ private TypeSchema CreatePrimitiveTypeSchema(string type, Dictionary namedSchemas) { var name = type.RequiredProperty(Token.Name); var nspace = this.GetNamespace(type, parent, name); @@ -433,6 +433,9 @@ private FixedSchema ParseFixedType(JObject type, NamedSchema parent) var customAttributes = type.GetAttributesNotIn(StandardProperties.Record); var result = new FixedSchema(attributes, size, typeof(byte[]), customAttributes); + + namedSchemas.Add(result.FullName, result); + return result; }