-
Notifications
You must be signed in to change notification settings - Fork 915
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
Fix struct row comparator's exception on empty structs #10604
Fix struct row comparator's exception on empty structs #10604
Conversation
Signed-off-by: sperlingxx <[email protected]>
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.
Looks fine. Any perf hit? You can check using SORT_NVBENCH
I didn't know there could be empty structs. Does this work if a struct contains 2 struct children, the first of which is empty? |
1 similar comment
I didn't know there could be empty structs. Does this work if a struct contains 2 struct children, the first of which is empty? |
Codecov Report
@@ Coverage Diff @@
## branch-22.06 #10604 +/- ##
===============================================
Coverage ? 86.34%
===============================================
Files ? 140
Lines ? 22280
Branches ? 0
===============================================
Hits ? 19237
Misses ? 3043
Partials ? 0 Continue to review full report at Codecov.
|
I'm a bit skeptical of that too, though there doesn't seem to be anything in the Arrow spec that forbids it: https://arrow.apache.org/docs/format/Columnar.html#struct-layout |
if (lcol.num_child_columns() == 0) { | ||
return cuda::std::make_pair(weak_ordering::EQUIVALENT, depth); | ||
} |
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.
@devavret I assume there is some check earlier on in hose code that verifies corresponding struct columns have the same number of children?
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.
Yes. If it reaches here, they're the same structure.
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 didn't know there could be empty structs. Does this work if a struct contains 2 struct children, the first of which is empty?
It does work. I added a test case to cover this scenario. IIUC, following the rule of decompose_structs
, the second child will be detached from the root struct.
S0
/ \
S1 S2
=>
S0
|
S1 S2
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.
The implementation of decompose_structs
itself was broken because it operated under the assumption that struct has at least 1 child. If S1 was empty then it would create
S0
|
S1
|
S2
I fixed the impl so this is good to go.
If empty structs always compare equal, then can't we just strip struct columns without children during the pre-processing step? |
Because empty structs may carry null masks, which triggers the null comparsion. |
Rerun tests. |
@sperlingxx mind if I push changes to this? I don't think the changes are sufficient. There is probably another corner case here. #10604 (comment) |
I added 0 as the depth of struct. Below is the perf result of my local machine:
|
Signed-off-by: sperlingxx <[email protected]>
So a minor perf hit for increasing depth vs old one #10164 (comment)
Depth 1 time increased from 174 ms to 179 ms and depth 8 increased from 517 ms to 589 ms. Not bad. Correctness is more important. |
Of course not. You are the champion of this area, please go ahead :) |
Rerun tests. |
cpp/tests/sort/sort_test.cpp
Outdated
std::vector<std::unique_ptr<cudf::column>> child_columns2; | ||
auto child_col_1 = cudf::make_structs_column(6, {}, UNKNOWN_NULL_COUNT, std::move(null_mask2)); | ||
child_columns2.push_back(std::move(child_col_1)); | ||
int_col col4{{0, 1, 2, 3, 4, 5}}; |
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.
Reverse this and the answer will not be the one you expect. You'd expect 415320 but you'd get 145320.
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.
Fixed 0ee82bc
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.
What's the TL;DR on the change made in #0ee82bc?
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.
Rather than flattening the struct and then traversing backwards to create branches, we now create branches while traversing. In the earlier method we depended on finding a leaf column to know when to break off the branch.
cpp/tests/sort/sort_test.cpp
Outdated
auto got3 = sorted_order(input3, {order::ASCENDING}); | ||
CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected3, got3->view()); | ||
CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected3, got3->view(), debug_output_level::ALL_ERRORS); |
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.
Shall we remove debug_output_level::ALL_ERRORS
?
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.
sure, why not.
@gpucibot merge |
Fixes #10603
This PR is to fix a bug of the optimized struct row comparator. For now, the struct row comparator assumes that structs being compared are non-empty, so it fails when comparing empty structs.