You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "pitrou (via GitHub)" <gi...@apache.org> on 2023/05/30 17:56:35 UTC

[GitHub] [arrow] pitrou commented on a diff in pull request #35727: GH-33206: [C++] Add support for StructArray sorting and nested sort keys

pitrou commented on code in PR #35727:
URL: https://github.com/apache/arrow/pull/35727#discussion_r1210629365


##########
cpp/src/arrow/compute/kernels/vector_sort_test.cc:
##########
@@ -2115,6 +2115,73 @@ INSTANTIATE_TEST_SUITE_P(AllNull, TestTableSortIndicesRandom,
                          testing::Combine(first_sort_keys, num_sort_keys,
                                           testing::Values(1.0)));
 
+class TestNestedSortIndices : public ::testing::Test {
+ protected:
+  static std::shared_ptr<Array> GetArray() {
+    auto child_type = struct_({field("a", uint8()), field("b", uint32())});
+    auto child_array = ArrayFromJSON(child_type,
+                                     R"([{"a": 5,    "b": null},
+                                         {"a": null, "b": 7   },
+                                         {"a": null, "b": 9   },
+                                         {"a": 2,    "b": 4   },
+                                         {"a": 5,    "b": 1   },
+                                         {"a": 3,    "b": null},
+                                         {"a": 2,    "b": 3   }
+                                         ])");
+
+    // The top-level validity bitmap is created independently to test null inheritance for
+    // child fields.
+    std::shared_ptr<Buffer> parent_bitmap;
+    ARROW_CHECK_OK(GetBitmapFromVector<bool>({1, 1, 1, 1, 1, 0, 1}, &parent_bitmap));
+
+    auto array =
+        *StructArray::Make({child_array}, {field("a", child_type)}, parent_bitmap);
+    ARROW_CHECK_OK(array->ValidateFull());
+    return array;
+  }
+
+  static std::shared_ptr<RecordBatch> GetRecordBatch() {
+    auto batch = *RecordBatch::FromStructArray(GetArray());
+    ARROW_CHECK_OK(batch->ValidateFull());
+    return batch;
+  }
+
+  static std::shared_ptr<ChunkedArray> GetChunkedArray() {
+    auto array = GetArray();
+    ArrayVector chunks(2);
+    chunks[0] = *array->SliceSafe(0, 3);
+    chunks[1] = *array->SliceSafe(3);
+    auto chunked = *ChunkedArray::Make(std::move(chunks));
+    ARROW_CHECK_OK(chunked->ValidateFull());
+    return chunked;
+  }
+
+  static std::shared_ptr<Table> GetTable() {
+    auto chunked = GetChunkedArray();
+    auto columns = *chunked->Flatten();
+    auto table =
+        Table::Make(arrow::schema(chunked->type()->fields()), std::move(columns));
+    ARROW_CHECK_OK(table->ValidateFull());
+    return table;
+  }
+
+  template <typename T>
+  void DoTest(const std::shared_ptr<T>& input) const {

Review Comment:
   Could simply take a `Datum` instead of templating this method?



-- 
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-unsubscribe@arrow.apache.org

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