zhengxiang378928908-code commented on PR #12920:
URL: https://github.com/apache/seatunnel/pull/12920#issuecomment-6378434477

   Thanks @fatmanverse, moving DECIMAL and STRING from `CEILING` to `HALF_UP` 
looks right. Could we qualify the database-equivalence wording in 
`incompatible-changes.md` and the source-type equivalence comments in the 
tests? The `sql-functions.md` note already explains that FLOAT and DOUBLE are 
converted from their exact binary values. That means the same decimal spelling 
can still produce different results across source types: the exactly 
representable `1.25` test doesn't cover cases such as `1.15`, `2.675` and 
`1.005`.
   
   On this branch (`7c4b22ea1`), `SystemFunction.castAs` gives (target scale in 
parentheses):
   
   | value | STRING / DECIMAL | DOUBLE | FLOAT |
   |---|---|---|---|
   | `1.15` (1) | 1.2 | 1.1 | 1.1 |
   | `2.675` (2) | 2.68 | 2.67 | 2.67 |
   | `1.005` (2) | 1.01 | 1.00 | 1.00 |
   | `-1.15` (1) | -1.2 | -1.1 | -1.1 |
   
   For comparison, `CAST(col AS DECIMAL(20,s))` on a `DOUBLE` / `FLOAT` column:
   
   | value | MySQL 8.0.46 DOUBLE | MySQL FLOAT | PostgreSQL 16.15 `float8` | 
PostgreSQL `float4` |
   |---|---|---|---|---|
   | `1.15` (1) | 1.2 | 1.1 | 1.2 | 1.2 |
   | `2.675` (2) | 2.68 | 2.67 | 2.68 | 2.68 |
   | `1.005` (2) | 1.01 | 1.00 | 1.01 | 1.01 |
   | `-1.15` (1) | -1.2 | -1.1 | -1.2 | -1.2 |
   
   For these four inputs, SeaTunnel's FLOAT results agree with MySQL FLOAT, 
while its DOUBLE results differ from both MySQL DOUBLE and PostgreSQL `float8`. 
PostgreSQL `float4` also differs from SeaTunnel FLOAT in these examples. I 
haven't checked H2.
   
   This predates this PR: #11523 introduced the exact-binary conversion and 
`HALF_UP` for FLOAT/DOUBLE. `BigDecimal.valueOf(double)` gives `1.2`, `2.68` 
and `1.01` for the positive DOUBLE examples and still gives `0.10` for `0.1d` 
at scale 2 with `HALF_UP`, but changing the DOUBLE conversion would be a 
separate compatibility decision.
   
   Could the compatibility note say that all source types now use `HALF_UP`, 
while FLOAT/DOUBLE keep the exact-binary conversion and can therefore differ 
from STRING/DECIMAL and from database casts near a rounding boundary? A `1.15d` 
at scale 1 case in the test would make that explicit.
   


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

Reply via email to