Github user felixcheung commented on a diff in the pull request:
https://github.com/apache/spark/pull/17783#discussion_r113754078
--- Diff: R/pkg/R/column.R ---
@@ -302,3 +301,65 @@ setMethod("otherwise",
jc <- callJMethod(x@jc, "otherwise", value)
column(jc)
})
+
+#' \%<=>\%
+#'
+#' Equality test that is safe for null values.
+#'
+#' Can be used, unlike standard equality operator, to perform null-safe
joins.
+#' Equivalent to Scala \code{Column.<=>} and \code{Column.eqNullSafe}.
+#'
+#' @param x a Column
+#' @param value a value to compare
+#' @rdname eq_null_safe
+#' @name %<=>%
+#' @aliases %<=>%,Column-method
+#' @export
+#' @examples
+#' \dontrun{
+#' df1 <- createDataFrame(data.frame(
+#' x = c(1, NA, 3, NA), y = c(2, 6, 3, NA)
+#' ))
+#'
+#' head(select(df1, df1$x == df1$y, df1$x %<=>% df1$y))
+#' ## (x = y) (x <=> y)
+#' ##1 FALSE FALSE
+#' ##2 NA FALSE
+#' ##3 TRUE TRUE
+#' ##4 NA TRUE
+#'
+#' df2 <- createDataFrame(data.frame(y = c(3, NA)))
+#' count(join(df1, df2, df1$y == df2$y))
+#' ## [1] 1
+#'
+#' count(join(df1, df2, df1$y %<=>% df2$y))
+#' ## [1] 2
+#' }
+#' @note \%<=>\% since 2.3.0
+setMethod("%<=>%",
+ signature(x = "Column", value = "ANY"),
+ function(x, value) {
+ value <- if (class(value) == "Column") { value@jc } else {
value }
+ jc <- callJMethod(x@jc, "eqNullSafe", value)
+ column(jc)
+ })
+
+#' !
+#'
+#' @rdname not
+#' @aliases !,Column-method
+#' @export
+#' @examples
+#' \dontrun{
+#' df <- createDataFrame(data.frame(x = c(-1, 0, 1)))
+#'
+#' head(select(df, !column("x") > 0))
+#' ## (NOT (x > 0.0))
+#' ##1 TRUE
+#' ##2 TRUE
+#' ##3 FALSE
+#' }
+#' @note ! since 2.3.0
+setMethod("!",
--- End diff --
does this not conflict with any existing R operator?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]