feat: add Spark-compatible hypot function#23774
Open
KarpagamKarthikeyan wants to merge 3 commits into
Open
Conversation
Author
|
cc @Jefffrey @andygrove — this is my first contribution, so CI is currently awaiting a committer's approval. Would really appreciate a trigger when you have a moment. This adds a Spark-compatible Thanks! |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Which issue does this PR close?
datafusion-sparkSpark Compatible Functions #15914Rationale for this change
Spark provides
hypot(expr1, expr2), which returnssqrt(expr1^2 + expr2^2)computed without intermediate overflow or underflow. It was not yet implemented indatafusion-spark— only an auto-generated test stub existed atspark/math/hypot.sltwith its query commented out.What changes are included in this PR?
SparkHypot(implementingScalarUDFImpl) indatafusion/spark/src/function/math/hypot.rs, backed by Rust'sf64::hypot— the same overflow-safe algorithm as Java/Spark'sMath.hypot.datafusion/spark/src/function/math/mod.rs.hypot.sltsqllogictest.The signature is
exact(Float64, Float64) -> Float64, following thedatafusion-sparkconvention of only accepting types Spark supports. Computation uses the Arrowbinarykernel so NULL in either argument propagates to a NULL result, matching Spark.Are these changes tested?
Yes —
datafusion/sqllogictest/test_files/spark/math/hypot.sltcovers:hypot(3, 4)→ 5,hypot(5, 12)→ 13),hypot(3e200, 4e200)stays finite, whereas a naivesqrt(a^2 + b^2)would overflow toInfinity.Are there any user-facing changes?
Yes — adds the Spark-compatible
hypotscalar function todatafusion-spark. No breaking changes to public APIs.