Skip to content

Commit

Permalink
fix issue Azure#987 where multiple of fixed schema show up on the sam…
Browse files Browse the repository at this point in the history
…e record type.
  • Loading branch information
chuanboz committed Mar 5, 2015
1 parent 680c689 commit 27d1ba6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<ClassOfGuid> serializer = AvroSerializer.Create<ClassOfGuid>(settings);
string writerSchema = serializer.WriterSchema.ToString();
AvroSerializer.CreateDeserializerOnly<ClassOfGuid>(writerSchema, settings);
}

[TestMethod]
[TestCategory("CheckIn")]
public void JsonSchemaBuilder_BuildFloatSchema()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,12 @@ public class ClassOfGuid : IEquatable<ClassOfGuid>
[DataMember]
public Guid PrimitiveGuid;

[DataMember]
public Guid PrimitiveGuid2;

public static ClassOfGuid Create(bool nullablesAreNulls)
{
return new ClassOfGuid { PrimitiveGuid = Utilities.GetRandom<Guid>(nullablesAreNulls), };
return new ClassOfGuid { PrimitiveGuid = Utilities.GetRandom<Guid>(nullablesAreNulls), PrimitiveGuid2 = Utilities.GetRandom<Guid>(nullablesAreNulls) };
}

public override bool Equals(object obj)
Expand All @@ -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();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -415,7 +415,7 @@ private TypeSchema CreatePrimitiveTypeSchema(string type, Dictionary<string, str
return result;
}

private FixedSchema ParseFixedType(JObject type, NamedSchema parent)
private FixedSchema ParseFixedType(JObject type, NamedSchema parent, Dictionary<string, NamedSchema> namedSchemas)
{
var name = type.RequiredProperty<string>(Token.Name);
var nspace = this.GetNamespace(type, parent, name);
Expand All @@ -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;
}

Expand Down

0 comments on commit 27d1ba6

Please sign in to comment.