You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "XiangpengHao (via GitHub)" <gi...@apache.org> on 2024/07/17 15:03:38 UTC
[PR] Add String view helper functions [datafusion]
XiangpengHao opened a new pull request, #11517:
URL: https://github.com/apache/datafusion/pull/11517
## 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 #123` indicates that this PR will close issue #123.
-->
Let's wait until #11514 is merged
Part of https://github.com/apache/datafusion/issues/10918
## Rationale for this change
Add a few helper functions to handle string views.
<!--
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.
-->
## 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.
-->
## 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)?
-->
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add String view helper functions [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #11517:
URL: https://github.com/apache/datafusion/pull/11517
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add String view helper functions [datafusion]
Posted by "XiangpengHao (via GitHub)" <gi...@apache.org>.
XiangpengHao commented on code in PR #11517:
URL: https://github.com/apache/datafusion/pull/11517#discussion_r1684718754
##########
datafusion/physical-expr/src/aggregate/min_max.rs:
##########
@@ -453,6 +454,14 @@ fn min_batch(values: &ArrayRef) -> Result<ScalarValue> {
DataType::LargeUtf8 => {
typed_min_max_batch_string!(values, LargeStringArray, LargeUtf8, min_string)
}
+ DataType::Utf8View => {
+ typed_min_max_batch_string!(
Review Comment:
yes
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add String view helper functions [datafusion]
Posted by "XiangpengHao (via GitHub)" <gi...@apache.org>.
XiangpengHao commented on PR #11517:
URL: https://github.com/apache/datafusion/pull/11517#issuecomment-2239801320
I rebased the branch so that it only contains the relevant changes
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add String view helper functions [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #11517:
URL: https://github.com/apache/datafusion/pull/11517#discussion_r1683489582
##########
datafusion/physical-expr/src/aggregate/min_max.rs:
##########
@@ -453,6 +454,14 @@ fn min_batch(values: &ArrayRef) -> Result<ScalarValue> {
DataType::LargeUtf8 => {
typed_min_max_batch_string!(values, LargeStringArray, LargeUtf8, min_string)
}
+ DataType::Utf8View => {
+ typed_min_max_batch_string!(
Review Comment:
Presumably this is using the fast kernel from https://github.com/apache/arrow-rs/pull/6053
##########
datafusion/common/src/hash_utils.rs:
##########
@@ -486,22 +490,57 @@ mod tests {
Ok(())
}
- #[test]
- fn create_hashes_binary() -> Result<()> {
- let byte_array = Arc::new(BinaryArray::from_vec(vec![
- &[4, 3, 2],
- &[4, 3, 2],
- &[1, 2, 3],
- ]));
+ macro_rules! create_hash_binary {
+ ($NAME:ident, $ARRAY:ty) => {
+ #[cfg(not(feature = "force_hash_collisions"))]
+ #[test]
+ fn $NAME() {
+ let binary = [
+ Some(b"short".to_byte_slice()),
+ None,
+ Some(b"long but different 12 bytes string"),
+ Some(b"short2"),
+ Some(b"Longer than 12 bytes string"),
+ Some(b"short"),
+ Some(b"Longer than 12 bytes string"),
+ ];
+
+ let binary_array = Arc::new(binary.iter().cloned().collect::<$ARRAY>());
+ let ref_array = Arc::new(binary.iter().cloned().collect::<BinaryArray>());
+
+ let random_state = RandomState::with_seeds(0, 0, 0, 0);
+
+ let mut binary_hashes = vec![0; binary.len()];
+ create_hashes(&[binary_array], &random_state, &mut binary_hashes)
+ .unwrap();
+
+ let mut ref_hashes = vec![0; binary.len()];
+ create_hashes(&[ref_array], &random_state, &mut ref_hashes).unwrap();
+
+ // Null values result in a zero hash,
+ for (val, hash) in binary.iter().zip(binary_hashes.iter()) {
+ match val {
+ Some(_) => assert_ne!(*hash, 0),
+ None => assert_eq!(*hash, 0),
+ }
+ }
- let random_state = RandomState::with_seeds(0, 0, 0, 0);
- let hashes_buff = &mut vec![0; byte_array.len()];
- let hashes = create_hashes(&[byte_array], &random_state, hashes_buff)?;
- assert_eq!(hashes.len(), 3,);
+ // same logical values should hash to the same hash value
+ assert_eq!(binary_hashes, ref_hashes);
- Ok(())
+ // Same values should map to same hash values
+ assert_eq!(binary[0], binary[5]);
Review Comment:
👍
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org