Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion R/pkg/NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Imports from base R
importFrom(methods, setGeneric, setMethod, setOldClass)
useDynLib(SparkR, stringHashCode)

# Disable native libraries till we figure out how to package it
# See SPARKR-7839
#useDynLib(SparkR, stringHashCode)

# S3 methods exported
export("sparkR.init")
Expand Down
38 changes: 37 additions & 1 deletion R/pkg/R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,49 @@ hashCode <- function(key) {
intBits <- packBits(rawToBits(rawVec), "integer")
as.integer(bitwXor(intBits[2], intBits[1]))
} else if (class(key) == "character") {
.Call("stringHashCode", key)
# TODO: SPARK-7839 means we might not have the native library available
if (is.loaded("stringHashCode")) {
.Call("stringHashCode", key)
} else {
n <- nchar(key)
if (n == 0) {
0L
} else {
asciiVals <- sapply(charToRaw(key), function(x) { strtoi(x, 16L) })
hashC <- 0
for (k in 1:length(asciiVals)) {
hashC <- mult31AndAdd(hashC, asciiVals[k])
}
as.integer(hashC)
}
}
} else {
warning(paste("Could not hash object, returning 0", sep = ""))
as.integer(0)
}
}

# Helper function used to wrap a 'numeric' value to integer bounds.
# Useful for implementing C-like integer arithmetic
wrapInt <- function(value) {
if (value > .Machine$integer.max) {
value <- value - 2 * .Machine$integer.max - 2
} else if (value < -1 * .Machine$integer.max) {
value <- 2 * .Machine$integer.max + value + 2
}
value
}

# Multiply `val` by 31 and add `addVal` to the result. Ensures that
# integer-overflows are handled at every step.
mult31AndAdd <- function(val, addVal) {
vec <- c(bitwShiftL(val, c(4,3,2,1,0)), addVal)
Reduce(function(a, b) {
wrapInt(as.numeric(a) + as.numeric(b))
},
vec)
}

# Create a new RDD with serializedMode == "byte".
# Return itself if already in "byte" format.
serializeToBytes <- function(rdd) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions make-distribution.sh
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ cp "$SPARK_HOME"/conf/*.template "$DISTDIR"/conf
cp "$SPARK_HOME/README.md" "$DISTDIR"
cp -r "$SPARK_HOME/bin" "$DISTDIR"
cp -r "$SPARK_HOME/python" "$DISTDIR"
mkdir -p "$DISTDIR"/R/lib
cp -r "$SPARK_HOME/R/lib/SparkR" "$DISTDIR"/R/lib
cp -r "$SPARK_HOME/sbin" "$DISTDIR"
cp -r "$SPARK_HOME/ec2" "$DISTDIR"

Expand Down