Repository navigation
Simplify Spark sha2 implementation - #19475
Conversation
| signature: Signature::user_defined(Volatility::Immutable), | ||
| aliases: vec![], | ||
| signature: Signature::coercible( | ||
| vec![ | ||
| Coercion::new_implicit( | ||
| TypeSignatureClass::Native(logical_binary()), | ||
| vec![TypeSignatureClass::Native(logical_string())], | ||
| NativeType::Binary, | ||
| ), | ||
| Coercion::new_implicit( | ||
| TypeSignatureClass::Native(logical_int32()), | ||
| vec![TypeSignatureClass::Integer], | ||
| NativeType::Int32, |
There was a problem hiding this comment.
Moving away from user_defined; also we cast strings to binary to simplify implementation as we only need raw bytes either way
| let mut digest = sha2::Sha224::default(); | ||
| digest.update(value); | ||
| Some(hex_encode(digest.finalize())) | ||
| } | ||
| (Some(value), Some(0 | 256)) => { | ||
| let mut digest = sha2::Sha256::default(); | ||
| digest.update(value); | ||
| Some(hex_encode(digest.finalize())) | ||
| } | ||
| (Some(value), Some(384)) => { | ||
| let mut digest = sha2::Sha384::default(); | ||
| digest.update(value); | ||
| Some(hex_encode(digest.finalize())) | ||
| } |
There was a problem hiding this comment.
We directly use the sha2 crate to do the hashing now; previously we used functions exposed by datafusion-functions but that seemed like unnecessary indirection
| regex = "1.12" | ||
| rstest = "0.26.1" | ||
| serde_json = "1" | ||
| sha2 = "^0.10.9" |
There was a problem hiding this comment.
Because datafusion-spark now uses sha2 directly, we extract it as a common dependency
|
@Jefffrey thank you. |
Performance wasn't on my mind when I did this refactor; I was more focused on trying to get the code in a more readable state. Adding fast paths for scalars should be trivial from this point on, but I'm not sure if I want to add more to this PR as is. Happy to do so if preferred. |
## 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. --> - Part of apache#12725 ## 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. --> Simplify implementation, also remove usage of user_defined. ## 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 to be simpler. ## 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 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. --> No. <!-- If there are any breaking changes to public APIs, please add the `api change` label. --> Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
Which issue does this PR close?
Signature::user_definedfor normal functions #12725Rationale for this change
Simplify implementation, also remove usage of user_defined.
What changes are included in this PR?
Refactor to be simpler.
Are these changes tested?
Added tests.
Are there any user-facing changes?
No.