From fce4b6fa664ee1633ea7bacf38355a422218883d Mon Sep 17 00:00:00 2001 From: actuaryzhang Date: Fri, 3 Feb 2017 11:44:56 -0800 Subject: [PATCH 1/3] fix bug in names and add test --- R/pkg/R/DataFrame.R | 6 ++---- R/pkg/inst/tests/testthat/test_sparkSQL.R | 8 ++++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/R/pkg/R/DataFrame.R b/R/pkg/R/DataFrame.R index bfec3245cf52a..fefe25b1480a3 100644 --- a/R/pkg/R/DataFrame.R +++ b/R/pkg/R/DataFrame.R @@ -323,10 +323,8 @@ setMethod("names", setMethod("names<-", signature(x = "SparkDataFrame"), function(x, value) { - if (!is.null(value)) { - sdf <- callJMethod(x@sdf, "toDF", as.list(value)) - dataFrame(sdf) - } + colnames(x) <- value + x }) #' @rdname columns diff --git a/R/pkg/inst/tests/testthat/test_sparkSQL.R b/R/pkg/inst/tests/testthat/test_sparkSQL.R index 417a03ff61827..418f128ce8e8a 100644 --- a/R/pkg/inst/tests/testthat/test_sparkSQL.R +++ b/R/pkg/inst/tests/testthat/test_sparkSQL.R @@ -869,6 +869,14 @@ test_that("names() colnames() set the column names", { colnames(df) <- c("col3", "col4") expect_equal(names(df)[1], "col3") + expect_error(names(df) <- NULL, "Invalid column names.") + expect_error(names(df) <- c("sepal.length", "sepal_width"), + "Column names cannot contain the '.' symbol.") + expect_error(names(df) <- c(1, 2), "Invalid column names.") + expect_error(names(df) <- c("a"), + "Column names must have the same length as the number of columns in the dataset.") + expect_error(names(df) <- c("1", NA), "Column names cannot be NA.") + expect_error(colnames(df) <- c("sepal.length", "sepal_width"), "Column names cannot contain the '.' symbol.") expect_error(colnames(df) <- c(1, 2), "Invalid column names.") From 723b0a475625e9b08b393ef7a77d1664c995b1a2 Mon Sep 17 00:00:00 2001 From: actuaryzhang Date: Fri, 3 Feb 2017 14:46:11 -0800 Subject: [PATCH 2/3] trigger test --- R/pkg/inst/tests/testthat/test_sparkSQL.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/pkg/inst/tests/testthat/test_sparkSQL.R b/R/pkg/inst/tests/testthat/test_sparkSQL.R index 418f128ce8e8a..03d0306c08da9 100644 --- a/R/pkg/inst/tests/testthat/test_sparkSQL.R +++ b/R/pkg/inst/tests/testthat/test_sparkSQL.R @@ -877,6 +877,7 @@ test_that("names() colnames() set the column names", { "Column names must have the same length as the number of columns in the dataset.") expect_error(names(df) <- c("1", NA), "Column names cannot be NA.") + expect_error(colnames(df) <- NULL, "Invalid column names.") expect_error(colnames(df) <- c("sepal.length", "sepal_width"), "Column names cannot contain the '.' symbol.") expect_error(colnames(df) <- c(1, 2), "Invalid column names.") From f7dc3c602b7ef47f7c493d0fff9012bbc6450854 Mon Sep 17 00:00:00 2001 From: actuaryzhang Date: Fri, 3 Feb 2017 15:17:58 -0800 Subject: [PATCH 3/3] trigger test --- R/pkg/inst/tests/testthat/test_sparkSQL.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/pkg/inst/tests/testthat/test_sparkSQL.R b/R/pkg/inst/tests/testthat/test_sparkSQL.R index 03d0306c08da9..418f128ce8e8a 100644 --- a/R/pkg/inst/tests/testthat/test_sparkSQL.R +++ b/R/pkg/inst/tests/testthat/test_sparkSQL.R @@ -877,7 +877,6 @@ test_that("names() colnames() set the column names", { "Column names must have the same length as the number of columns in the dataset.") expect_error(names(df) <- c("1", NA), "Column names cannot be NA.") - expect_error(colnames(df) <- NULL, "Invalid column names.") expect_error(colnames(df) <- c("sepal.length", "sepal_width"), "Column names cannot contain the '.' symbol.") expect_error(colnames(df) <- c(1, 2), "Invalid column names.")