diff --git a/r/src/compute.cpp b/r/src/compute.cpp index e84f70016a5..527751b900d 100644 --- a/r/src/compute.cpp +++ b/r/src/compute.cpp @@ -354,6 +354,13 @@ std::shared_ptr make_compute_options( return std::make_shared(max_splits, reverse); } + if (func_name == "utf8_trim" || func_name == "utf8_ltrim" || + func_name == "utf8_rtrim" || func_name == "ascii_trim" || + func_name == "ascii_ltrim" || func_name == "ascii_rtrim") { + using Options = arrow::compute::TrimOptions; + return std::make_shared(cpp11::as_cpp(options["characters"])); + } + if (func_name == "utf8_slice_codeunits") { using Options = arrow::compute::SliceOptions; diff --git a/r/tests/testthat/test-compute-no-bindings.R b/r/tests/testthat/test-compute-no-bindings.R new file mode 100644 index 00000000000..33b97e8ed76 --- /dev/null +++ b/r/tests/testthat/test-compute-no-bindings.R @@ -0,0 +1,53 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +test_that("non-bound compute kernels using TrimOptions", { + expect_equal( + call_function("utf8_trim", Scalar$create("abracadabra"), options = list(characters = "ab")), + Scalar$create("racadabr") + ) + + expect_equal( + call_function("utf8_ltrim", Scalar$create("abracadabra"), options = list(characters = "ab")), + Scalar$create("racadabra") + ) + + expect_equal( + call_function("utf8_rtrim", Scalar$create("abracadabra"), options = list(characters = "ab")), + Scalar$create("abracadabr") + ) + + expect_equal( + call_function("utf8_rtrim", Scalar$create("abracadabra"), options = list(characters = "ab")), + Scalar$create("abracadabr") + ) + + expect_equal( + call_function("ascii_ltrim", Scalar$create("abracadabra"), options = list(characters = "ab")), + Scalar$create("racadabra") + ) + + expect_equal( + call_function("ascii_rtrim", Scalar$create("abracadabra"), options = list(characters = "ab")), + Scalar$create("abracadabr") + ) + + expect_equal( + call_function("ascii_rtrim", Scalar$create("abracadabra"), options = list(characters = "ab")), + Scalar$create("abracadabr") + ) +})