fixing factorial negative values#22278
Open
raushanprabhakar1 wants to merge 1 commit into
Open
Conversation
Contributor
Author
|
Hi @Dandandan , requesting you to review. Thanks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
factorialof a negative value should error #22270Rationale for this change
PostgreSQL returns a domain error for
factorialon negative inputs (ERROR: factorial of a negative number is undefined). DataFusion incorrectly returned1for 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 returning1.#[user_doc]description so it matches behavior (non-negative inputs; error on negative values and on overflow).math.sltthat expects this error forfactorial(-1).Note: Spark’s
factorialindatafusion-sparkis unchanged (PySpark-style nulls for out-of-domain values).Are these changes tested?
Yes. A sqllogictest was added in
datafusion/sqllogictest/test_files/math.sltforSELECT factorial(-1).Are there any user-facing changes?
Yes.
factorialwith a negative argument now errors at execution time instead of returning1. 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.