From 890dcc163518ddbe1d505d3c6b7524f385d10017 Mon Sep 17 00:00:00 2001 From: Nic Crane Date: Tue, 7 Sep 2021 13:22:22 +0100 Subject: [PATCH 1/5] Add bindings for the matchsubstringoptions kernels --- r/src/compute.cpp | 4 +++- r/tests/testthat/test-compute-no-bindings.R | 24 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/r/src/compute.cpp b/r/src/compute.cpp index b2a261b0b00..994dc702e8e 100644 --- a/r/src/compute.cpp +++ b/r/src/compute.cpp @@ -287,7 +287,9 @@ std::shared_ptr make_compute_options( if (func_name == "match_substring" || func_name == "match_substring_regex" || func_name == "find_substring" || func_name == "find_substring_regex" || - func_name == "match_like") { + func_name == "match_like" || func_name == "starts_with" || + func_name == "ends_with" || func_name == "count_substring" || + func_name == "count_substring_regex") { using Options = arrow::compute::MatchSubstringOptions; bool ignore_case = false; if (!Rf_isNull(options["ignore_case"])) { diff --git a/r/tests/testthat/test-compute-no-bindings.R b/r/tests/testthat/test-compute-no-bindings.R index 0769eb416e4..397e8674402 100644 --- a/r/tests/testthat/test-compute-no-bindings.R +++ b/r/tests/testthat/test-compute-no-bindings.R @@ -126,3 +126,27 @@ test_that("non-bound compute kernels using PartitionNthOptions", { c(1L, 0L, 4L, 3L, 2L, 5L, 6L, 7L, 8L, 9L) ) }) + + +test_that("non-bound compute kernels using MatchSubstringOptions", { + skip_if_not_available("utf8proc") + expect_equal( + call_function("starts_with", Array$create(c("abracadabra", "abacus", "abdicate", "abrasive")), options = list(pattern = "abr")), + Array$create(c(TRUE, FALSE, FALSE, TRUE)) + ) + + expect_equal( + call_function("ends_with", Array$create(c("abracadabra", "abacus", "abdicate", "abrasive")), options = list(pattern = "e")), + Array$create(c(FALSE, FALSE, TRUE, TRUE)) + ) + + expect_equal( + as.vector(call_function("count_substring", Array$create(c("abracadabra", "abacus", "abdicate", "abrasive")), options = list(pattern = "e"))), + c(0, 0, 1, 1) + ) + + expect_equal( + as.vector(call_function("count_substring_regex", Array$create(c("abracadabra", "abacus", "abdicate", "abrasive")), options = list(pattern = "e"))), + c(0, 0, 1, 1) + ) +}) From 4bed65d4e30a92ab96bff702d1bd4c9f1bdab88d Mon Sep 17 00:00:00 2001 From: Nic Crane Date: Tue, 7 Sep 2021 13:31:02 +0100 Subject: [PATCH 2/5] Add links to tickets --- r/tests/testthat/test-compute-no-bindings.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/r/tests/testthat/test-compute-no-bindings.R b/r/tests/testthat/test-compute-no-bindings.R index 397e8674402..8cb58431dff 100644 --- a/r/tests/testthat/test-compute-no-bindings.R +++ b/r/tests/testthat/test-compute-no-bindings.R @@ -130,21 +130,26 @@ test_that("non-bound compute kernels using PartitionNthOptions", { test_that("non-bound compute kernels using MatchSubstringOptions", { skip_if_not_available("utf8proc") + + # Remove this test when ARROW-13924 has been completed and more complete tests for bindings have been written expect_equal( call_function("starts_with", Array$create(c("abracadabra", "abacus", "abdicate", "abrasive")), options = list(pattern = "abr")), Array$create(c(TRUE, FALSE, FALSE, TRUE)) ) + # Remove this test when ARROW-13924 has been completed and more complete tests for bindings have been written expect_equal( call_function("ends_with", Array$create(c("abracadabra", "abacus", "abdicate", "abrasive")), options = list(pattern = "e")), Array$create(c(FALSE, FALSE, TRUE, TRUE)) ) + # Remove this test when ARROW-13156 has been completed and more complete tests for bindings have been written expect_equal( as.vector(call_function("count_substring", Array$create(c("abracadabra", "abacus", "abdicate", "abrasive")), options = list(pattern = "e"))), c(0, 0, 1, 1) ) + # Remove this test when ARROW-13156 has been completed and more complete tests for bindings have been written expect_equal( as.vector(call_function("count_substring_regex", Array$create(c("abracadabra", "abacus", "abdicate", "abrasive")), options = list(pattern = "e"))), c(0, 0, 1, 1) From 429deb65925c8ad6e6c246980dab1aeb7552aa7a Mon Sep 17 00:00:00 2001 From: Nic Crane Date: Tue, 7 Sep 2021 13:51:35 +0100 Subject: [PATCH 3/5] Appease the angry linter --- r/tests/testthat/test-compute-no-bindings.R | 35 ++++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/r/tests/testthat/test-compute-no-bindings.R b/r/tests/testthat/test-compute-no-bindings.R index 8cb58431dff..ff5f0fb689c 100644 --- a/r/tests/testthat/test-compute-no-bindings.R +++ b/r/tests/testthat/test-compute-no-bindings.R @@ -131,27 +131,46 @@ test_that("non-bound compute kernels using PartitionNthOptions", { test_that("non-bound compute kernels using MatchSubstringOptions", { skip_if_not_available("utf8proc") - # Remove this test when ARROW-13924 has been completed and more complete tests for bindings have been written + # Remove this test when ARROW-13924 has been completed expect_equal( - call_function("starts_with", Array$create(c("abracadabra", "abacus", "abdicate", "abrasive")), options = list(pattern = "abr")), + call_function( + "starts_with", + Array$create(c("abracadabra", "abacus", "abdicate", "abrasive")), + options = list(pattern = "abr") + ), Array$create(c(TRUE, FALSE, FALSE, TRUE)) ) - # Remove this test when ARROW-13924 has been completed and more complete tests for bindings have been written + # Remove this test when ARROW-13924 has been completed expect_equal( - call_function("ends_with", Array$create(c("abracadabra", "abacus", "abdicate", "abrasive")), options = list(pattern = "e")), + call_function( + "ends_with", + Array$create(c("abracadabra", "abacus", "abdicate", "abrasive")), + options = list(pattern = "e")), Array$create(c(FALSE, FALSE, TRUE, TRUE)) ) - # Remove this test when ARROW-13156 has been completed and more complete tests for bindings have been written + # Remove this test when ARROW-13156 has been completed expect_equal( - as.vector(call_function("count_substring", Array$create(c("abracadabra", "abacus", "abdicate", "abrasive")), options = list(pattern = "e"))), + as.vector( + call_function( + "count_substring", + Array$create(c("abracadabra", "abacus", "abdicate", "abrasive")), + options = list(pattern = "e") + ) + ), c(0, 0, 1, 1) ) - # Remove this test when ARROW-13156 has been completed and more complete tests for bindings have been written + # Remove this test when ARROW-13156 has been completed expect_equal( - as.vector(call_function("count_substring_regex", Array$create(c("abracadabra", "abacus", "abdicate", "abrasive")), options = list(pattern = "e"))), + as.vector( + call_function( + "count_substring_regex", + Array$create(c("abracadabra", "abacus", "abdicate", "abrasive")), + options = list(pattern = "e") + ) + ), c(0, 0, 1, 1) ) }) From 2e01c2bd6a0b8c272bfd336ae566c3a7d68950e0 Mon Sep 17 00:00:00 2001 From: Nic Crane Date: Tue, 7 Sep 2021 14:35:34 +0100 Subject: [PATCH 4/5] re2 skip --- r/tests/testthat/test-compute-no-bindings.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/r/tests/testthat/test-compute-no-bindings.R b/r/tests/testthat/test-compute-no-bindings.R index ff5f0fb689c..6cb683ff3e6 100644 --- a/r/tests/testthat/test-compute-no-bindings.R +++ b/r/tests/testthat/test-compute-no-bindings.R @@ -162,6 +162,8 @@ test_that("non-bound compute kernels using MatchSubstringOptions", { c(0, 0, 1, 1) ) + skip_if_not_available("re2") + # Remove this test when ARROW-13156 has been completed expect_equal( as.vector( From 46e504b18842cc2254a63129574cce25164f5e75 Mon Sep 17 00:00:00 2001 From: Nic Crane Date: Tue, 14 Sep 2021 08:34:56 +0100 Subject: [PATCH 5/5] I hate linters --- r/tests/testthat/test-compute-no-bindings.R | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/r/tests/testthat/test-compute-no-bindings.R b/r/tests/testthat/test-compute-no-bindings.R index 6cb683ff3e6..30fb922d81c 100644 --- a/r/tests/testthat/test-compute-no-bindings.R +++ b/r/tests/testthat/test-compute-no-bindings.R @@ -131,40 +131,41 @@ test_that("non-bound compute kernels using PartitionNthOptions", { test_that("non-bound compute kernels using MatchSubstringOptions", { skip_if_not_available("utf8proc") - # Remove this test when ARROW-13924 has been completed + # Remove this test when ARROW-13924 has been completed expect_equal( call_function( "starts_with", Array$create(c("abracadabra", "abacus", "abdicate", "abrasive")), options = list(pattern = "abr") - ), + ), Array$create(c(TRUE, FALSE, FALSE, TRUE)) ) - # Remove this test when ARROW-13924 has been completed + # Remove this test when ARROW-13924 has been completed expect_equal( call_function( "ends_with", Array$create(c("abracadabra", "abacus", "abdicate", "abrasive")), - options = list(pattern = "e")), + options = list(pattern = "e") + ), Array$create(c(FALSE, FALSE, TRUE, TRUE)) ) - # Remove this test when ARROW-13156 has been completed + # Remove this test when ARROW-13156 has been completed expect_equal( as.vector( call_function( "count_substring", Array$create(c("abracadabra", "abacus", "abdicate", "abrasive")), options = list(pattern = "e") - ) - ), + ) + ), c(0, 0, 1, 1) ) skip_if_not_available("re2") - # Remove this test when ARROW-13156 has been completed + # Remove this test when ARROW-13156 has been completed expect_equal( as.vector( call_function(