nealrichardson commented on code in PR #13397:
URL: https://github.com/apache/arrow/pull/13397#discussion_r916284404


##########
r/tests/testthat/test-compute.R:
##########
@@ -0,0 +1,107 @@
+# 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("list_compute_functions() works", {
+  expect_type(list_compute_functions(), "character")
+  expect_true(all(!grepl("^hash_", list_compute_functions())))
+})
+
+
+test_that("arrow_base_scalar_function() works", {
+  # check in/out type as schema/data type
+  fun <- arrow_base_scalar_function(schema(.y = int32()), int64(), function(x, 
y) y[[1]])
+  expect_equal(attr(fun, "in_type")[[1]], schema(.y = int32()))
+  expect_equal(attr(fun, "out_type")[[1]](), int64())
+
+  # check in/out type as data type/data type
+  fun <- arrow_base_scalar_function(int32(), int64(), function(x, y) y[[1]])
+  expect_equal(attr(fun, "in_type")[[1]][[1]], field("", int32()))
+  expect_equal(attr(fun, "out_type")[[1]](), int64())
+
+  # check in/out type as field/data type
+  fun <- arrow_base_scalar_function(
+    field("a_name", int32()),
+    int64(),
+    function(x, y) y[[1]]
+  )
+  expect_equal(attr(fun, "in_type")[[1]], schema(a_name = int32()))
+  expect_equal(attr(fun, "out_type")[[1]](), int64())
+
+  # check in/out type as lists
+  fun <- arrow_base_scalar_function(
+    list(int32(), int64()),
+    list(int64(), int32()),
+    function(x, y) y[[1]]
+  )
+
+  expect_equal(attr(fun, "in_type")[[1]][[1]], field("", int32()))
+  expect_equal(attr(fun, "in_type")[[2]][[1]], field("", int64()))
+  expect_equal(attr(fun, "out_type")[[1]](), int64())
+  expect_equal(attr(fun, "out_type")[[2]](), int32())
+
+  expect_snapshot_error(arrow_base_scalar_function(int32(), int32(), identity))
+  expect_snapshot_error(arrow_base_scalar_function(int32(), int32(), NULL))
+})
+
+test_that("arrow_scalar_function() returns a base scalar function", {
+  base_fun <- arrow_scalar_function(
+    list(float64(), float64()),
+    float64(),
+    function(x, y) {
+      x + y

Review Comment:
   Could do something wild and bespoke, like generate fitted values from a 
regression model run in R (`stats::predict.lm()`). I guess even that could be 
decomposed into functions we support in arrow, but it saves a bunch of code a 
user would have to write, and it makes for a better story.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to