fix: ln() error on non-positive input (PostgreSQL compat)#22579
Open
telleroutlook wants to merge 1 commit into
Open
fix: ln() error on non-positive input (PostgreSQL compat)#22579telleroutlook wants to merge 1 commit into
telleroutlook wants to merge 1 commit into
Conversation
PostgreSQL raises "cannot take logarithm of a negative number" for ln(-1). DataFusion currently returns NaN. Add input validation to match PostgreSQL behavior, using the same pattern as sqrt(). Closes apache#22271
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?
Closes #22271.
Rationale for this change
ln(-1.0::float8)returns NaN in DataFusion but PostgreSQL raises an error: "cannot take logarithm of a negative number". This is one of the PostgreSQL compat issues tracked in #22247.What changes are included in this PR?
validate_ln_inputthat errors when input ≤ 0make_math_unary_udf!forLnFunc, same pattern assqrt()Are these changes tested?
Existing math tests pass. The validator follows the same pattern as
validate_sqrt_inputwhich is well-tested.Are there any user-facing changes?
Yes —
ln(x)now returns an error for x ≤ 0 instead of NaN. This is a behavior change toward PostgreSQL compatibility.