-
Notifications
You must be signed in to change notification settings - Fork 29k
SPARK-1628: Add missing hashCode methods in Partitioner subclasses #549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,6 +83,8 @@ class HashPartitioner(partitions: Int) extends Partitioner { | |
| case _ => | ||
| false | ||
| } | ||
|
|
||
| override def hashCode: Int = numPartitions | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -119,7 +121,7 @@ class RangePartitioner[K : Ordering : ClassTag, V]( | |
| } | ||
| } | ||
|
|
||
| def numPartitions = partitions | ||
| def numPartitions = rangeBounds.length + 1 | ||
|
|
||
| private val binarySearch: ((Array[K], K) => Int) = CollectionsUtils.makeBinarySearch[K] | ||
|
|
||
|
|
@@ -155,4 +157,17 @@ class RangePartitioner[K : Ordering : ClassTag, V]( | |
| case _ => | ||
| false | ||
| } | ||
|
|
||
|
|
||
| override def hashCode(): Int = { | ||
| val prime = 31 | ||
| var result = 1 | ||
| var i = 0 | ||
| while (i < rangeBounds.length) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this be simplified a lot with Arrays.hashCode()?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is not a generics
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Darn,
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe Scala compiler can not determine that using which one here: Arrays.hashCode(Object[]), Arrays.hashCode(int[]), or Arrays.hashCode(double[])... |
||
| result = prime * result + rangeBounds(i).hashCode | ||
| i += 1 | ||
| } | ||
| result = prime * result + ascending.hashCode | ||
| result | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If using
numPartitions = partitions, there is a chance thatp1 == p2 && p1.numPartitions != p2.numPartitionsis true. For example, ifrdd.sampleis empty,p1 = new RangePartitioner[...](10, rdd, true), andp2 = new RangePartitioner[...](1, rdd, true).That's confusing. So I changed
partitionstorangeBounds.length + 1.