shinzoxD opened a new pull request, #24399: URL: https://github.com/apache/datafusion/pull/24399
## Which issue does this PR close? - Closes #22261. ## Rationale for this change `SELECT log(0.0::float8)` currently returns `-inf`. PostgreSQL raises `ERROR: cannot take logarithm of zero`. This is the same class of domain error already accepted for `sqrt` of a negative number (#22260 / #22308), `power(0, negative)` (#22272), and `factorial` of a negative number (#22270). IEEE 754 would yield `-inf`; PostgreSQL treats it as undefined. A previous attempt (#22564) grew into a log-function refactor (simplification rewrites, `log(1, 64)`, etc.) and was closed. This PR stays scoped to the issue: reject a **zero value** at evaluation time. ## What changes are included in this PR? - `log` now returns `cannot take logarithm of zero` when the number being logged is zero (including `-0.0`, float32/float64, and decimal zeros). - A zero *base* (`log(0, 64)`) and `log(1, 64)` are unchanged. Those are separate compatibility cases. - Existing `log` simplifications (`log(a, 1) => 0`, `log(a, a) => 1`, `log(a, power(a, b)) => b`) are unchanged. - User-guide note updated: it still claimed `log(0)` returns `-inf` and `sqrt(-1)` returns `NaN`, both of which are now domain errors. ## Are these changes tested? Yes. - Unit tests in `datafusion/functions/src/math/log.rs` cover unary/binary float64, float32, `-0.0`, array input, decimal128, and decimal256. - `math.slt` adds the issue query plus two-arg, negative-zero, column, and decimal cases, matching the style of the `power(0, -1)` tests. - `scalar.slt` updates the previous `log(0) => -Infinity` expectation to the domain error, and keeps `log(1, 64) => Infinity`. Ran: - `cargo test -p datafusion-functions --lib math::log` - `cargo clippy -p datafusion-functions --lib -- -D warnings` - `cargo test -p datafusion-sqllogictest --test sqllogictests -- math.slt` - `cargo test -p datafusion-sqllogictest --test sqllogictests -- scalar.slt` (log cases pass; later failures are missing `testing` submodule testdata for `aggregate_test_100`, unrelated) ## Are there any user-facing changes? Yes. `log(0)`, `log(0.0::float8)`, and other zero values now fail the query with `cannot take logarithm of zero` instead of returning `-inf`. Queries that relied on the IEEE result need to filter zeros first. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
