You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "neilconway (via GitHub)" <gi...@apache.org> on 2026/05/30 17:14:31 UTC
[PR] fix: Remove `power(decimal, int)` code path [datafusion]
neilconway opened a new pull request, #22651:
URL: https://github.com/apache/datafusion/pull/22651
## Which issue does this PR close?
- Closes #22480
- Closes #22510
## Rationale for this change
`power(decimal, int)` attempts to compute `power` without loss of precision. For negative exponents, the code did the computation in `Float64` and then cast the result back to `decimal`. Unfortunately, the previous implementation got this wrong: using the precision of the base might not be sufficient to accurately represent the result. It seems simpler to return `Float64` for the negative exponent case.
We could potentially try to return `decimal` for non-negative exponents and `Float64` for negative exponents, but that is complicated, and also means that the code would produce different results for literal arguments vs. columnar arguments, which I think should be avoided.
On reflection, it seems simplest to just remove the `power(decimal, int)` code path entirely, and have `power` always return `Float64`. This also fixes another issue in the decimal code path (#22480)
## What changes are included in this PR?
* Remove `power(decimal, ...)` support; both args will be coerced to Float64 if necessary, and the function will always return Float64
* Update SLT
* Add new test cases for #22480 and #22510
## Are these changes tested?
Yes.
## Are there any user-facing changes?
Yes, `power(decimal, ...)` will now return `Float64`.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Remove `power(decimal, int)` code path [datafusion]
Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey merged PR #22651:
URL: https://github.com/apache/datafusion/pull/22651
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Remove `power(decimal, int)` code path [datafusion]
Posted by "neilconway (via GitHub)" <gi...@apache.org>.
neilconway commented on PR #22651:
URL: https://github.com/apache/datafusion/pull/22651#issuecomment-4583905477
@theirix @Jefffrey curious what you think
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Remove `power(decimal, int)` code path [datafusion]
Posted by "theirix (via GitHub)" <gi...@apache.org>.
theirix commented on PR #22651:
URL: https://github.com/apache/datafusion/pull/22651#issuecomment-4584845335
Thanks for the PR, @neilconway . I had similar reflections on `power` recently, and this change would make sense.
Since `power` and `log` can change scale drastically, fixed-size decimal types are tricky to implement correctly without having an infinite intermediate representation like `BigInt` or Postgres-style infinite decimal. An ideal behaviour for me is determining whether it makes sense to return decimal values based on the arguments and scale, but it essentially shifts computation to the planning phase and doesn't work well with arrays (you can have small and large scales in the same array, but the return type has to stay the same).
Nevertheless, other scale-preserving functions like `round`, `abs`, `gcd`, etc still benefit from a decimal implementation since they carry the same type across operations.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Remove `power(decimal, int)` code path [datafusion]
Posted by "neilconway (via GitHub)" <gi...@apache.org>.
neilconway commented on PR #22651:
URL: https://github.com/apache/datafusion/pull/22651#issuecomment-4586757732
@theirix Yep, makes sense to me!
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] fix: Remove `power(decimal, int)` code path [datafusion]
Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey commented on PR #22651:
URL: https://github.com/apache/datafusion/pull/22651#issuecomment-4620908132
thanks @neilconway & @theirix
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org