WillAyd commented on code in PR #12963:
URL: https://github.com/apache/arrow/pull/12963#discussion_r861086948
##########
cpp/src/arrow/compute/kernels/vector_sort_test.cc:
##########
@@ -1936,6 +1940,95 @@ TEST_P(TestTableSortIndicesRandom, Sort) {
}
}
+// Ranking Tests
+//
+TEST(ArrayRankFunction, Array) {
+ auto arr = ArrayFromJSON(int16(), "[0, 1, -3, -42, 5]");
+ auto expectedAsc = ArrayFromJSON(uint64(), "[3, 4, 2, 1, 5]");
+ for (auto null_placement : AllNullPlacements()) {
+ for (auto tiebreaker : AllTiebreakers()) {
+ RankOptions options(SortOrder::Ascending, null_placement, tiebreaker);
+ ASSERT_OK_AND_ASSIGN(auto actual, CallFunction("rank", {arr}, &options));
+ AssertDatumsEqual(expectedAsc, actual, /*verbose=*/true);
+ }
+ }
+
+ auto expectedDesc = ArrayFromJSON(uint64(), "[3, 2, 4, 5, 1]");
+ for (auto null_placement : AllNullPlacements()) {
+ for (auto tiebreaker : AllTiebreakers()) {
+ RankOptions options(SortOrder::Descending, null_placement, tiebreaker);
+ ASSERT_OK_AND_ASSIGN(auto actual, CallFunction("rank", {arr}, &options));
+ AssertDatumsEqual(expectedDesc, actual, /*verbose=*/true);
+ }
+ }
+}
+
+TEST(ArrayRankFunction, NullHandling) {
+ auto arr = ArrayFromJSON(int16(), "[0, 1, null, null, 2]");
+ auto expectedEnd = ArrayFromJSON(uint64(), "[1, 2, 4, 5, 3]");
+ RankOptions optionsEnd(SortOrder::Ascending, NullPlacement::AtEnd,
Tiebreaker::First);
+ ASSERT_OK_AND_ASSIGN(auto actualEnd, CallFunction("rank", {arr},
&optionsEnd));
+ AssertDatumsEqual(expectedEnd, actualEnd, /*verbose=*/true);
+
+ auto expectedStart = ArrayFromJSON(uint64(), "[3, 4, 1, 2, 5]");
+ RankOptions optionsStart(SortOrder::Ascending, NullPlacement::AtStart,
+ Tiebreaker::First);
+ ASSERT_OK_AND_ASSIGN(auto actualStart, CallFunction("rank", {arr},
&optionsStart));
+ AssertDatumsEqual(expectedStart, actualStart, /*verbose=*/true);
+}
+
+TEST(ArrayRankFunction, TiebreakHandlingAsc) {
Review Comment:
That's what I am thinking as well - might be worth a separate PR /
initiative for the Keep scenario
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]