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

   ## Which issue does this PR close?
   
   - Closes #22472.
   
   ## Rationale for this change
   
   This PR makes several improvements to the `power` UDF:
   
   1. Previously, `power(decimal, float)` returned `decimal`, with the same 
precision as the decimal argument. This resulted in silently truncating the 
results in ways that most users wouldn't expect; for example, 
`power(2.5::decimal(2, 1), 4.0)` returned `39`. Instead, this PR changes 
`power(decimal, float)` to return a `Float64` instead.
   
   2. `simplify` for `power` could sometimes have resulted in mismatches 
between the declared return type of the function and the simplified expression. 
Change this to insert casts instead.
   
   3. Previously, `power(decimal, int-array)` converted its inputs to 
`Float64`, on the argument that this improved performance. Empirically, this 
does not seem to be true any longer (perhaps it was true with older version of 
Arrow). Perhaps more importantly, converting exact numeric types to floating 
point is wrong, because it silently loses precision. The behavior here was also 
inconsistent with the behavior for `power(decimal, int-scalar)`.
   
   On a newly added benchmark, 
   
   ## What changes are included in this PR?
   
   * Implement bugfixes described above.
   * Various refactoring and code cleanup
   * Add new benchmark
   * Update SLT tests
   
   ## Are these changes tested?
   
   Yes; new tests added.
   
   ## Are there any user-facing changes?
   
   Yes; this commit changes the behavior of `power` with a decimal base. In 
most cases this is a clear improvement; one slight regression is that the 
`decimal` code path for `power` is more likely to needlessly overflow (#22480); 
I will fix that in a followup PR.


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