Skip to content

fix: ln() error on non-positive input (PostgreSQL compat)#22579

Closed
telleroutlook wants to merge 1 commit into
apache:mainfrom
telleroutlook:fix-ln-negative-input-error
Closed

fix: ln() error on non-positive input (PostgreSQL compat)#22579
telleroutlook wants to merge 1 commit into
apache:mainfrom
telleroutlook:fix-ln-negative-input-error

Conversation

@telleroutlook

Copy link
Copy Markdown

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?

  • Add validate_ln_input that errors when input ≤ 0
  • Pass validator to make_math_unary_udf! for LnFunc, same pattern as sqrt()

Are these changes tested?

Existing math tests pass. The validator follows the same pattern as validate_sqrt_input which 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.

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
@github-actions github-actions Bot added the functions Changes to functions implementation label May 27, 2026
@kumarUjjawal

Copy link
Copy Markdown
Contributor

There's already an open pr for this issue #22276

@telleroutlook

Copy link
Copy Markdown
Author

Closing as duplicate of #22276. Thanks @kumarUjjawal for pointing this out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PostgreSQL compatibility: ln(-1.0::float8) should error, not return NaN

2 participants