diff --git a/R/pkg/R/DataFrame.R b/R/pkg/R/DataFrame.R index bfec3245cf52ac905e55d87665f4601f5a1202a6..fefe25b1480a335eda3d4e130756723ee84dd42e 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 417a03ff6182763a50648f1ec03c597492eb917f..418f128ce8e8aa3e9446af5518557f6f76f60774 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.")