From 93513df691c2efc4e0f223459dd2ce7bc950864d Mon Sep 17 00:00:00 2001 From: Andrew Ash Date: Sun, 15 Jun 2014 14:33:57 -0700 Subject: [PATCH] SPARK-2148 Add link to requirements for custom equals() and hashcode() methods --- docs/programming-guide.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/programming-guide.md b/docs/programming-guide.md index ef0c0e34301f3..51d0cc9fa3931 100644 --- a/docs/programming-guide.md +++ b/docs/programming-guide.md @@ -762,6 +762,11 @@ val counts = pairs.reduceByKey((a, b) => a + b) We could also use `counts.sortByKey()`, for example, to sort the pairs alphabetically, and finally `counts.collect()` to bring them back to the driver program as an array of objects. +**Note:** when using custom objects as the key in key-value pair operations, you must be sure that a +custom `equals()` method is accompanied with a matching `hashCode()` method. For full details, see +the contract outlined in the [Object.hashCode() +documentation](http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#hashCode()) +
@@ -794,6 +799,10 @@ JavaPairRDD counts = pairs.reduceByKey((a, b) -> a + b); We could also use `counts.sortByKey()`, for example, to sort the pairs alphabetically, and finally `counts.collect()` to bring them back to the driver program as an array of objects. +**Note:** when using custom objects as the key in key-value pair operations, you must be sure that a +custom `equals()` method is accompanied with a matching `hashCode()` method. For full details, see +the contract outlined in the [Object.hashCode() +documentation](http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#hashCode())