aboutsummaryrefslogtreecommitdiff
path: root/R
diff options
context:
space:
mode:
authorSun Rui <rui.sun@intel.com>2015-04-23 16:08:14 -0700
committerShivaram Venkataraman <shivaram@cs.berkeley.edu>2015-04-23 16:08:14 -0700
commit73db132bf503341c7a5cf9409351c282a8464175 (patch)
tree978eecc5d5a1c5d5ab93ae25954b16d892fbd577 /R
parent6220d933e5ce4ba890f5d6a50a69b95d319dafb4 (diff)
downloadspark-73db132bf503341c7a5cf9409351c282a8464175.tar.gz
spark-73db132bf503341c7a5cf9409351c282a8464175.tar.bz2
spark-73db132bf503341c7a5cf9409351c282a8464175.zip
[SPARK-6818] [SPARKR] Support column deletion in SparkR DataFrame API.
Author: Sun Rui <rui.sun@intel.com> Closes #5655 from sun-rui/SPARK-6818 and squashes the following commits: 7c66570 [Sun Rui] [SPARK-6818][SPARKR] Support column deletion in SparkR DataFrame API.
Diffstat (limited to 'R')
-rw-r--r--R/pkg/R/DataFrame.R8
-rw-r--r--R/pkg/inst/tests/test_sparkSQL.R5
2 files changed, 12 insertions, 1 deletions
diff --git a/R/pkg/R/DataFrame.R b/R/pkg/R/DataFrame.R
index 861fe1c78b..b59b700af5 100644
--- a/R/pkg/R/DataFrame.R
+++ b/R/pkg/R/DataFrame.R
@@ -790,9 +790,12 @@ setMethod("$", signature(x = "DataFrame"),
setMethod("$<-", signature(x = "DataFrame"),
function(x, name, value) {
- stopifnot(class(value) == "Column")
+ stopifnot(class(value) == "Column" || is.null(value))
cols <- columns(x)
if (name %in% cols) {
+ if (is.null(value)) {
+ cols <- Filter(function(c) { c != name }, cols)
+ }
cols <- lapply(cols, function(c) {
if (c == name) {
alias(value, name)
@@ -802,6 +805,9 @@ setMethod("$<-", signature(x = "DataFrame"),
})
nx <- select(x, cols)
} else {
+ if (is.null(value)) {
+ return(x)
+ }
nx <- withColumn(x, name, value)
}
x@sdf <- nx@sdf
diff --git a/R/pkg/inst/tests/test_sparkSQL.R b/R/pkg/inst/tests/test_sparkSQL.R
index 25831ae2d9..af7a6c5820 100644
--- a/R/pkg/inst/tests/test_sparkSQL.R
+++ b/R/pkg/inst/tests/test_sparkSQL.R
@@ -449,6 +449,11 @@ test_that("select operators", {
df$age2 <- df$age * 2
expect_equal(columns(df), c("name", "age", "age2"))
expect_equal(count(where(df, df$age2 == df$age * 2)), 2)
+
+ df$age2 <- NULL
+ expect_equal(columns(df), c("name", "age"))
+ df$age3 <- NULL
+ expect_equal(columns(df), c("name", "age"))
})
test_that("select with column", {