Skip to content

fix: reject negative logarithm inputs#22738

Closed
puneetdixit200 wants to merge 1 commit into
apache:mainfrom
puneetdixit200:fix/22271-log-domain-error
Closed

fix: reject negative logarithm inputs#22738
puneetdixit200 wants to merge 1 commit into
apache:mainfrom
puneetdixit200:fix/22271-log-domain-error

Conversation

@puneetdixit200

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

PostgreSQL-compatible logarithm behavior should reject negative inputs instead of returning NaN. DataFusion already keeps the existing zero/base-one edge cases, so this change is scoped to negative logarithm arguments.

What changes are included in this PR?

  • Adds a positive-domain check for ln, log2, and log10.
  • Adds the same negative-value check to log(...) for float and decimal inputs.
  • Updates scalar sqllogictests and log unit tests to cover the new error behavior while keeping existing zero/base behavior unchanged.

Are these changes tested?

  • cargo fmt --all
  • cargo test -p datafusion-functions log --lib
  • cargo test --profile=ci --test sqllogictests -- scalar.slt
  • cargo clippy --all-targets --all-features -- -D warnings

Are there any user-facing changes?

Yes. Negative logarithm inputs now return a domain error instead of NaN.

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels Jun 3, 2026
@kumarUjjawal

Copy link
Copy Markdown
Contributor

@puneetdixit200 Isn't this the same PR you opened previously which already had another PR.

I would appreciate it if you look at the linked pr in the issue before opening a new one.

@puneetdixit200

Copy link
Copy Markdown
Contributor Author

Closing this as a duplicate of #22276. I missed the existing linked PR when reopening this scope; sorry for the noise.

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

2 participants