You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by fe...@apache.org on 2017/02/05 19:38:07 UTC

spark git commit: [SPARK-19452][SPARKR] Fix bug in the name assignment method

Repository: spark
Updated Branches:
  refs/heads/master 0674e7eb8 -> b94f4b6fa


[SPARK-19452][SPARKR] Fix bug in the name assignment method

## What changes were proposed in this pull request?
The names method fails to check for validity of the assignment values. This can be fixed by calling colnames within names.

## How was this patch tested?
new tests.

Author: actuaryzhang <ac...@gmail.com>

Closes #16794 from actuaryzhang/sparkRNames.


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/b94f4b6f
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/b94f4b6f
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/b94f4b6f

Branch: refs/heads/master
Commit: b94f4b6fa65232b6113125198e031b5ad0faafd6
Parents: 0674e7e
Author: actuaryzhang <ac...@gmail.com>
Authored: Sun Feb 5 11:37:45 2017 -0800
Committer: Felix Cheung <fe...@apache.org>
Committed: Sun Feb 5 11:37:45 2017 -0800

----------------------------------------------------------------------
 R/pkg/R/DataFrame.R                       | 6 ++----
 R/pkg/inst/tests/testthat/test_sparkSQL.R | 8 ++++++++
 2 files changed, 10 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/b94f4b6f/R/pkg/R/DataFrame.R
----------------------------------------------------------------------
diff --git a/R/pkg/R/DataFrame.R b/R/pkg/R/DataFrame.R
index bfec324..fefe25b 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

http://git-wip-us.apache.org/repos/asf/spark/blob/b94f4b6f/R/pkg/inst/tests/testthat/test_sparkSQL.R
----------------------------------------------------------------------
diff --git a/R/pkg/inst/tests/testthat/test_sparkSQL.R b/R/pkg/inst/tests/testthat/test_sparkSQL.R
index 417a03f..418f128 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.")


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org