Skip to content

Commit 7e8caa3

Browse files
shivaramDavies Liu
authored andcommitted
Merge pull request #246 from hlin09/fixCombineByKey
Fixes combineByKey
1 parent ed66c81 commit 7e8caa3

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

R/pkg/R/pairRDD.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ setMethod("combineByKey",
428428
pred <- function(item) exists(item$hash, keys)
429429
lapply(part,
430430
function(item) {
431-
item$hash <- as.character(item[[1]])
431+
item$hash <- as.character(hashCode(item[[1]]))
432432
updateOrCreatePair(item, keys, combiners, pred, mergeValue, createCombiner)
433433
})
434434
convertEnvsToList(keys, combiners)
@@ -441,7 +441,7 @@ setMethod("combineByKey",
441441
pred <- function(item) exists(item$hash, keys)
442442
lapply(part,
443443
function(item) {
444-
item$hash <- as.character(item[[1]])
444+
item$hash <- as.character(hashCode(item[[1]]))
445445
updateOrCreatePair(item, keys, combiners, pred, mergeCombiners, identity)
446446
})
447447
convertEnvsToList(keys, combiners)

R/pkg/inst/tests/test_shuffle.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@ test_that("combineByKey for doubles", {
8787
expect_equal(sortKeyValueList(actual), sortKeyValueList(expected))
8888
})
8989

90+
test_that("combineByKey for characters", {
91+
stringKeyRDD <- parallelize(sc,
92+
list(list("max", 1L), list("min", 2L),
93+
list("other", 3L), list("max", 4L)), 2L)
94+
reduced <- combineByKey(stringKeyRDD,
95+
function(x) { x }, "+", "+", 2L)
96+
actual <- collect(reduced)
97+
98+
expected <- list(list("max", 5L), list("min", 2L), list("other", 3L))
99+
expect_equal(sortKeyValueList(actual), sortKeyValueList(expected))
100+
})
101+
90102
test_that("aggregateByKey", {
91103
# test aggregateByKey for int keys
92104
rdd <- parallelize(sc, list(list(1, 1), list(1, 2), list(2, 3), list(2, 4)))

0 commit comments

Comments
 (0)