From be0d5d3bbebf0912c27bf41ce27b5ba214e61e19 Mon Sep 17 00:00:00 2001 From: Sean Owen Date: Sat, 23 Apr 2016 10:47:50 -0700 Subject: [SPARK-14873][CORE] Java sampleByKey methods take ju.Map but with Scala Double values; results in type Object ## What changes were proposed in this pull request? Java `sampleByKey` methods should accept `Map` with `java.lang.Double` values ## How was this patch tested? Existing (updated) Jenkins tests Author: Sean Owen Closes #12637 from srowen/SPARK-14873. --- .../scala/org/apache/spark/api/java/JavaPairRDD.scala | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'core/src/main/scala/org/apache') diff --git a/core/src/main/scala/org/apache/spark/api/java/JavaPairRDD.scala b/core/src/main/scala/org/apache/spark/api/java/JavaPairRDD.scala index 2897272a8b..1c95bc4bfc 100644 --- a/core/src/main/scala/org/apache/spark/api/java/JavaPairRDD.scala +++ b/core/src/main/scala/org/apache/spark/api/java/JavaPairRDD.scala @@ -139,9 +139,12 @@ class JavaPairRDD[K, V](val rdd: RDD[(K, V)]) * math.ceil(numItems * samplingRate) over all key values. */ def sampleByKey(withReplacement: Boolean, - fractions: java.util.Map[K, Double], + fractions: java.util.Map[K, jl.Double], seed: Long): JavaPairRDD[K, V] = - new JavaPairRDD[K, V](rdd.sampleByKey(withReplacement, fractions.asScala, seed)) + new JavaPairRDD[K, V](rdd.sampleByKey( + withReplacement, + fractions.asScala.mapValues(_.toDouble).toMap, // map to Scala Double; toMap to serialize + seed)) /** * Return a subset of this RDD sampled by key (via stratified sampling). @@ -154,7 +157,7 @@ class JavaPairRDD[K, V](val rdd: RDD[(K, V)]) * Use Utils.random.nextLong as the default seed for the random number generator. */ def sampleByKey(withReplacement: Boolean, - fractions: java.util.Map[K, Double]): JavaPairRDD[K, V] = + fractions: java.util.Map[K, jl.Double]): JavaPairRDD[K, V] = sampleByKey(withReplacement, fractions, Utils.random.nextLong) /** @@ -168,9 +171,12 @@ class JavaPairRDD[K, V](val rdd: RDD[(K, V)]) * two additional passes. */ def sampleByKeyExact(withReplacement: Boolean, - fractions: java.util.Map[K, Double], + fractions: java.util.Map[K, jl.Double], seed: Long): JavaPairRDD[K, V] = - new JavaPairRDD[K, V](rdd.sampleByKeyExact(withReplacement, fractions.asScala, seed)) + new JavaPairRDD[K, V](rdd.sampleByKeyExact( + withReplacement, + fractions.asScala.mapValues(_.toDouble).toMap, // map to Scala Double; toMap to serialize + seed)) /** * Return a subset of this RDD sampled by key (via stratified sampling) containing exactly @@ -186,7 +192,7 @@ class JavaPairRDD[K, V](val rdd: RDD[(K, V)]) */ def sampleByKeyExact( withReplacement: Boolean, - fractions: java.util.Map[K, Double]): JavaPairRDD[K, V] = + fractions: java.util.Map[K, jl.Double]): JavaPairRDD[K, V] = sampleByKeyExact(withReplacement, fractions, Utils.random.nextLong) /** -- cgit v1.2.3