Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix R style checks.
  • Loading branch information
Sun Rui committed Sep 6, 2015
commit 1e223e0e1894adfac699f62d3429ebb181e87e85
8 changes: 4 additions & 4 deletions R/pkg/R/DataFrame.R
Original file line number Diff line number Diff line change
Expand Up @@ -661,15 +661,15 @@ setMethod("collect",
# listCols is a list of columns
listCols <- callJStatic("org.apache.spark.sql.api.r.SQLUtils", "dfToCols", x@sdf)
stopifnot(length(listCols) == ncol)

# An empty data.frame with 0 columns and number of rows as collected
nrow <- length(listCols[[1]])
if (nrow <= 0) {
df <- data.frame()
} else {
df <- data.frame(row.names = 1 : nrow)
df <- data.frame(row.names = 1 : nrow)
}

# Append columns one by one
for (colIndex in 1 : ncol) {
# Note: appending a column of list type into a data.frame so that
Expand All @@ -683,7 +683,7 @@ setMethod("collect",
# TODO: more robust check on column of primitive types
vec <- do.call(c, col)
if (class(vec) != "list") {
df[[names[colIndex]]] <- vec
df[[names[colIndex]]] <- vec
} else {
# For columns of complex type, be careful to access them.
# Get a column of complex type returns a list.
Expand Down
2 changes: 1 addition & 1 deletion R/pkg/R/schema.R
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ structField.character <- function(x, type, nullable = TRUE) {
}

checkType(type)

sfObj <- callJStatic("org.apache.spark.sql.api.r.SQLUtils",
"createStructField",
x,
Expand Down
12 changes: 6 additions & 6 deletions R/pkg/inst/tests/test_Serde.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ test_that("SerDe of primitive types", {
x <- callJStatic("SparkRHandler", "echo", 1L)
expect_equal(x, 1L)
expect_equal(class(x), "integer")

x <- callJStatic("SparkRHandler", "echo", 1)
expect_equal(x, 1)
expect_equal(class(x), "numeric")

x <- callJStatic("SparkRHandler", "echo", TRUE)
expect_true(x)
expect_equal(class(x), "logical")

x <- callJStatic("SparkRHandler", "echo", "abc")
expect_equal(x, "abc")
expect_equal(class(x), "character")
expect_equal(class(x), "character")
})

test_that("SerDe of list of primitive types", {
Expand All @@ -47,17 +47,17 @@ test_that("SerDe of list of primitive types", {
y <- callJStatic("SparkRHandler", "echo", x)
expect_equal(x, y)
expect_equal(class(y[[1]]), "numeric")

x <- list(TRUE, FALSE)
y <- callJStatic("SparkRHandler", "echo", x)
expect_equal(x, y)
expect_equal(class(y[[1]]), "logical")

x <- list("a", "b", "c")
y <- callJStatic("SparkRHandler", "echo", x)
expect_equal(x, y)
expect_equal(class(y[[1]]), "character")

# Empty list
x <- list()
y <- callJStatic("SparkRHandler", "echo", x)
Expand Down
8 changes: 4 additions & 4 deletions R/pkg/inst/tests/test_sparkSQL.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jsonPathNa <- tempfile(pattern="sparkr-test", fileext=".tmp")
writeLines(mockLinesNa, jsonPathNa)

# For test complex types in DataFrame
mockLinesComplexType <-
mockLinesComplexType <-
c("{\"c1\":[1, 2, 3], \"c2\":[\"a\", \"b\", \"c\"], \"c3\":[1.0, 2.0, 3.0]}",
"{\"c1\":[4, 5, 6], \"c2\":[\"d\", \"e\", \"f\"], \"c3\":[4.0, 5.0, 6.0]}",
"{\"c1\":[7, 8, 9], \"c2\":[\"g\", \"h\", \"i\"], \"c3\":[7.0, 8.0, 9.0]}")
Expand Down Expand Up @@ -253,7 +253,7 @@ test_that("create DataFrame with nested array and struct", {
# ldf <- collect(df)
# expect_equal(ldf[1,], l[[1]])


# ArrayType only for now
l <- list(as.list(1:10), list("a", "b"))
df <- createDataFrame(sqlContext, list(l), c("a", "b"))
Expand All @@ -269,7 +269,7 @@ test_that("Collect DataFrame with complex types", {
# only ArrayType now
# TODO: tests for StructType and MapType after they are supported
df <- jsonFile(sqlContext, complexTypeJsonPath)

ldf <- collect(df)
expect_equal(nrow(ldf), 3)
expect_equal(ncol(ldf), 3)
Expand Down Expand Up @@ -638,7 +638,7 @@ test_that("subsetting", {
df4 <- df[df$age %in% c(19, 30), 1:2]
expect_equal(count(df4), 2)
expect_equal(columns(df4), c("name", "age"))

df5 <- df[df$age %in% c(19), c(1,2)]
expect_equal(count(df5), 1)
expect_equal(columns(df5), c("name", "age"))
Expand Down