-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
GH-26648: [C++] Optimize union equality comparison #45384
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c36adf5
edit Visit(SparseUnionType) to check for "runs"
mcshawn10 d7bbf97
remove unused var
mcshawn10 ea2dc13
Lint C++, Python, R, Docker, RAT format fix
mcshawn10 c362cf4
fix white space
mcshawn10 6a8c9cf
PR comments
mcshawn10 b097958
Add equality tests
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 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 |
---|---|---|
|
@@ -381,23 +381,49 @@ class RangeDataEqualsImpl { | |
const int8_t* right_codes = right_.GetValues<int8_t>(1); | ||
|
||
// Unions don't have a null bitmap | ||
int64_t run_start = 0; // Start index of the current run | ||
|
||
for (int64_t i = 0; i < range_length_; ++i) { | ||
const auto type_id = left_codes[left_start_idx_ + i]; | ||
if (type_id != right_codes[right_start_idx_ + i]) { | ||
const auto current_type_id = left_codes[left_start_idx_ + i]; | ||
|
||
if (current_type_id != right_codes[right_start_idx_ + i]) { | ||
result_ = false; | ||
break; | ||
} | ||
const auto child_num = child_ids[type_id]; | ||
// XXX can we instead detect runs of same-child union values? | ||
RangeDataEqualsImpl impl( | ||
options_, floating_approximate_, *left_.child_data[child_num], | ||
*right_.child_data[child_num], left_start_idx_ + left_.offset + i, | ||
right_start_idx_ + right_.offset + i, 1); | ||
if (!impl.Compare()) { | ||
result_ = false; | ||
break; | ||
// Check if the current element breaks the run | ||
if (i > 0 && current_type_id != left_codes[left_start_idx_ + i - 1]) { | ||
// Compare the previous run | ||
const auto previous_child_num = child_ids[left_codes[left_start_idx_ + i - 1]]; | ||
int64_t run_length = i - run_start; | ||
|
||
RangeDataEqualsImpl impl( | ||
options_, floating_approximate_, *left_.child_data[previous_child_num], | ||
*right_.child_data[previous_child_num], | ||
left_start_idx_ + left_.offset + run_start, | ||
right_start_idx_ + right_.offset + run_start, run_length); | ||
|
||
if (!impl.Compare()) { | ||
result_ = false; | ||
return Status::OK(); | ||
} | ||
|
||
// Start a new run | ||
run_start = i; | ||
} | ||
} | ||
|
||
// Handle the final run | ||
const auto final_child_num = child_ids[left_codes[left_start_idx_ + run_start]]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably only do this final comparison if |
||
int64_t final_run_length = range_length_ - run_start; | ||
|
||
RangeDataEqualsImpl impl( | ||
options_, floating_approximate_, *left_.child_data[final_child_num], | ||
*right_.child_data[final_child_num], left_start_idx_ + left_.offset + run_start, | ||
right_start_idx_ + right_.offset + run_start, final_run_length); | ||
|
||
if (!impl.Compare()) { | ||
result_ = false; | ||
} | ||
return Status::OK(); | ||
} | ||
|
||
|
Oops, something went wrong.
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.
Can
break
just as above.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.
thank you for the feedback! just implemented the suggestions