fix: widen power(decimal, float) to Float64, fix bugs#22482
Conversation
|
cc @theirix since worked on the decimal part for this before |
passes in main, fails in PR. |
|
Please fix the slt tests that are failing - math.slt, expr.slt, push_down_filter_regression.slt |
783cef6 to
6b3e7cc
Compare
|
@Omega359 thanks, fixed. |
|
Thanks, this is a real regression. The main question is whether we should use a decimal or a float output type. |
We could follow DuckDB and others by always returning a float output type, but to me it seems unfortunate to lose exact precision for the
AFAIK this PR should work fine in that scenario (I'm working on this in part because I want to flip |
Which issue does this PR close?
power(decimal, float)should return float #22472.Rationale for this change
This PR makes several improvements to the
powerUDF:Previously,
power(decimal, float)returneddecimal, 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)returned39. Instead, this PR changespower(decimal, float)to return aFloat64instead.simplifyforpowercould sometimes have resulted in mismatches between the declared return type of the function and the simplified expression. Change this to insert casts instead.Previously,
power(decimal, int-array)converted its inputs toFloat64, 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 undesirable because it loses precision. The behavior here was also inconsistent with the behavior forpower(decimal, int-scalar).Benchmarks (Arm64):
What changes are included in this PR?
Are these changes tested?
Yes; new tests added.
Are there any user-facing changes?
Yes; this commit changes the behavior of
powerwith a decimal base. In most cases this is a clear improvement; one slight regression is that thedecimalcode path forpoweris more likely to needlessly overflow (#22480); I will fix that in a followup PR.