raushanprabhakar1 opened a new pull request, #22278: URL: https://github.com/apache/datafusion/pull/22278
## Which issue does this PR close? - Closes #22270 ## Rationale for this change PostgreSQL returns a domain error for `factorial` on negative inputs (`ERROR: factorial of a negative number is undefined`). DataFusion incorrectly returned `1` for negative values (e.g. `factorial(-1)`), which breaks PostgreSQL-aligned SQL semantics and can silently produce wrong results. ## What changes are included in this PR? - **`factorial` (core / `datafusion-functions`):** Negative arguments now fail with an execution error and message aligned with PostgreSQL: `factorial of a negative number is undefined`, instead of returning `1`. - **Documentation:** Updated the `#[user_doc]` description so it matches behavior (non-negative inputs; error on negative values and on overflow). - **Tests:** Added a sqllogictest in `math.slt` that expects this error for `factorial(-1)`. **Note:** Spark’s `factorial` in `datafusion-spark` is unchanged (PySpark-style nulls for out-of-domain values). ## Are these changes tested? Yes. A sqllogictest was added in `datafusion/sqllogictest/test_files/math.slt` for `SELECT factorial(-1)`. ## Are there any user-facing changes? Yes. `factorial` with a negative argument now errors at execution time instead of returning `1`. This matches PostgreSQL and fixes incorrect results; callers that relied on the old behavior would need to adjust. No public Rust API breakage in exported types; behavior change is SQL/UDF semantics for negative inputs. -- 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]
