[CALCITE-6395] Significant precision loss when representing REAL literals#3782
Conversation
|
This PR actually removes some code to fix a bug. Should be easy to review! |
| return o; | ||
| } | ||
| return new BigDecimal(((Number) o).doubleValue(), MathContext.DECIMAL32) | ||
| .stripTrailingZeros(); |
There was a problem hiding this comment.
I wonder whether will we have similar issue with
CAST(FLOAT AS VARCHAR)calcite/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
Lines 3511 to 3520 in 19debd3
There was a problem hiding this comment.
Frankly I don't understand why in that place the float has to be converted to a decimal and then to a string. One can do the conversion directly. The question is whether I fix this in this PR or file another issue. If it's small enough I will bundle it here.
There was a problem hiding this comment.
The truth is that float only has about 7 decimal digits of precision, so one could argue that the original answer provided by Calcite was legal. However, it makes it much easier to test code if the result provided by Calcite for CAST(CAST string AS REAL) AS BIGINT) is the same as the Java result of (long)Float.parseFloat(string), at least when running on the same CPU.
There was a problem hiding this comment.
I have fixed this path as well in a subsequent commit.
Just because Calcite uses Decimal literals to represent FP values doesn't mean it has to convert to Decimal when converting to strings.
|
Thanks for fixing that, also checked that there is no more usages of |
…rals Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
|



No description provided.