ianmcook commented on a change in pull request #9745:
URL: https://github.com/apache/arrow/pull/9745#discussion_r600520066



##########
File path: r/tests/testthat/test-compute-sort.R
##########
@@ -0,0 +1,157 @@
+# 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.
+
+context("compute: sorting")
+
+library(dplyr)
+
+tbl <- example_data_for_sorting
+
+test_that("Scalar sort", {
+  expect_identical(
+    as.vector(sort(Scalar$create(42L))),
+    42L
+  )
+})
+
+test_that("Array sort on integers", {
+  expect_equal(
+    Array$create(tbl$int)$SortIndices(),
+    Array$create(0L:9L, type = uint64())
+  )
+  expect_equal(
+    Array$create(rev(tbl$int))$SortIndices(descending = TRUE),
+    Array$create(c(1L:9L, 0L), type = uint64())
+  )
+  expect_equal(
+    as.vector(sort(Array$create(tbl$int))),
+    sort(tbl$int)
+  )
+  expect_equal(
+    as.vector(sort(Array$create(tbl$int), na.last = NA)),
+    sort(tbl$int, na.last = NA)
+  )
+  expect_equal(
+    as.vector(sort(Array$create(tbl$int), na.last = TRUE)),
+    sort(tbl$int, na.last = TRUE)
+  )
+  expect_equal(
+    as.vector(sort(Array$create(tbl$int), na.last = FALSE)),
+    sort(tbl$int, na.last = FALSE)
+  )
+  expect_equal(
+    as.vector(sort(Array$create(tbl$int), decreasing = TRUE)),
+    sort(tbl$int, decreasing = TRUE)
+  )
+  expect_equal(
+    as.vector(sort(Array$create(tbl$int), decreasing = TRUE, na.last = TRUE)),
+    sort(tbl$int, decreasing = TRUE, na.last = TRUE)
+  )
+  expect_equal(
+    as.vector(sort(Array$create(tbl$int), decreasing = TRUE, na.last = FALSE)),
+    sort(tbl$int, decreasing = TRUE, na.last = FALSE)
+  )
+})
+
+test_that("ChunkedArray sort on integers", {
+  expect_equal(
+    ChunkedArray$create(tbl$int[1:5], tbl$int[6:10])$SortIndices(),
+    Array$create(0L:9L, type = uint64())
+  )
+  expect_equal(
+    ChunkedArray$create(rev(tbl$int)[1:5], 
rev(tbl$int)[6:10])$SortIndices(descending = TRUE),
+    Array$create(c(1L:9L, 0L), type = uint64())
+  )
+  expect_equal(
+    as.vector(sort(ChunkedArray$create(tbl$int[1:5], tbl$int[6:10]))),
+    sort(tbl$int)
+  )
+  expect_equal(
+    as.vector(sort(ChunkedArray$create(tbl$int[1:5], tbl$int[6:10]), na.last = 
NA)),
+    sort(tbl$int, na.last = NA)
+  )
+  expect_equal(
+    as.vector(sort(ChunkedArray$create(tbl$int[1:5], tbl$int[6:10]), na.last = 
TRUE)),
+    sort(tbl$int, na.last = TRUE)
+  )
+  expect_equal(
+    as.vector(sort(ChunkedArray$create(tbl$int[1:5], tbl$int[6:10]), na.last = 
FALSE)),
+    sort(tbl$int, na.last = FALSE)
+  )
+  expect_equal(
+    as.vector(sort(ChunkedArray$create(tbl$int[1:5], tbl$int[6:10]), 
decreasing = TRUE)),
+    sort(tbl$int, decreasing = TRUE)
+  )
+  expect_equal(
+    as.vector(sort(ChunkedArray$create(tbl$int[1:5], tbl$int[6:10]), 
decreasing = TRUE, na.last = TRUE)),
+    sort(tbl$int, decreasing = TRUE, na.last = TRUE)
+  )
+  expect_equal(
+    as.vector(sort(ChunkedArray$create(tbl$int[1:5], tbl$int[6:10]), 
decreasing = TRUE, na.last = FALSE)),
+    sort(tbl$int, decreasing = TRUE, na.last = FALSE)
+  )
+})
+
+test_that("Array/ChunkedArray sort on strings", {
+  expect_equal(
+    as.vector(sort(Array$create(tbl$chr), decreasing = TRUE, na.last = FALSE)),
+    sort(tbl$chr, decreasing = TRUE, na.last = FALSE)
+  )
+  expect_equal(
+    as.vector(sort(ChunkedArray$create(tbl$chr[1:5], tbl$chr[6:10]), 
decreasing = TRUE, na.last = FALSE)),
+    sort(tbl$chr, decreasing = TRUE, na.last = FALSE)
+  )
+})
+
+test_that("Array/ChunkedArray sort on floats", {
+  skip("ARROW-12055")
+  expect_equal(
+    as.vector(sort(Array$create(tbl$dbl), decreasing = TRUE, na.last = FALSE)),
+    sort(tbl$dbl, decreasing = TRUE, na.last = FALSE)
+  )
+  expect_equal(
+    as.vector(sort(ChunkedArray$create(tbl$dbl[1:5], tbl$dbl[6:10]), 
decreasing = TRUE, na.last = FALSE)),
+    sort(tbl$dbl, decreasing = TRUE, na.last = FALSE)
+  )
+})
+
+test_that("Table/RecordBatch sort", {

Review comment:
       I cleaned up the tests in adb45acc7e03c9dd74af05d7b56536aad0a0cf44. They 
now use the helper function `expect_dplyr_equal()` that I added in 
ddaffcd41b899a79f95f08717544db3b3266d273 which improves readability.




-- 
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.

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


Reply via email to