Fix JoinKey sort order and allow comparison with other types. #72

Merged
merged 1 commit into from Sep 4, 2013

Conversation

Projects
None yet
2 participants
Contributor

jkleint commented May 8, 2013

Primary and secondary JoinKeys seem to compare backwards when using the Python backend (e.g., with mapredtest), due to this code in JoinKey.__cmp__():

return cmp(self.isprimary, other.isprimary)

because when comparing the .isprimary attribute of a JoinKey, False sorts before True.

This isn't noticed using the Unix or Hadoop backends because isprimary serializes to 1 for primary and 2 for secondary.

This patch also allows comparing a JoinKey to any other type without crashing (it arbitrarily sorts first). This is useful in a situation like:

def reducer(keysvals):
    key, val = next(keysvals, (defaultkey, defaultval))
    if key == defaultkey:
        ...

@klbostee klbostee added a commit that referenced this pull request Sep 4, 2013

@klbostee klbostee Merge pull request #72 from jkleint/master
Fix JoinKey sort order and allow comparison with other types.
aef376f

@klbostee klbostee merged commit aef376f into klbostee:master Sep 4, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment