Skip to content
Snippets Groups Projects
Commit 773ca037 authored by Yu ISHIKAWA's avatar Yu ISHIKAWA Committed by Shivaram Venkataraman
Browse files

[MINOR] [SPARKR] Fix some validation problems in SparkR

Getting rid of some validation problems in SparkR
https://github.com/apache/spark/pull/7883

cc shivaram

```
inst/tests/test_Serde.R:26:1: style: Trailing whitespace is superfluous.

^~
inst/tests/test_Serde.R:34:1: style: Trailing whitespace is superfluous.

^~
inst/tests/test_Serde.R:37:38: style: Trailing whitespace is superfluous.
  expect_equal(class(x), "character")
                                     ^~
inst/tests/test_Serde.R:50:1: style: Trailing whitespace is superfluous.

^~
inst/tests/test_Serde.R:55:1: style: Trailing whitespace is superfluous.

^~
inst/tests/test_Serde.R:60:1: style: Trailing whitespace is superfluous.

^~
inst/tests/test_sparkSQL.R:611:1: style: Trailing whitespace is superfluous.

^~
R/DataFrame.R:664:1: style: Trailing whitespace is superfluous.

^~~~~~~~~~~~~~
R/DataFrame.R:670:55: style: Trailing whitespace is superfluous.
                df <- data.frame(row.names = 1 : nrow)
                                                      ^~~~~~~~~~~~~~~~
R/DataFrame.R:672:1: style: Trailing whitespace is superfluous.

^~~~~~~~~~~~~~
R/DataFrame.R:686:49: style: Trailing whitespace is superfluous.
                    df[[names[colIndex]]] <- vec
                                                ^~~~~~~~~~~~~~~~~~
```

Author: Yu ISHIKAWA <yuu.ishikawa@gmail.com>

Closes #8474 from yu-iskw/minor-fix-sparkr.
parent ad7f0f16
No related branches found
No related tags found
No related merge requests found
...@@ -661,15 +661,15 @@ setMethod("collect", ...@@ -661,15 +661,15 @@ setMethod("collect",
# listCols is a list of columns # listCols is a list of columns
listCols <- callJStatic("org.apache.spark.sql.api.r.SQLUtils", "dfToCols", x@sdf) listCols <- callJStatic("org.apache.spark.sql.api.r.SQLUtils", "dfToCols", x@sdf)
stopifnot(length(listCols) == ncol) stopifnot(length(listCols) == ncol)
# An empty data.frame with 0 columns and number of rows as collected # An empty data.frame with 0 columns and number of rows as collected
nrow <- length(listCols[[1]]) nrow <- length(listCols[[1]])
if (nrow <= 0) { if (nrow <= 0) {
df <- data.frame() df <- data.frame()
} else { } else {
df <- data.frame(row.names = 1 : nrow) df <- data.frame(row.names = 1 : nrow)
} }
# Append columns one by one # Append columns one by one
for (colIndex in 1 : ncol) { for (colIndex in 1 : ncol) {
# Note: appending a column of list type into a data.frame so that # Note: appending a column of list type into a data.frame so that
...@@ -683,7 +683,7 @@ setMethod("collect", ...@@ -683,7 +683,7 @@ setMethod("collect",
# TODO: more robust check on column of primitive types # TODO: more robust check on column of primitive types
vec <- do.call(c, col) vec <- do.call(c, col)
if (class(vec) != "list") { if (class(vec) != "list") {
df[[names[colIndex]]] <- vec df[[names[colIndex]]] <- vec
} else { } else {
# For columns of complex type, be careful to access them. # For columns of complex type, be careful to access them.
# Get a column of complex type returns a list. # Get a column of complex type returns a list.
......
...@@ -23,7 +23,7 @@ test_that("SerDe of primitive types", { ...@@ -23,7 +23,7 @@ test_that("SerDe of primitive types", {
x <- callJStatic("SparkRHandler", "echo", 1L) x <- callJStatic("SparkRHandler", "echo", 1L)
expect_equal(x, 1L) expect_equal(x, 1L)
expect_equal(class(x), "integer") expect_equal(class(x), "integer")
x <- callJStatic("SparkRHandler", "echo", 1) x <- callJStatic("SparkRHandler", "echo", 1)
expect_equal(x, 1) expect_equal(x, 1)
expect_equal(class(x), "numeric") expect_equal(class(x), "numeric")
...@@ -31,10 +31,10 @@ test_that("SerDe of primitive types", { ...@@ -31,10 +31,10 @@ test_that("SerDe of primitive types", {
x <- callJStatic("SparkRHandler", "echo", TRUE) x <- callJStatic("SparkRHandler", "echo", TRUE)
expect_true(x) expect_true(x)
expect_equal(class(x), "logical") expect_equal(class(x), "logical")
x <- callJStatic("SparkRHandler", "echo", "abc") x <- callJStatic("SparkRHandler", "echo", "abc")
expect_equal(x, "abc") expect_equal(x, "abc")
expect_equal(class(x), "character") expect_equal(class(x), "character")
}) })
test_that("SerDe of list of primitive types", { test_that("SerDe of list of primitive types", {
...@@ -47,17 +47,17 @@ test_that("SerDe of list of primitive types", { ...@@ -47,17 +47,17 @@ test_that("SerDe of list of primitive types", {
y <- callJStatic("SparkRHandler", "echo", x) y <- callJStatic("SparkRHandler", "echo", x)
expect_equal(x, y) expect_equal(x, y)
expect_equal(class(y[[1]]), "numeric") expect_equal(class(y[[1]]), "numeric")
x <- list(TRUE, FALSE) x <- list(TRUE, FALSE)
y <- callJStatic("SparkRHandler", "echo", x) y <- callJStatic("SparkRHandler", "echo", x)
expect_equal(x, y) expect_equal(x, y)
expect_equal(class(y[[1]]), "logical") expect_equal(class(y[[1]]), "logical")
x <- list("a", "b", "c") x <- list("a", "b", "c")
y <- callJStatic("SparkRHandler", "echo", x) y <- callJStatic("SparkRHandler", "echo", x)
expect_equal(x, y) expect_equal(x, y)
expect_equal(class(y[[1]]), "character") expect_equal(class(y[[1]]), "character")
# Empty list # Empty list
x <- list() x <- list()
y <- callJStatic("SparkRHandler", "echo", x) y <- callJStatic("SparkRHandler", "echo", x)
......
...@@ -608,7 +608,7 @@ test_that("subsetting", { ...@@ -608,7 +608,7 @@ test_that("subsetting", {
df4 <- df[df$age %in% c(19, 30), 1:2] df4 <- df[df$age %in% c(19, 30), 1:2]
expect_equal(count(df4), 2) expect_equal(count(df4), 2)
expect_equal(columns(df4), c("name", "age")) expect_equal(columns(df4), c("name", "age"))
df5 <- df[df$age %in% c(19), c(1,2)] df5 <- df[df$age %in% c(19), c(1,2)]
expect_equal(count(df5), 1) expect_equal(count(df5), 1)
expect_equal(columns(df5), c("name", "age")) expect_equal(columns(df5), c("name", "age"))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment