xiedeyantu opened a new pull request, #22306:
URL: https://github.com/apache/datafusion/pull/22306

   ## Which issue does this PR close?
   
   - Closes #22259.
   
   ## Rationale for this change
   
   `factorial` was previously implemented using an `Int64` lookup table, which 
caused `factorial(21)` to fail with an overflow error. This differs from 
PostgreSQL, which returns an exact numeric result for this input.
   
   This change improves PostgreSQL compatibility by allowing `factorial` to 
return exact results beyond the `i64` boundary, while still preserving overflow 
behavior once the supported decimal range is exceeded.
   
   ## What changes are included in this PR?
   
   - Change `factorial` to return `Decimal256(76, 0)` instead of `Int64`.
   - Preserve the existing lookup-table fast path for values up to `20!`.
   - Extend factorial computation beyond the lookup-table range using checked 
`i256` multiplication.
   - Keep overflow behavior for inputs whose factorial exceeds the supported 
`Decimal256` range.
   - Add and update sqllogictest coverage for the new result and return type.
   
   ## Are these changes tested?
   
   Yes.
   
   This PR updates sqllogictest coverage for `factorial`, including:
   - exact result validation for `factorial(21)`
   - return type validation for the new decimal result
   - updated expectations for existing scalar and columnar factorial queries
   
   Validated with:
   
   ```bash
   cargo test -p datafusion-sqllogictest --test sqllogictests scalar
   ```
   
   ## Are there any user-facing changes?
   
   Yes.
   
   `factorial(21)` now returns `51090942171709440000` instead of raising an 
overflow error, and the return type of `factorial` is now `Decimal256(76, 0)` 
rather than `Int64`.
   


-- 
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]

Reply via email to