-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-12016 [C++] Implement array_sort_indices and sort_indices for BOOL type #10585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
62b9d01
adding bool sort and partition_nth_indices
nirandaperera bec60ae
adding chunked array capability
nirandaperera be3f0eb
editing R files
nirandaperera 5af2751
adding bool type for record batches and tables
nirandaperera ad1fe2b
adding a simple bench
nirandaperera cc0f790
minor change
nirandaperera efb4800
adding specialized impl for bool
nirandaperera cb0cead
changing vector to array
nirandaperera c81df3f
adding PR comments
nirandaperera 5d58b53
Update vector_sort.cc
nirandaperera ce74d34
minor changes
nirandaperera 151e466
removing non-null case in TestTableSortIndices
nirandaperera fbb2129
removing unnecessary uint32/ uint64 branch
nirandaperera b6ccdb2
trying to fix appveyor error
nirandaperera 3de75a7
Update docs, simplify code
pitrou 257527c
Improve performance in the no-nulls case
pitrou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -180,6 +180,10 @@ template <typename ArrowType> | |
| class TestNthToIndicesForIntegral : public TestNthToIndices<ArrowType> {}; | ||
| TYPED_TEST_SUITE(TestNthToIndicesForIntegral, IntegralArrowTypes); | ||
|
|
||
| template <typename ArrowType> | ||
| class TestNthToIndicesForBool : public TestNthToIndices<ArrowType> {}; | ||
| TYPED_TEST_SUITE(TestNthToIndicesForBool, ::testing::Types<BooleanType>); | ||
|
|
||
| template <typename ArrowType> | ||
| class TestNthToIndicesForTemporal : public TestNthToIndices<ArrowType> {}; | ||
| TYPED_TEST_SUITE(TestNthToIndicesForTemporal, TemporalArrowTypes); | ||
|
|
@@ -223,6 +227,13 @@ TYPED_TEST(TestNthToIndicesForIntegral, Integral) { | |
| this->AssertNthToIndicesJson("[null, 1, 3, null, 2, 5]", 6); | ||
| } | ||
|
|
||
| TYPED_TEST(TestNthToIndicesForBool, Bool) { | ||
| this->AssertNthToIndicesJson("[null, false, true, null, false, true]", 0); | ||
| this->AssertNthToIndicesJson("[null, false, true, null, false, true]", 2); | ||
| this->AssertNthToIndicesJson("[null, false, true, null, false, true]", 5); | ||
| this->AssertNthToIndicesJson("[null, false, true, null, false, true]", 6); | ||
| } | ||
|
|
||
| TYPED_TEST(TestNthToIndicesForTemporal, Temporal) { | ||
| this->AssertNthToIndicesJson("[null, 1, 3, null, 2, 5]", 0); | ||
| this->AssertNthToIndicesJson("[null, 1, 3, null, 2, 5]", 2); | ||
|
|
@@ -402,6 +413,10 @@ template <typename ArrowType> | |
| class TestArraySortIndicesForReal : public TestArraySortIndices<ArrowType> {}; | ||
| TYPED_TEST_SUITE(TestArraySortIndicesForReal, RealArrowTypes); | ||
|
|
||
| template <typename ArrowType> | ||
| class TestArraySortIndicesForBool : public TestArraySortIndices<ArrowType> {}; | ||
| TYPED_TEST_SUITE(TestArraySortIndicesForBool, ::testing::Types<BooleanType>); | ||
|
|
||
| template <typename ArrowType> | ||
| class TestArraySortIndicesForIntegral : public TestArraySortIndices<ArrowType> {}; | ||
| TYPED_TEST_SUITE(TestArraySortIndicesForIntegral, IntegralArrowTypes); | ||
|
|
@@ -464,6 +479,26 @@ TYPED_TEST(TestArraySortIndicesForIntegral, SortIntegral) { | |
| "[5, 2, 4, 1, 0, 3]"); | ||
| } | ||
|
|
||
| TYPED_TEST(TestArraySortIndicesForBool, SortBool) { | ||
| this->AssertSortIndices("[]", "[]"); | ||
|
|
||
| this->AssertSortIndices("[true, true, false]", "[2, 0, 1]"); | ||
| this->AssertSortIndices("[false, false, false, true, true, true, true]", | ||
| "[0, 1, 2, 3, 4, 5, 6]"); | ||
| this->AssertSortIndices("[true, true, true, true, false, false, false]", | ||
| "[4, 5, 6, 0, 1, 2, 3]"); | ||
|
|
||
| this->AssertSortIndices("[false, true, false, true, true, false, false]", | ||
| SortOrder::Ascending, "[0, 2, 5, 6, 1, 3, 4]"); | ||
| this->AssertSortIndices("[false, true, false, true, true, false, false]", | ||
| SortOrder::Descending, "[1, 3, 4, 0, 2, 5, 6]"); | ||
|
|
||
| this->AssertSortIndices("[null, true, false, null, false, true]", SortOrder::Ascending, | ||
| "[2, 4, 1, 5, 0, 3]"); | ||
| this->AssertSortIndices("[null, true, false, null, false, true]", SortOrder::Descending, | ||
| "[1, 5, 2, 4, 0, 3]"); | ||
| } | ||
|
|
||
| TYPED_TEST(TestArraySortIndicesForTemporal, SortTemporal) { | ||
| this->AssertSortIndices("[]", "[]"); | ||
|
|
||
|
|
@@ -546,7 +581,7 @@ class TestArraySortIndicesRandomCompare : public TestBase {}; | |
| using SortIndicesableTypes = | ||
| ::testing::Types<UInt8Type, UInt16Type, UInt32Type, UInt64Type, Int8Type, Int16Type, | ||
| Int32Type, Int64Type, FloatType, DoubleType, StringType, | ||
| Decimal128Type>; | ||
| Decimal128Type, BooleanType>; | ||
|
|
||
| template <typename ArrayType> | ||
| void ValidateSorted(const ArrayType& array, UInt64Array& offsets, SortOrder order) { | ||
|
|
@@ -842,6 +877,27 @@ TEST_F(TestRecordBatchSortIndices, NaNAndNull) { | |
| AssertSortIndices(batch, options, "[7, 1, 2, 6, 5, 4, 0, 3]"); | ||
| } | ||
|
|
||
| TEST_F(TestRecordBatchSortIndices, Boolean) { | ||
| auto schema = ::arrow::schema({ | ||
| {field("a", boolean())}, | ||
| {field("b", boolean())}, | ||
| }); | ||
| SortOptions options( | ||
| {SortKey("a", SortOrder::Ascending), SortKey("b", SortOrder::Descending)}); | ||
|
|
||
| auto batch = RecordBatchFromJSON(schema, | ||
| R"([{"a": true, "b": null}, | ||
| {"a": false, "b": null}, | ||
| {"a": true, "b": true}, | ||
| {"a": false, "b": true}, | ||
| {"a": true, "b": false}, | ||
| {"a": null, "b": false}, | ||
| {"a": false, "b": null}, | ||
| {"a": null, "b": true} | ||
| ])"); | ||
| AssertSortIndices(batch, options, "[3, 1, 6, 2, 4, 0, 7, 5]"); | ||
| } | ||
|
|
||
| TEST_F(TestRecordBatchSortIndices, MoreTypes) { | ||
| auto schema = ::arrow::schema({ | ||
| {field("a", timestamp(TimeUnit::MICRO))}, | ||
|
|
@@ -980,6 +1036,25 @@ TEST_F(TestTableSortIndices, NaNAndNull) { | |
| AssertSortIndices(table, options, "[7, 1, 2, 6, 5, 4, 0, 3]"); | ||
| } | ||
|
|
||
| TEST_F(TestTableSortIndices, Boolean) { | ||
|
||
| auto schema = ::arrow::schema({ | ||
| {field("a", boolean())}, | ||
| {field("b", boolean())}, | ||
| }); | ||
| SortOptions options( | ||
| {SortKey("a", SortOrder::Ascending), SortKey("b", SortOrder::Descending)}); | ||
| auto table = TableFromJSON(schema, {R"([{"a": true, "b": null}, | ||
| {"a": false, "b": null}, | ||
| {"a": true, "b": true}, | ||
| {"a": false, "b": true}])", | ||
| R"([{"a": true, "b": false}, | ||
| {"a": null, "b": false}, | ||
| {"a": false, "b": null}, | ||
| {"a": null, "b": true} | ||
| ])"}); | ||
| AssertSortIndices(table, options, "[3, 1, 6, 2, 4, 0, 7, 5]"); | ||
| } | ||
|
|
||
| TEST_F(TestTableSortIndices, BinaryLike) { | ||
| auto schema = ::arrow::schema({ | ||
| {field("a", large_utf8())}, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's worth testing the non-null case separately. This will make less test code to maintain.