From 17e3ca6df5eb4b7b74cd8d04868da39eb0137826 Mon Sep 17 00:00:00 2001 From: Leona Yoda Date: Thu, 30 Sep 2021 14:43:09 +0900 Subject: [PATCH] [SPARK-36899][R] Support ILIKE API on R ### What changes were proposed in this pull request? Support ILIKE (case insensitive LIKE) API on R. ### Why are the changes needed? ILIKE statement on SQL interface is supported by SPARK-36674. This PR will support R API for it. ### Does this PR introduce _any_ user-facing change? Yes. Users can call ilike from R. ### How was this patch tested? Unit tests. Closes #34152 from yoda-mon/r-ilike. Authored-by: Leona Yoda Signed-off-by: Kousuke Saruta --- R/pkg/NAMESPACE | 1 + R/pkg/R/column.R | 2 +- R/pkg/R/generics.R | 3 +++ R/pkg/tests/fulltests/test_sparkSQL.R | 2 ++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/R/pkg/NAMESPACE b/R/pkg/NAMESPACE index 5de7aeb8d2..11403f6346 100644 --- a/R/pkg/NAMESPACE +++ b/R/pkg/NAMESPACE @@ -316,6 +316,7 @@ exportMethods("%<=>%", "hour", "hypot", "ifelse", + "ilike", "initcap", "input_file_name", "instr", diff --git a/R/pkg/R/column.R b/R/pkg/R/column.R index 9fa117ccb6..f1fd30e144 100644 --- a/R/pkg/R/column.R +++ b/R/pkg/R/column.R @@ -72,7 +72,7 @@ column_functions1 <- c( "desc", "desc_nulls_first", "desc_nulls_last", "isNaN", "isNull", "isNotNull" ) -column_functions2 <- c("like", "rlike", "getField", "getItem", "contains") +column_functions2 <- c("like", "rlike", "ilike", "getField", "getItem", "contains") createOperator <- function(op) { setMethod(op, diff --git a/R/pkg/R/generics.R b/R/pkg/R/generics.R index 9da818bdfb..ad29a7019e 100644 --- a/R/pkg/R/generics.R +++ b/R/pkg/R/generics.R @@ -725,6 +725,9 @@ setGeneric("like", function(x, ...) { standardGeneric("like") }) #' @rdname columnfunctions setGeneric("rlike", function(x, ...) { standardGeneric("rlike") }) +#' @rdname columnfunctions +setGeneric("ilike", function(x, ...) { standardGeneric("ilike") }) + #' @rdname startsWith setGeneric("startsWith", function(x, prefix) { standardGeneric("startsWith") }) diff --git a/R/pkg/tests/fulltests/test_sparkSQL.R b/R/pkg/tests/fulltests/test_sparkSQL.R index bd5c25074b..1d8ac2b6bf 100644 --- a/R/pkg/tests/fulltests/test_sparkSQL.R +++ b/R/pkg/tests/fulltests/test_sparkSQL.R @@ -2130,6 +2130,8 @@ test_that("higher order functions", { expr("transform(xs, (x, i) -> CASE WHEN ((i % 2.0) = 0.0) THEN x ELSE (- x) END)"), array_exists("vs", function(v) rlike(v, "FAILED")) == expr("exists(vs, v -> (v RLIKE 'FAILED'))"), + array_exists("vs", function(v) ilike(v, "failed")) == + expr("exists(vs, v -> (v ILIKE 'failed'))"), array_forall("xs", function(x) x > 0) == expr("forall(xs, x -> x > 0)"), array_filter("xs", function(x, i) x > 0 | i %% 2 == 0) ==