[jira] Created: (NUTCH-263) MapWritable.equals() doesn't work properly

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] Created: (NUTCH-263) MapWritable.equals() doesn't work properly

JIRA jira@apache.org
MapWritable.equals() doesn't work properly
------------------------------------------

         Key: NUTCH-263
         URL: http://issues.apache.org/jira/browse/NUTCH-263
     Project: Nutch
        Type: Bug

    Versions: 0.8-dev    
    Reporter: Andrzej Bialecki


MapWritable.equals() is sensitive to the order in which map entries have been created. E.g. this fails but it should succeed:

    MapWritable map1 = new MapWritable();
    MapWritable map2 = new MapWritable();
    map1.put(new UTF8("key1"), new UTF8("val1"));
    map1.put(new UTF8("key2"), new UTF8("val2"));
    map2.put(new UTF8("key2"), new UTF8("val2"));
    map2.put(new UTF8("key1"), new UTF8("val1"));
    assertTrue(map1.equals(map2));

Users expect that this should not be the case, i.e. this class should follow the same rules as Map.equals() ("Returns true if the given object is also a map and the two Maps represent the same mappings").

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (NUTCH-263) MapWritable.equals() doesn't work properly

JIRA jira@apache.org
     [ http://issues.apache.org/jira/browse/NUTCH-263?page=all ]

Andrzej Bialecki  updated NUTCH-263:
------------------------------------

    Attachment: patch1.txt

This patch fixes the issue, but at the cost of creating new objects... improvements are welcome.

> MapWritable.equals() doesn't work properly
> ------------------------------------------
>
>          Key: NUTCH-263
>          URL: http://issues.apache.org/jira/browse/NUTCH-263
>      Project: Nutch
>         Type: Bug

>     Versions: 0.8-dev
>     Reporter: Andrzej Bialecki
>  Attachments: patch1.txt
>
> MapWritable.equals() is sensitive to the order in which map entries have been created. E.g. this fails but it should succeed:
>     MapWritable map1 = new MapWritable();
>     MapWritable map2 = new MapWritable();
>     map1.put(new UTF8("key1"), new UTF8("val1"));
>     map1.put(new UTF8("key2"), new UTF8("val2"));
>     map2.put(new UTF8("key2"), new UTF8("val2"));
>     map2.put(new UTF8("key1"), new UTF8("val1"));
>     assertTrue(map1.equals(map2));
> Users expect that this should not be the case, i.e. this class should follow the same rules as Map.equals() ("Returns true if the given object is also a map and the two Maps represent the same mappings").

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (NUTCH-263) MapWritable.equals() doesn't work properly

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org
    [ http://issues.apache.org/jira/browse/NUTCH-263?page=comments#action_12377749 ]

Jerome Charron commented on NUTCH-263:
--------------------------------------

Andrzej, a small but efficient improvement could be to check the maps sizes prior to any other tests:

if (obj instanceof MapWritable) {
  MapWritable map = (MapWritable) obj;
  if (map.fSize == fSize) {
    ...
  }
}
return false;

No?

> MapWritable.equals() doesn't work properly
> ------------------------------------------
>
>          Key: NUTCH-263
>          URL: http://issues.apache.org/jira/browse/NUTCH-263
>      Project: Nutch
>         Type: Bug

>     Versions: 0.8-dev
>     Reporter: Andrzej Bialecki
>  Attachments: patch1.txt
>
> MapWritable.equals() is sensitive to the order in which map entries have been created. E.g. this fails but it should succeed:
>     MapWritable map1 = new MapWritable();
>     MapWritable map2 = new MapWritable();
>     map1.put(new UTF8("key1"), new UTF8("val1"));
>     map1.put(new UTF8("key2"), new UTF8("val2"));
>     map2.put(new UTF8("key2"), new UTF8("val2"));
>     map2.put(new UTF8("key1"), new UTF8("val1"));
>     assertTrue(map1.equals(map2));
> Users expect that this should not be the case, i.e. this class should follow the same rules as Map.equals() ("Returns true if the given object is also a map and the two Maps represent the same mappings").

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (NUTCH-263) MapWritable.equals() doesn't work properly

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org
    [ http://issues.apache.org/jira/browse/NUTCH-263?page=comments#action_12377752 ]

Andrzej Bialecki  commented on NUTCH-263:
-----------------------------------------

Yes, definitely. I didn't have time to analyze the code so thoroughly (I hope Stefan will pipe in :) ), but the ideal solution would be to avoid creating any objects, even if sizes are equal ...

> MapWritable.equals() doesn't work properly
> ------------------------------------------
>
>          Key: NUTCH-263
>          URL: http://issues.apache.org/jira/browse/NUTCH-263
>      Project: Nutch
>         Type: Bug

>     Versions: 0.8-dev
>     Reporter: Andrzej Bialecki
>  Attachments: patch1.txt
>
> MapWritable.equals() is sensitive to the order in which map entries have been created. E.g. this fails but it should succeed:
>     MapWritable map1 = new MapWritable();
>     MapWritable map2 = new MapWritable();
>     map1.put(new UTF8("key1"), new UTF8("val1"));
>     map1.put(new UTF8("key2"), new UTF8("val2"));
>     map2.put(new UTF8("key2"), new UTF8("val2"));
>     map2.put(new UTF8("key1"), new UTF8("val1"));
>     assertTrue(map1.equals(map2));
> Users expect that this should not be the case, i.e. this class should follow the same rules as Map.equals() ("Returns true if the given object is also a map and the two Maps represent the same mappings").

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply | Threaded
Open this post in threaded view
|

[jira] Closed: (NUTCH-263) MapWritable.equals() doesn't work properly

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org
     [ http://issues.apache.org/jira/browse/NUTCH-263?page=all ]
     
Andrzej Bialecki  closed NUTCH-263:
-----------------------------------

    Resolution: Fixed

Patch applied in rev. 405179. If further improvements are needed please re-open this issue.

> MapWritable.equals() doesn't work properly
> ------------------------------------------
>
>          Key: NUTCH-263
>          URL: http://issues.apache.org/jira/browse/NUTCH-263
>      Project: Nutch
>         Type: Bug

>     Versions: 0.8-dev
>     Reporter: Andrzej Bialecki
>  Attachments: patch1.txt
>
> MapWritable.equals() is sensitive to the order in which map entries have been created. E.g. this fails but it should succeed:
>     MapWritable map1 = new MapWritable();
>     MapWritable map2 = new MapWritable();
>     map1.put(new UTF8("key1"), new UTF8("val1"));
>     map1.put(new UTF8("key2"), new UTF8("val2"));
>     map2.put(new UTF8("key2"), new UTF8("val2"));
>     map2.put(new UTF8("key1"), new UTF8("val1"));
>     assertTrue(map1.equals(map2));
> Users expect that this should not be the case, i.e. this class should follow the same rules as Map.equals() ("Returns true if the given object is also a map and the two Maps represent the same mappings").

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira