@@ -317,7 +317,9 @@ abstract class RDD[T: ClassTag](
317
317
/**
318
318
* Return a new RDD containing the distinct elements in this RDD.
319
319
*/
320
- def distinct (): RDD [T ] = distinct(partitions.length)
320
+ def distinct (): RDD [T ] = withScope {
321
+ distinct(partitions.length)
322
+ }
321
323
322
324
/**
323
325
* Return a new RDD that has exactly numPartitions partitions.
@@ -429,7 +431,7 @@ abstract class RDD[T: ClassTag](
429
431
def takeSample (
430
432
withReplacement : Boolean ,
431
433
num : Int ,
432
- seed : Long = Utils .random.nextLong): Array [T ] = {
434
+ seed : Long = Utils .random.nextLong): Array [T ] = withScope {
433
435
val numStDev = 10.0
434
436
435
437
if (num < 0 ) {
@@ -487,7 +489,9 @@ abstract class RDD[T: ClassTag](
487
489
* Return the union of this RDD and another one. Any identical elements will appear multiple
488
490
* times (use `.distinct()` to eliminate them).
489
491
*/
490
- def ++ (other : RDD [T ]): RDD [T ] = this .union(other)
492
+ def ++ (other : RDD [T ]): RDD [T ] = withScope {
493
+ this .union(other)
494
+ }
491
495
492
496
/**
493
497
* Return this RDD sorted by the given key function.
@@ -567,8 +571,9 @@ abstract class RDD[T: ClassTag](
567
571
* aggregation (such as a sum or average) over each key, using [[PairRDDFunctions.aggregateByKey ]]
568
572
* or [[PairRDDFunctions.reduceByKey ]] will provide much better performance.
569
573
*/
570
- def groupBy [K ](f : T => K )(implicit kt : ClassTag [K ]): RDD [(K , Iterable [T ])] =
574
+ def groupBy [K ](f : T => K )(implicit kt : ClassTag [K ]): RDD [(K , Iterable [T ])] = withScope {
571
575
groupBy[K ](f, defaultPartitioner(this ))
576
+ }
572
577
573
578
/**
574
579
* Return an RDD of grouped elements. Each group consists of a key and a sequence of elements
@@ -579,8 +584,11 @@ abstract class RDD[T: ClassTag](
579
584
* aggregation (such as a sum or average) over each key, using [[PairRDDFunctions.aggregateByKey ]]
580
585
* or [[PairRDDFunctions.reduceByKey ]] will provide much better performance.
581
586
*/
582
- def groupBy [K ](f : T => K , numPartitions : Int )(implicit kt : ClassTag [K ]): RDD [(K , Iterable [T ])] =
587
+ def groupBy [K ](
588
+ f : T => K ,
589
+ numPartitions : Int )(implicit kt : ClassTag [K ]): RDD [(K , Iterable [T ])] = withScope {
583
590
groupBy(f, new HashPartitioner (numPartitions))
591
+ }
584
592
585
593
/**
586
594
* Return an RDD of grouped items. Each group consists of a key and a sequence of elements
@@ -739,7 +747,7 @@ abstract class RDD[T: ClassTag](
739
747
mapPartitionsWithIndex { (index, iter) =>
740
748
val a = constructA(index)
741
749
iter.map(t => {f(t, a); t})
742
- }.foreach(_ => {})
750
+ }
743
751
}
744
752
745
753
/**
0 commit comments