Skip to content

Commit caf0136

Browse files
Sun Ruishivaram
authored andcommitted
[SPARK-6852] [SPARKR] Accept numeric as numPartitions in SparkR.
Author: Sun Rui <[email protected]> Closes #5613 from sun-rui/SPARK-6852 and squashes the following commits: abaf02e [Sun Rui] Change the type of default numPartitions from integer to numeric in generics.R. 29d67c1 [Sun Rui] [SPARK-6852][SPARKR] Accept numeric as numPartitions in SparkR.
1 parent ebb77b2 commit caf0136

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

R/pkg/R/RDD.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ setMethod("keyBy",
967967
setMethod("repartition",
968968
signature(x = "RDD", numPartitions = "numeric"),
969969
function(x, numPartitions) {
970-
coalesce(x, numToInt(numPartitions), TRUE)
970+
coalesce(x, numPartitions, TRUE)
971971
})
972972

973973
#' Return a new RDD that is reduced into numPartitions partitions.

R/pkg/R/generics.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ setGeneric("countByValue", function(x) { standardGeneric("countByValue") })
6060

6161
#' @rdname distinct
6262
#' @export
63-
setGeneric("distinct", function(x, numPartitions = 1L) { standardGeneric("distinct") })
63+
setGeneric("distinct", function(x, numPartitions = 1) { standardGeneric("distinct") })
6464

6565
#' @rdname filterRDD
6666
#' @export
@@ -182,7 +182,7 @@ setGeneric("setName", function(x, name) { standardGeneric("setName") })
182182
#' @rdname sortBy
183183
#' @export
184184
setGeneric("sortBy",
185-
function(x, func, ascending = TRUE, numPartitions = 1L) {
185+
function(x, func, ascending = TRUE, numPartitions = 1) {
186186
standardGeneric("sortBy")
187187
})
188188

@@ -244,7 +244,7 @@ setGeneric("flatMapValues", function(X, FUN) { standardGeneric("flatMapValues")
244244

245245
#' @rdname intersection
246246
#' @export
247-
setGeneric("intersection", function(x, other, numPartitions = 1L) {
247+
setGeneric("intersection", function(x, other, numPartitions = 1) {
248248
standardGeneric("intersection") })
249249

250250
#' @rdname keys
@@ -346,21 +346,21 @@ setGeneric("rightOuterJoin", function(x, y, numPartitions) { standardGeneric("ri
346346
#' @rdname sortByKey
347347
#' @export
348348
setGeneric("sortByKey",
349-
function(x, ascending = TRUE, numPartitions = 1L) {
349+
function(x, ascending = TRUE, numPartitions = 1) {
350350
standardGeneric("sortByKey")
351351
})
352352

353353
#' @rdname subtract
354354
#' @export
355355
setGeneric("subtract",
356-
function(x, other, numPartitions = 1L) {
356+
function(x, other, numPartitions = 1) {
357357
standardGeneric("subtract")
358358
})
359359

360360
#' @rdname subtractByKey
361361
#' @export
362362
setGeneric("subtractByKey",
363-
function(x, other, numPartitions = 1L) {
363+
function(x, other, numPartitions = 1) {
364364
standardGeneric("subtractByKey")
365365
})
366366

R/pkg/R/pairRDD.R

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ setMethod("flatMapValues",
190190
#' @rdname partitionBy
191191
#' @aliases partitionBy,RDD,integer-method
192192
setMethod("partitionBy",
193-
signature(x = "RDD", numPartitions = "integer"),
193+
signature(x = "RDD", numPartitions = "numeric"),
194194
function(x, numPartitions, partitionFunc = hashCode) {
195195

196196
#if (missing(partitionFunc)) {
@@ -211,7 +211,7 @@ setMethod("partitionBy",
211211
# the content (key-val pairs).
212212
pairwiseRRDD <- newJObject("org.apache.spark.api.r.PairwiseRRDD",
213213
callJMethod(jrdd, "rdd"),
214-
as.integer(numPartitions),
214+
numToInt(numPartitions),
215215
serializedHashFuncBytes,
216216
getSerializedMode(x),
217217
packageNamesArr,
@@ -221,7 +221,7 @@ setMethod("partitionBy",
221221

222222
# Create a corresponding partitioner.
223223
rPartitioner <- newJObject("org.apache.spark.HashPartitioner",
224-
as.integer(numPartitions))
224+
numToInt(numPartitions))
225225

226226
# Call partitionBy on the obtained PairwiseRDD.
227227
javaPairRDD <- callJMethod(pairwiseRRDD, "asJavaPairRDD")
@@ -256,7 +256,7 @@ setMethod("partitionBy",
256256
#' @rdname groupByKey
257257
#' @aliases groupByKey,RDD,integer-method
258258
setMethod("groupByKey",
259-
signature(x = "RDD", numPartitions = "integer"),
259+
signature(x = "RDD", numPartitions = "numeric"),
260260
function(x, numPartitions) {
261261
shuffled <- partitionBy(x, numPartitions)
262262
groupVals <- function(part) {
@@ -315,7 +315,7 @@ setMethod("groupByKey",
315315
#' @rdname reduceByKey
316316
#' @aliases reduceByKey,RDD,integer-method
317317
setMethod("reduceByKey",
318-
signature(x = "RDD", combineFunc = "ANY", numPartitions = "integer"),
318+
signature(x = "RDD", combineFunc = "ANY", numPartitions = "numeric"),
319319
function(x, combineFunc, numPartitions) {
320320
reduceVals <- function(part) {
321321
vals <- new.env()
@@ -422,7 +422,7 @@ setMethod("reduceByKeyLocally",
422422
#' @aliases combineByKey,RDD,ANY,ANY,ANY,integer-method
423423
setMethod("combineByKey",
424424
signature(x = "RDD", createCombiner = "ANY", mergeValue = "ANY",
425-
mergeCombiners = "ANY", numPartitions = "integer"),
425+
mergeCombiners = "ANY", numPartitions = "numeric"),
426426
function(x, createCombiner, mergeValue, mergeCombiners, numPartitions) {
427427
combineLocally <- function(part) {
428428
combiners <- new.env()
@@ -483,7 +483,7 @@ setMethod("combineByKey",
483483
#' @aliases aggregateByKey,RDD,ANY,ANY,ANY,integer-method
484484
setMethod("aggregateByKey",
485485
signature(x = "RDD", zeroValue = "ANY", seqOp = "ANY",
486-
combOp = "ANY", numPartitions = "integer"),
486+
combOp = "ANY", numPartitions = "numeric"),
487487
function(x, zeroValue, seqOp, combOp, numPartitions) {
488488
createCombiner <- function(v) {
489489
do.call(seqOp, list(zeroValue, v))
@@ -514,7 +514,7 @@ setMethod("aggregateByKey",
514514
#' @aliases foldByKey,RDD,ANY,ANY,integer-method
515515
setMethod("foldByKey",
516516
signature(x = "RDD", zeroValue = "ANY",
517-
func = "ANY", numPartitions = "integer"),
517+
func = "ANY", numPartitions = "numeric"),
518518
function(x, zeroValue, func, numPartitions) {
519519
aggregateByKey(x, zeroValue, func, func, numPartitions)
520520
})
@@ -553,7 +553,7 @@ setMethod("join",
553553
joinTaggedList(v, list(FALSE, FALSE))
554554
}
555555

556-
joined <- flatMapValues(groupByKey(unionRDD(xTagged, yTagged), numToInt(numPartitions)),
556+
joined <- flatMapValues(groupByKey(unionRDD(xTagged, yTagged), numPartitions),
557557
doJoin)
558558
})
559559

@@ -582,7 +582,7 @@ setMethod("join",
582582
#' @rdname join-methods
583583
#' @aliases leftOuterJoin,RDD,RDD-method
584584
setMethod("leftOuterJoin",
585-
signature(x = "RDD", y = "RDD", numPartitions = "integer"),
585+
signature(x = "RDD", y = "RDD", numPartitions = "numeric"),
586586
function(x, y, numPartitions) {
587587
xTagged <- lapply(x, function(i) { list(i[[1]], list(1L, i[[2]])) })
588588
yTagged <- lapply(y, function(i) { list(i[[1]], list(2L, i[[2]])) })
@@ -619,7 +619,7 @@ setMethod("leftOuterJoin",
619619
#' @rdname join-methods
620620
#' @aliases rightOuterJoin,RDD,RDD-method
621621
setMethod("rightOuterJoin",
622-
signature(x = "RDD", y = "RDD", numPartitions = "integer"),
622+
signature(x = "RDD", y = "RDD", numPartitions = "numeric"),
623623
function(x, y, numPartitions) {
624624
xTagged <- lapply(x, function(i) { list(i[[1]], list(1L, i[[2]])) })
625625
yTagged <- lapply(y, function(i) { list(i[[1]], list(2L, i[[2]])) })
@@ -659,7 +659,7 @@ setMethod("rightOuterJoin",
659659
#' @rdname join-methods
660660
#' @aliases fullOuterJoin,RDD,RDD-method
661661
setMethod("fullOuterJoin",
662-
signature(x = "RDD", y = "RDD", numPartitions = "integer"),
662+
signature(x = "RDD", y = "RDD", numPartitions = "numeric"),
663663
function(x, y, numPartitions) {
664664
xTagged <- lapply(x, function(i) { list(i[[1]], list(1L, i[[2]])) })
665665
yTagged <- lapply(y, function(i) { list(i[[1]], list(2L, i[[2]])) })

0 commit comments

Comments
 (0)