Skip to content

Commit 9387402

Browse files
author
Davies Liu
committed
fix style
1 parent 40199eb commit 9387402

6 files changed

Lines changed: 36 additions & 41 deletions

File tree

R/pkg/NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ exportMethods(
5353
"reduceByKeyLocally",
5454
"repartition",
5555
"rightOuterJoin",
56-
"sampleRDD",
5756
"sampleByKey",
57+
"sampleRDD",
5858
"saveAsTextFile",
5959
"saveAsObjectFile",
6060
"sortBy",

R/pkg/R/RDD.R

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,45 +1496,45 @@ setMethod("zipRDD",
14961496
stop("Can only zip RDDs which have the same number of partitions.")
14971497
}
14981498

1499-
if (getSerializedMode(x) != getSerializedMode(other) ||
1499+
if (getSerializedMode(x) != getSerializedMode(other) ||
15001500
getSerializedMode(x) == "byte") {
15011501
# Append the number of elements in each partition to that partition so that we can later
15021502
# check if corresponding partitions of both RDDs have the same number of elements.
15031503
#
1504-
# Note that this appending also serves the purpose of reserialization, because even if
1504+
# Note that this appending also serves the purpose of reserialization, because even if
15051505
# any RDD is serialized, we need to reserialize it to make sure its partitions are encoded
15061506
# as a single byte array. For example, partitions of an RDD generated from partitionBy()
1507-
# may be encoded as multiple byte arrays.
1507+
# may be encoded as multiple byte arrays.
15081508
appendLength <- function(part) {
15091509
part[[length(part) + 1]] <- length(part) + 1
15101510
part
15111511
}
15121512
x <- lapplyPartition(x, appendLength)
15131513
other <- lapplyPartition(other, appendLength)
15141514
}
1515-
1515+
15161516
zippedJRDD <- callJMethod(getJRDD(x), "zip", getJRDD(other))
15171517
# The zippedRDD's elements are of scala Tuple2 type. The serialized
15181518
# flag Here is used for the elements inside the tuples.
15191519
serializerMode <- getSerializedMode(x)
15201520
zippedRDD <- RDD(zippedJRDD, serializerMode)
1521-
1521+
15221522
partitionFunc <- function(split, part) {
15231523
len <- length(part)
15241524
if (len > 0) {
15251525
if (serializerMode == "byte") {
15261526
lengthOfValues <- part[[len]]
15271527
lengthOfKeys <- part[[len - lengthOfValues]]
15281528
stopifnot(len == lengthOfKeys + lengthOfValues)
1529-
1529+
15301530
# check if corresponding partitions of both RDDs have the same number of elements.
15311531
if (lengthOfKeys != lengthOfValues) {
15321532
stop("Can only zip RDDs with same number of elements in each pair of corresponding partitions.")
15331533
}
1534-
1534+
15351535
if (lengthOfKeys > 1) {
15361536
keys <- part[1 : (lengthOfKeys - 1)]
1537-
values <- part[(lengthOfKeys + 1) : (len - 1)]
1537+
values <- part[(lengthOfKeys + 1) : (len - 1)]
15381538
} else {
15391539
keys <- list()
15401540
values <- list()
@@ -1557,7 +1557,7 @@ setMethod("zipRDD",
15571557
part
15581558
}
15591559
}
1560-
1560+
15611561
PipelinedRDD(zippedRDD, partitionFunc)
15621562
})
15631563

@@ -1585,17 +1585,16 @@ setMethod("subtract",
15851585
mapFunction <- function(e) { list(e, NA) }
15861586
rdd1 <- map(x, mapFunction)
15871587
rdd2 <- map(other, mapFunction)
1588-
15891588
keys(subtractByKey(rdd1, rdd2, numPartitions))
15901589
})
15911590

15921591
#' Intersection of this RDD and another one.
15931592
#'
15941593
#' Return the intersection of this RDD and another one.
1595-
#' The output will not contain any duplicate elements,
1594+
#' The output will not contain any duplicate elements,
15961595
#' even if the input RDDs did. Performs a hash partition
15971596
#' across the cluster.
1598-
#' Note that this method performs a shuffle internally.
1597+
#' Note that this method performs a shuffle internally.
15991598
#'
16001599
#' @param x An RDD.
16011600
#' @param other An RDD.
@@ -1616,7 +1615,7 @@ setMethod("intersection",
16161615
function(x, other, numPartitions = SparkR::numPartitions(x)) {
16171616
rdd1 <- map(x, function(v) { list(v, NA) })
16181617
rdd2 <- map(other, function(v) { list(v, NA) })
1619-
1618+
16201619
filterFunction <- function(elem) {
16211620
iters <- elem[[2]]
16221621
all(as.vector(

R/pkg/R/generics.R

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,6 @@ setGeneric("minimum", function(x) { standardGeneric("minimum") })
134134
#' @export
135135
setGeneric("sumRDD", function(x) { standardGeneric("sumRDD") })
136136

137-
#' @rdname foreach
138-
#' @export
139-
setGeneric("foreach", function(x, func) { standardGeneric("foreach") })
140-
141137
#' @rdname name
142138
#' @export
143139
setGeneric("name", function(x) { standardGeneric("name") })
@@ -269,6 +265,10 @@ setGeneric("sampleByKey",
269265
standardGeneric("sampleByKey")
270266
})
271267

268+
#' @rdname values
269+
#' @export
270+
setGeneric("values", function(x) { standardGeneric("values") })
271+
272272

273273
############ Shuffle Functions ############
274274

@@ -349,18 +349,18 @@ setGeneric("sortByKey",
349349
standardGeneric("sortByKey")
350350
})
351351

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

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

366366
################### Broadcast Variable Methods #################
@@ -462,10 +462,6 @@ setGeneric("showDF", function(x,...) { standardGeneric("showDF") })
462462
#' @export
463463
setGeneric("sortDF", function(x, col, ...) { standardGeneric("sortDF") })
464464

465-
#' @rdname subtract
466-
#' @export
467-
setGeneric("subtract", function(x, y) { standardGeneric("subtract") })
468-
469465
#' @rdname tojson
470466
#' @export
471467
setGeneric("toJSON", function(x) { standardGeneric("toJSON") })

R/pkg/R/pairRDD.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ setMethod("subtractByKey",
813813
iters <- elem[[2]]
814814
(length(iters[[1]]) > 0) && (length(iters[[2]]) == 0)
815815
}
816-
816+
817817
flatMapValues(filterRDD(cogroup(x,
818818
other,
819819
numPartitions = numPartitions),

R/pkg/inst/tests/test_rdd.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -481,12 +481,12 @@ test_that("subtract() on RDDs", {
481481
actual <- collect(subtract(rdd1, rdd2))
482482
expect_equal(as.list(sort(as.vector(actual, mode="integer"))),
483483
l)
484-
484+
485485
rdd2 <- parallelize(sc, list(2, 4))
486486
actual <- collect(subtract(rdd1, rdd2))
487487
expect_equal(as.list(sort(as.vector(actual, mode="integer"))),
488488
list(1, 1, 3))
489-
489+
490490
l <- list("a", "a", "b", "b", "c", "d")
491491
rdd1 <- parallelize(sc, l)
492492
rdd2 <- parallelize(sc, list("b", "d"))
@@ -499,21 +499,21 @@ test_that("subtractByKey() on pairwise RDDs", {
499499
l <- list(list("a", 1), list("b", 4),
500500
list("b", 5), list("a", 2))
501501
rdd1 <- parallelize(sc, l)
502-
502+
503503
# subtractByKey by itself
504504
actual <- collect(subtractByKey(rdd1, rdd1))
505505
expect_equal(actual, list())
506-
506+
507507
# subtractByKey by an empty RDD
508508
rdd2 <- parallelize(sc, list())
509509
actual <- collect(subtractByKey(rdd1, rdd2))
510510
expect_equal(sortKeyValueList(actual),
511511
sortKeyValueList(l))
512-
512+
513513
rdd2 <- parallelize(sc, list(list("a", 3), list("c", 1)))
514514
actual <- collect(subtractByKey(rdd1, rdd2))
515515
expect_equal(actual,
516-
list(list("b", 4), list("b", 5)))
516+
list(list("b", 4), list("b", 5)))
517517

518518
l <- list(list(1, 1), list(2, 4),
519519
list(2, 5), list(1, 2))
@@ -528,12 +528,12 @@ test_that("intersection() on RDDs", {
528528
# intersection with self
529529
actual <- collect(intersection(rdd, rdd))
530530
expect_equal(sort(as.integer(actual)), nums)
531-
531+
532532
# intersection with an empty RDD
533533
emptyRdd <- parallelize(sc, list())
534534
actual <- collect(intersection(rdd, emptyRdd))
535535
expect_equal(actual, list())
536-
536+
537537
rdd1 <- parallelize(sc, list(1, 10, 2, 3, 4, 5))
538538
rdd2 <- parallelize(sc, list(1, 6, 2, 3, 7, 8))
539539
actual <- collect(intersection(rdd1, rdd2))

R/pkg/inst/tests/test_shuffle.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ test_that("combineByKey for doubles", {
8888
})
8989

9090
test_that("combineByKey for characters", {
91-
stringKeyRDD <- parallelize(sc,
92-
list(list("max", 1L), list("min", 2L),
91+
stringKeyRDD <- parallelize(sc,
92+
list(list("max", 1L), list("min", 2L),
9393
list("other", 3L), list("max", 4L)), 2L)
94-
reduced <- combineByKey(stringKeyRDD,
94+
reduced <- combineByKey(stringKeyRDD,
9595
function(x) { x }, "+", "+", 2L)
9696
actual <- collect(reduced)
97-
97+
9898
expected <- list(list("max", 5L), list("min", 2L), list("other", 3L))
9999
expect_equal(sortKeyValueList(actual), sortKeyValueList(expected))
100100
})

0 commit comments

Comments
 (0)