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

   ## Which issue does this PR close?
   
   - Closes #22260.
   
   ## Rationale for this change
   
   DataFusion previously returned `NaN` for `sqrt` on negative floating-point 
inputs, for example `sqrt((-1.0)::float8)`. This differs from PostgreSQL 
semantics, which raise an error for square root of a negative number.
   
   This change makes `sqrt` return an execution error for out-of-domain 
negative inputs so its behavior is closer to PostgreSQL and avoids silently 
producing `NaN` for invalid inputs.
   
   ## What changes are included in this PR?
   
   - Updated the unary math UDF helper to support an optional validator 
callback for runtime input validation.
   - Switched `sqrt` to use a named validator helper instead of inline 
predicate and error-string arguments.
   - Added runtime validation for `sqrt` so negative inputs now raise `cannot 
take square root of a negative number`.
   - Updated sqllogictests for `sqrt`:
     - negative literal inputs now expect an error
     - negative column inputs now expect an error
     - positive column coverage was retained using in-domain inputs
   
   ## Are these changes tested?
   
   Yes.
   
   The change is covered by existing SQL logic tests and targeted validation 
runs:
   
   - `cargo test -p datafusion-functions sqrt`
   - `cargo test -p datafusion-sqllogictest --test sqllogictests scalar`
   
   ## Are there any user-facing changes?
   
   Yes.
   
   `sqrt` now raises an execution error for negative inputs instead of 
returning `NaN`. This changes user-visible query behavior to better align with 
PostgreSQL semantics.


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