presto
presto copied to clipboard
(v2) Fix ROUND() returning incorrect results for edge cases
This achieves the same as #18451, which was reverted (#18768) because of a performance regression (see comment). Instead of systematically using BigDecimal in round(), we call it only when we detect that we are on an edge case scenario of num*factor overflowing a long.
Test plan -
Unit test: mvn -Dtest="TestMathFunctions" test
Performance: SqlRoundBenchmark.java (did not commit it):
- result for the original round() (that is wrong for edge cases)
- result for the version that systematically uses BigDecimal (performance regression)
- result for this PR's version (no performance regression)
== NO RELEASE NOTE ==
Can you add the benchmark that you said did not commit so we can be sure? Thanks!
Can you add the benchmark that you said did not commit so we can be sure? Thanks!
I put the link to the gist in the PR description. Do you want me to commit it?
BTW, many thanks for working on this bug fix, appreciate it!
Can you please add the Benchmark as well ?
Ok, I committed the benchmark as well.