From b56520c077c2ea969f0e4373a911940d8a7b29d2 Mon Sep 17 00:00:00 2001 From: Nic Crane Date: Mon, 6 Sep 2021 12:14:16 +0100 Subject: [PATCH 1/3] Add ReplaceSliceOptions options bindings --- r/src/compute.cpp | 8 ++++++++ r/tests/testthat/test-compute-no-bindings.R | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/r/src/compute.cpp b/r/src/compute.cpp index 446e011f548..e0bb9c2000d 100644 --- a/r/src/compute.cpp +++ b/r/src/compute.cpp @@ -384,6 +384,14 @@ std::shared_ptr make_compute_options( step); } + if (func_name == "utf8_replace_slice" || func_name == "binary_replace_slice") { + using Options = arrow::compute::ReplaceSliceOptions; + + return std::make_shared(cpp11::as_cpp(options["start"]), + cpp11::as_cpp(options["stop"]), + cpp11::as_cpp(options["replacement"])); + } + if (func_name == "variance" || func_name == "stddev" || func_name == "hash_variance" || func_name == "hash_stddev") { using Options = arrow::compute::VarianceOptions; diff --git a/r/tests/testthat/test-compute-no-bindings.R b/r/tests/testthat/test-compute-no-bindings.R index afcc779ea5d..b7720c71c05 100644 --- a/r/tests/testthat/test-compute-no-bindings.R +++ b/r/tests/testthat/test-compute-no-bindings.R @@ -53,3 +53,23 @@ skip_if_not_available("utf8proc") Scalar$create("abracadabr") ) }) + +test_that("non-bound compute kernels using ReplaceSliceOptions", { + expect_equal( + call_function( + "binary_replace_slice", + Array$create("I need to fix this string"), + options = list(start = 1, stop = 1, replacement = " don't") + ), + Array$create("I don't need to fix this string") + ) + + expect_equal( + call_function( + "utf8_replace_slice", + Array$create("I need to fix this string"), + options = list(start = 1, stop = 1, replacement = " don't") + ), + Array$create("I don't need to fix this string") + ) +}) From 26e6724249b6ae34c087e11ff35516e603110ad8 Mon Sep 17 00:00:00 2001 From: Nic Crane Date: Mon, 6 Sep 2021 12:20:50 +0100 Subject: [PATCH 2/3] Don't run if utf8proc unavailable --- r/tests/testthat/test-compute-no-bindings.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/r/tests/testthat/test-compute-no-bindings.R b/r/tests/testthat/test-compute-no-bindings.R index b7720c71c05..4d4bd9eea69 100644 --- a/r/tests/testthat/test-compute-no-bindings.R +++ b/r/tests/testthat/test-compute-no-bindings.R @@ -55,6 +55,9 @@ skip_if_not_available("utf8proc") }) test_that("non-bound compute kernels using ReplaceSliceOptions", { + + skip_if_not_available("utf8proc") + expect_equal( call_function( "binary_replace_slice", From 58aeb7ef968476e308e9a8c16e159a63d76f1085 Mon Sep 17 00:00:00 2001 From: Nic Crane Date: Mon, 13 Sep 2021 23:53:11 +0100 Subject: [PATCH 3/3] Fix dodgy merge --- r/tests/testthat/test-compute-no-bindings.R | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/r/tests/testthat/test-compute-no-bindings.R b/r/tests/testthat/test-compute-no-bindings.R index 22b1e5fb5ca..ecd54f51090 100644 --- a/r/tests/testthat/test-compute-no-bindings.R +++ b/r/tests/testthat/test-compute-no-bindings.R @@ -17,7 +17,7 @@ test_that("non-bound compute kernels using TrimOptions", { -skip_if_not_available("utf8proc") + skip_if_not_available("utf8proc") expect_equal( call_function( "utf8_trim", @@ -83,9 +83,8 @@ skip_if_not_available("utf8proc") }) test_that("non-bound compute kernels using ReplaceSliceOptions", { - skip_if_not_available("utf8proc") - + expect_equal( call_function( "binary_replace_slice", @@ -94,7 +93,7 @@ test_that("non-bound compute kernels using ReplaceSliceOptions", { ), Array$create("I don't need to fix this string") ) -}) + expect_equal( call_function( "utf8_replace_slice", @@ -102,7 +101,8 @@ test_that("non-bound compute kernels using ReplaceSliceOptions", { options = list(start = 1, stop = 1, replacement = " don't") ), Array$create("I don't need to fix this string") - + ) +}) test_that("non-bound compute kernels using ModeOptions", { expect_equal( as.vector(