Skip to content

Commit 4a39cb2

Browse files
author
Marcelo Vanzin
committed
Merge branch 'master' into SPARK-19556
2 parents ab4b5dd + 17eddb3 commit 4a39cb2

File tree

233 files changed

+5982
-2290
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

233 files changed

+5982
-2290
lines changed

R/pkg/R/context.R

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,13 @@ spark.addFile <- function(path, recursive = FALSE) {
330330
#'}
331331
#' @note spark.getSparkFilesRootDirectory since 2.1.0
332332
spark.getSparkFilesRootDirectory <- function() {
333-
callJStatic("org.apache.spark.SparkFiles", "getRootDirectory")
333+
if (Sys.getenv("SPARKR_IS_RUNNING_ON_WORKER") == "") {
334+
# Running on driver.
335+
callJStatic("org.apache.spark.SparkFiles", "getRootDirectory")
336+
} else {
337+
# Running on worker.
338+
Sys.getenv("SPARKR_SPARKFILES_ROOT_DIR")
339+
}
334340
}
335341

336342
#' Get the absolute path of a file added through spark.addFile.
@@ -345,7 +351,13 @@ spark.getSparkFilesRootDirectory <- function() {
345351
#'}
346352
#' @note spark.getSparkFiles since 2.1.0
347353
spark.getSparkFiles <- function(fileName) {
348-
callJStatic("org.apache.spark.SparkFiles", "get", as.character(fileName))
354+
if (Sys.getenv("SPARKR_IS_RUNNING_ON_WORKER") == "") {
355+
# Running on driver.
356+
callJStatic("org.apache.spark.SparkFiles", "get", as.character(fileName))
357+
} else {
358+
# Running on worker.
359+
file.path(spark.getSparkFilesRootDirectory(), as.character(fileName))
360+
}
349361
}
350362

351363
#' Run a function over a list of elements, distributing the computations with Spark

R/pkg/R/functions.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2632,8 +2632,8 @@ setMethod("date_sub", signature(y = "Column", x = "numeric"),
26322632

26332633
#' format_number
26342634
#'
2635-
#' Formats numeric column y to a format like '#,###,###.##', rounded to x decimal places,
2636-
#' and returns the result as a string column.
2635+
#' Formats numeric column y to a format like '#,###,###.##', rounded to x decimal places
2636+
#' with HALF_EVEN round mode, and returns the result as a string column.
26372637
#'
26382638
#' If x is 0, the result has no decimal point or fractional part.
26392639
#' If x < 0, the result will be null.
@@ -3548,7 +3548,7 @@ setMethod("row_number",
35483548

35493549
#' array_contains
35503550
#'
3551-
#' Returns true if the array contain the value.
3551+
#' Returns null if the array is null, true if the array contains the value, and false otherwise.
35523552
#'
35533553
#' @param x A Column
35543554
#' @param value A value to be checked if contained in the column

R/pkg/inst/tests/testthat/test_Windows.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ test_that("sparkJars tag in SparkContext", {
2020
if (.Platform$OS.type != "windows") {
2121
skip("This test is only for Windows, skipped")
2222
}
23+
2324
testOutput <- launchScript("ECHO", "a/b/c", wait = TRUE)
2425
abcPath <- testOutput[1]
2526
expect_equal(abcPath, "a\\b\\c")

R/pkg/inst/tests/testthat/test_context.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ test_that("add and get file to be downloaded with Spark job on every node", {
177177
spark.addFile(path)
178178
download_path <- spark.getSparkFiles(filename)
179179
expect_equal(readLines(download_path), words)
180+
181+
# Test spark.getSparkFiles works well on executors.
182+
seq <- seq(from = 1, to = 10, length.out = 5)
183+
f <- function(seq) { spark.getSparkFiles(filename) }
184+
results <- spark.lapply(seq, f)
185+
for (i in 1:5) { expect_equal(basename(results[[i]]), filename) }
186+
180187
unlink(path)
181188

182189
# Test add directory recursively.

R/pkg/inst/tests/testthat/test_sparkSQL.R

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,59 @@ test_that("structType and structField", {
140140
expect_equal(testSchema$fields()[[1]]$dataType.toString(), "StringType")
141141
})
142142

143+
test_that("structField type strings", {
144+
# positive cases
145+
primitiveTypes <- list(byte = "ByteType",
146+
integer = "IntegerType",
147+
float = "FloatType",
148+
double = "DoubleType",
149+
string = "StringType",
150+
binary = "BinaryType",
151+
boolean = "BooleanType",
152+
timestamp = "TimestampType",
153+
date = "DateType")
154+
155+
complexTypes <- list("map<string,integer>" = "MapType(StringType,IntegerType,true)",
156+
"array<string>" = "ArrayType(StringType,true)",
157+
"struct<a:string>" = "StructType(StructField(a,StringType,true))")
158+
159+
typeList <- c(primitiveTypes, complexTypes)
160+
typeStrings <- names(typeList)
161+
162+
for (i in seq_along(typeStrings)){
163+
typeString <- typeStrings[i]
164+
expected <- typeList[[i]]
165+
testField <- structField("_col", typeString)
166+
expect_is(testField, "structField")
167+
expect_true(testField$nullable())
168+
expect_equal(testField$dataType.toString(), expected)
169+
}
170+
171+
# negative cases
172+
primitiveErrors <- list(Byte = "Byte",
173+
INTEGER = "INTEGER",
174+
numeric = "numeric",
175+
character = "character",
176+
raw = "raw",
177+
logical = "logical")
178+
179+
complexErrors <- list("map<string, integer>" = " integer",
180+
"array<String>" = "String",
181+
"struct<a:string >" = "string ",
182+
"map <string,integer>" = "map <string,integer>",
183+
"array< string>" = " string",
184+
"struct<a: string>" = " string")
185+
186+
errorList <- c(primitiveErrors, complexErrors)
187+
typeStrings <- names(errorList)
188+
189+
for (i in seq_along(typeStrings)){
190+
typeString <- typeStrings[i]
191+
expected <- paste0("Unsupported type for SparkDataframe: ", errorList[[i]])
192+
expect_error(structField("_col", typeString), expected)
193+
}
194+
})
195+
143196
test_that("create DataFrame from RDD", {
144197
rdd <- lapply(parallelize(sc, 1:10), function(x) { list(x, as.character(x)) })
145198
df <- createDataFrame(rdd, list("a", "b"))

appveyor.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ branches:
2727
only_commits:
2828
files:
2929
- R/
30+
- sql/core/src/main/scala/org/apache/spark/sql/api/r/
31+
- core/src/main/scala/org/apache/spark/api/r/
32+
- mllib/src/main/scala/org/apache/spark/ml/r/
3033

3134
cache:
3235
- C:\Users\appveyor\.m2

bin/spark-class2.cmd

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,16 @@ if not "x%SPARK_PREPEND_CLASSES%"=="x" (
5050

5151
rem Figure out where java is.
5252
set RUNNER=java
53-
if not "x%JAVA_HOME%"=="x" set RUNNER=%JAVA_HOME%\bin\java
53+
if not "x%JAVA_HOME%"=="x" (
54+
set RUNNER="%JAVA_HOME%\bin\java"
55+
) else (
56+
where /q "%RUNNER%"
57+
if ERRORLEVEL 1 (
58+
echo Java not found and JAVA_HOME environment variable is not set.
59+
echo Install Java and set JAVA_HOME to point to the Java installation directory.
60+
exit /b 1
61+
)
62+
)
5463

5564
rem The launcher library prints the command to be executed in a single line suitable for being
5665
rem executed by the batch interpreter. So read all the output of the launcher into a variable.

common/network-common/src/main/java/org/apache/spark/network/crypto/ClientChallenge.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
/**
2929
* The client challenge message, used to initiate authentication.
3030
*
31-
* @see README.md
31+
* Please see crypto/README.md for more details of implementation.
3232
*/
3333
public class ClientChallenge implements Encodable {
3434
/** Serialization tag used to catch incorrect payloads. */

common/network-common/src/main/java/org/apache/spark/network/crypto/ServerResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
/**
2929
* Server's response to client's challenge.
3030
*
31-
* @see README.md
31+
* Please see crypto/README.md for more details.
3232
*/
3333
public class ServerResponse implements Encodable {
3434
/** Serialization tag used to catch incorrect payloads. */

common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ public static class LongWrapper {
863863
* This is done solely for better performance and is not expected to be used by end users.
864864
*
865865
* {@link LongWrapper} could have been used here but using `int` directly save the extra cost of
866-
* conversion from `long` -> `int`
866+
* conversion from `long` to `int`
867867
*/
868868
public static class IntWrapper {
869869
public int value = 0;

0 commit comments

Comments
 (0)