Refactor ListArray hashing to consider only sliced values#19500
Refactor ListArray hashing to consider only sliced values#19500alamb merged 2 commits intoapache:mainfrom
Conversation
| let first_offset = array.value_offsets().first().cloned().unwrap_or_default(); | ||
| let last_offset = array.value_offsets().last().cloned().unwrap_or_default(); | ||
| let value_bytes_len = (last_offset - first_offset).as_usize(); | ||
| let mut values_hashes = vec![0u64; value_bytes_len]; | ||
| create_hashes( | ||
| [array | ||
| .values() | ||
| .slice(first_offset.as_usize(), value_bytes_len)], | ||
| random_state, | ||
| &mut values_hashes, | ||
| )?; |
| &mut values_hashes, | ||
| )?; | ||
|
|
||
| if array.null_count() > 0 { |
There was a problem hiding this comment.
Switching to this count probably doesn't affect much (how often do we see a nullbuffer thats present but has all bits valid?) but it's consistent with how we check for nulls in the other functions
| )?; | ||
|
|
||
| if array.null_count() > 0 { | ||
| for (i, (start, stop)) in array.value_offsets().iter().tuple_windows().enumerate() |
There was a problem hiding this comment.
Using tuple_windows from itertools makes this more ergonomic
| let first_offset = array.value_offsets().first().cloned().unwrap_or_default(); | ||
| let last_offset = array.value_offsets().last().cloned().unwrap_or_default(); | ||
| let value_bytes_len = (last_offset - first_offset).as_usize(); | ||
| let mut values_hashes = vec![0u64; value_bytes_len]; |
There was a problem hiding this comment.
This allocates a fresh values_hashes Vec for every list column hashed.
Could we reuse a buffer (similar to HASH_BUFFER above) or early-return for empty value_bytes_len to trim repeated allocations?
There was a problem hiding this comment.
Do you mean reuse a buffer between invocations of hash_list_array() itself? We could look into that, but I'd say thats beyond the scope of changes here especially as the other functions don't do this, so might need more plumbing etc.
There was a problem hiding this comment.
I agree removing the allocation would be good -- however, the existing code also creates vec! so I don't think this change is any worse in this regard
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes apache#123` indicates that this PR will close issue apache#123. --> N/A ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> When hashing list arrays we hash all bytes of the child array, even if we slice to a certain range of values. Refactor to slice only the needed bytes; also do some general refactors. ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> Refactor list array hashing. ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> Added test. ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> No. <!-- If there are any breaking changes to public APIs, please add the `api change` label. -->
Which issue does this PR close?
N/A
Rationale for this change
When hashing list arrays we hash all bytes of the child array, even if we slice to a certain range of values. Refactor to slice only the needed bytes; also do some general refactors.
What changes are included in this PR?
Refactor list array hashing.
Are these changes tested?
Added test.
Are there any user-facing changes?
No.