avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1339387 - in /avro/trunk: ./ lang/java/avro/src/main/java/org/apache/avro/ lang/java/avro/src/main/java/org/apache/avro/generic/ lang/java/avro/src/test/java/org/apache/avro/generic/ lang/java/ipc/src/test/java/org/apache/avro/
Date Wed, 16 May 2012 21:57:46 GMT
Author: cutting
Date: Wed May 16 21:57:46 2012
New Revision: 1339387

URL: http://svn.apache.org/viewvc?rev=1339387&view=rev
Log:
AVRO-1049. Java: Fix GenericData.Record#equals() to correctly compare schemas and fix Schema#equals()
to consider order.

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/Schema.java
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java
    avro/trunk/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericData.java
    avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1339387&r1=1339386&r2=1339387&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Wed May 16 21:57:46 2012
@@ -62,6 +62,9 @@ Avro 1.6.3 (5 March 2012)
     parameters are a union of a primitive and null.
     (Hamed Asghari via cutting)
 
+    AVRO-1049. Java: Fix GenericData.Record#equals() to correctly
+    compare schemas and fix Schema#equals() to consider order. (cutting)
+
   IMPROVEMENTS
 
     AVRO-1030. Fix a broken link in the documentation.

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/Schema.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/Schema.java?rev=1339387&r1=1339386&r2=1339387&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/Schema.java (original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/Schema.java Wed May 16 21:57:46
2012
@@ -451,6 +451,7 @@ public abstract class Schema {
       return (name.equals(that.name)) &&
         (schema.equals(that.schema)) &&
         defaultValueEquals(that.defaultValue) &&
+        (order == that.order) &&
         props.equals(that.props);
     }
     public int hashCode() { return name.hashCode() + schema.computeHash(); }

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java?rev=1339387&r1=1339386&r2=1339387&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java (original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java Wed May
16 21:57:46 2012
@@ -103,7 +103,7 @@ public class GenericData {
       if (o == this) return true;                 // identical object
       if (!(o instanceof Record)) return false;   // not a record
       Record that = (Record)o;
-      if (!schema.getFullName().equals(that.schema.getFullName()))
+      if (!this.schema.equals(that.schema))
         return false;                             // not the same schema
       return GenericData.get().compare(this, that, schema, true) == 0;
     }

Modified: avro/trunk/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericData.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericData.java?rev=1339387&r1=1339386&r2=1339387&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericData.java (original)
+++ avro/trunk/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericData.java Wed
May 16 21:57:46 2012
@@ -140,6 +140,30 @@ public class TestGenericData {
     return schema;
   }
 
+  @Test public void testEquals2() {
+   Schema schema1 = Schema.createRecord("r", null, "x", false);
+   List<Field> fields1 = new ArrayList<Field>();
+   fields1.add(new Field("a", Schema.create(Schema.Type.STRING), null, null,
+                         Field.Order.IGNORE));
+   schema1.setFields(fields1);
+
+   // only differs in field order
+   Schema schema2 = Schema.createRecord("r", null, "x", false);
+   List<Field> fields2 = new ArrayList<Field>();
+   fields2.add(new Field("a", Schema.create(Schema.Type.STRING), null, null,
+                         Field.Order.ASCENDING));
+   schema2.setFields(fields2);
+
+   GenericRecord record1 = new GenericData.Record(schema1);
+   record1.put("a", "1");
+
+   GenericRecord record2 = new GenericData.Record(schema2);
+   record2.put("a", "2");
+
+   assertFalse(record2.equals(record1));
+   assertFalse(record1.equals(record2));
+  }
+
   @Test
   public void testRecordGetFieldDoesntExist() throws Exception {
     List<Field> fields = new ArrayList<Field>();

Modified: avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java?rev=1339387&r1=1339386&r2=1339387&view=diff
==============================================================================
--- avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java (original)
+++ avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java Wed May 16 21:57:46
2012
@@ -191,6 +191,10 @@ public class TestSchema {
       +"[{\"name\":\"f\", \"type\":\"long\", \"foo\":\"bar\"}]}";
     Schema schema = Schema.parse(recordJson);
 
+    GenericData.Record record = new GenericData.Record(schema);
+    record.put("f", 11L);
+    check(recordJson, "{\"f\":11}", record, false);
+
     // test field props
     assertEquals("bar", schema.getField("f").getProp("foo"));
     assertEquals("bar", Schema.parse(schema.toString())
@@ -198,9 +202,6 @@ public class TestSchema {
     schema.getField("f").addProp("baz", "boo");
     assertEquals("boo", schema.getField("f").getProp("baz"));
 
-    GenericData.Record record = new GenericData.Record(schema);
-    record.put("f", 11L);
-    check(recordJson, "{\"f\":11}", record, false);
     checkParseError("{\"type\":\"record\"}");
     checkParseError("{\"type\":\"record\",\"name\":\"X\"}");
     checkParseError("{\"type\":\"record\",\"name\":\"X\",\"fields\":\"Y\"}");



Mime
View raw message