Skip to content

Commit 1c2dbec

Browse files
committed
minor fix for refactoring join code
1 parent 4eec962 commit 1c2dbec

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

pkg/R/RDD.R

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,8 +1614,7 @@ setMethod("join",
16141614
rdd2Tagged <- lapply(rdd2, function(x) { list(x[[1]], list(2L, x[[2]])) })
16151615

16161616
doJoin <- function(v) {
1617-
result <- joinTaggedList(v, list(FALSE, FALSE))
1618-
result
1617+
joinTaggedList(v, list(FALSE, FALSE))
16191618
}
16201619

16211620
joined <- flatMapValues(groupByKey(unionRDD(rdd1Tagged, rdd2Tagged), numPartitions), doJoin)
@@ -1654,8 +1653,7 @@ setMethod("leftOuterJoin",
16541653
rdd2Tagged <- lapply(rdd2, function(x) { list(x[[1]], list(2L, x[[2]])) })
16551654

16561655
doJoin <- function(v) {
1657-
result <- joinTaggedList(v, list(FALSE, TRUE))
1658-
result
1656+
joinTaggedList(v, list(FALSE, TRUE))
16591657
}
16601658

16611659
joined <- flatMapValues(groupByKey(unionRDD(rdd1Tagged, rdd2Tagged), numPartitions), doJoin)
@@ -1694,8 +1692,7 @@ setMethod("rightOuterJoin",
16941692
rdd2Tagged <- lapply(rdd2, function(x) { list(x[[1]], list(2L, x[[2]])) })
16951693

16961694
doJoin <- function(v) {
1697-
result <- joinTaggedList(v, list(TRUE, FALSE))
1698-
result
1695+
joinTaggedList(v, list(TRUE, FALSE))
16991696
}
17001697

17011698
joined <- flatMapValues(groupByKey(unionRDD(rdd1Tagged, rdd2Tagged), numPartitions), doJoin)
@@ -1740,8 +1737,7 @@ setMethod("fullOuterJoin",
17401737
rdd2Tagged <- lapply(rdd2, function(x) { list(x[[1]], list(2L, x[[2]])) })
17411738

17421739
doJoin <- function(v) {
1743-
result <- joinTaggedList(v, list(TRUE, TRUE))
1744-
result
1740+
joinTaggedList(v, list(TRUE, TRUE))
17451741
}
17461742

17471743
joined <- flatMapValues(groupByKey(unionRDD(rdd1Tagged, rdd2Tagged), numPartitions), doJoin)

pkg/R/utils.R

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,14 @@ sortKeyValueList <- function(kv_list) {
219219
kv_list[order(keys)]
220220
}
221221

222-
## Utility function to generate compact R lists from grouped rdd
223-
# Used in Join-family functions
222+
# Utility function to generate compact R lists from grouped rdd
223+
# Used in Join-family functions
224+
# param:
225+
# tagged_list R list generated via groupByKey with tags(1L, 2L, ...)
226+
# cnull Boolean list where each element determines whether the corresponding list should
227+
# be converted to list(NULL)
224228
genCompactLists <- function(tagged_list, cnull) {
225229
len <- length(tagged_list)
226-
num <- length(cnull)
227230
lists <- list(vector("list", len), vector("list", len))
228231
index <- list(1, 1)
229232

@@ -234,8 +237,8 @@ genCompactLists <- function(tagged_list, cnull) {
234237
index[[tag]] <- idx + 1
235238
}
236239

237-
len <- lapply(index, function(x) x-1)
238-
for (i in (1:num)) {
240+
len <- lapply(index, function(x) x - 1)
241+
for (i in (1:2)) {
239242
if (cnull[[i]] && len[[i]] == 0) {
240243
lists[[i]] <- list(NULL)
241244
} else {
@@ -246,8 +249,10 @@ genCompactLists <- function(tagged_list, cnull) {
246249
lists
247250
}
248251

249-
## Utility function to merge compact R lists
250-
# Used in Join-family functions
252+
# Utility function to merge compact R lists
253+
# Used in Join-family functions
254+
# param:
255+
# left/right Two compact lists ready for Cartesian product
251256
mergeCompactLists <- function(left, right) {
252257
result <- list()
253258
length(result) <- length(left) * length(right)
@@ -261,10 +266,13 @@ mergeCompactLists <- function(left, right) {
261266
result
262267
}
263268

264-
## Utility function to wrapper above two operations
265-
# Used in Join-family functions
269+
# Utility function to wrapper above two operations
270+
# Used in Join-family functions
271+
# param (same as genCompactLists):
272+
# tagged_list R list generated via groupByKey with tags(1L, 2L, ...)
273+
# cnull Boolean list where each element determines whether the corresponding list should
274+
# be converted to list(NULL)
266275
joinTaggedList <- function(tagged_list, cnull) {
267276
lists <- genCompactLists(tagged_list, cnull)
268-
result <- mergeCompactLists(lists[[1]], lists[[2]])
269-
result
277+
mergeCompactLists(lists[[1]], lists[[2]])
270278
}

0 commit comments

Comments
 (0)