Skip to content

Reject negative ln inputs#22276

Open
akmhatey-ai wants to merge 2 commits into
apache:mainfrom
akmhatey-ai:codex/ln-negative-input-error
Open

Reject negative ln inputs#22276
akmhatey-ai wants to merge 2 commits into
apache:mainfrom
akmhatey-ai:codex/ln-negative-input-error

Conversation

@akmhatey-ai
Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

DataFusion currently returns NaN for negative ln inputs. PostgreSQL raises an error for the same case, and issue #22271 tracks aligning ln((-1.0)::float8) with that behavior.

This keeps the existing ln(0) behavior unchanged.

What changes are included in this PR?

  • Move ln from the shared unary math macro to a dedicated LnFunc implementation.
  • Return a compute error when ln receives a negative Float32 or Float64 value.
  • Update scalar.slt to cover positive column inputs plus negative scalar and column error cases.

Are these changes tested?

Yes. I ran:

  • cargo fmt --check -- datafusion/functions/src/math/mod.rs datafusion/functions/src/math/ln.rs
  • cargo check -p datafusion-functions
  • cargo test -p datafusion-functions math::ln --lib
  • cargo test -p datafusion-sqllogictest --test sqllogictests -- scalar:586
  • cargo test -p datafusion-sqllogictest --test sqllogictests -- scalar:593
  • cargo test -p datafusion-sqllogictest --test sqllogictests -- scalar:597
  • git diff --check

I also ran cargo test -p datafusion-sqllogictest --test sqllogictests -- scalar. The changed ln records passed, but the full file failed later at scalar.slt:1546+ because local aggregate_test_100 data was empty in this checkout; those failures were unrelated to this change.

Are there any user-facing changes?

Yes. ln now errors on negative inputs instead of returning NaN.

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant