fatmanverse opened a new pull request, #12920:
URL: https://github.com/apache/seatunnel/pull/12920

   Fixes #12915
   
   ### Purpose of this pull request
   
   `SystemFunction#castAs` rounded `CAST(x AS DECIMAL(p,s))` with 
`RoundingMode.CEILING` for DECIMAL and STRING sources, and with `HALF_UP` for 
FLOAT and DOUBLE (#11523). (Integral sources took the CEILING branch too, but 
never drop digits.) The same value gave a different DECIMAL depending on its 
source type, and the CEILING results differ from `CAST` in MySQL, PostgreSQL 
and H2: `CAST(1.21 AS DECIMAL(6,1))` gave `1.3` and `CAST(-1.25 AS 
DECIMAL(6,1))` gave `-1.2`.
   
   All source types now round half away from zero. Float/Double are still 
converted from their exact binary value first, as #11523 introduced.
   
   Impact checked:
   
   - Only the DECIMAL branch of `castAs` changes. `CEIL`/`CEILING`, `FLOOR`, 
`ROUND` and `TRUNC` in `NumericFunction` keep their own rounding modes.
   - Casts that do not drop digits are unchanged. The e2e configs that cast to 
DECIMAL (`func_system.conf`: `"12.4"` -> `12.40`, a BIGINT -> 
`1687747869032.0000`; `jdbc_to_jdbc_with_transform.conf`) do not drop digits.
   - `SystemFunctionTest#testCastAsDecimalRounding` pinned the CEILING result 
(`"1.234"` -> `1.24`); it now expects `1.23`.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. Casting a DECIMAL or STRING value to a smaller scale can return a 
different last digit. This is documented in `incompatible-changes.md` (en/zh), 
and the CAST section of `sql-functions.md` (en/zh) now states the rounding rule.
   
   ### How was this patch tested?
   
   - `SystemFunctionTest`: DECIMAL, STRING and DOUBLE sources give the same 
result for positive, negative, tie and below-half values, integral sources are 
unchanged, and the same check runs through the SQL transform. 
`seatunnel-transforms-v2` unit tests pass on JDK 17, except 
`LLMBooleanOutputTest#readsLegacyFactoryWrapperWithValidationDisabled`, which 
fails the same way on dev (`InvalidClassException` on 
`AbstractMultiCatalogTransform`).
   - On a Zeta cluster, FakeSource -> Sql -> Jdbc (MySQL) with `1.21`, `-1.21`, 
`-1.25` as DECIMAL, STRING and DOUBLE: before `1.3/1.3/1.2`, `-1.2/-1.2/-1.2`, 
`-1.2/-1.2/-1.3`; now `1.2`, `-1.2`, `-1.3` for all three, the same as MySQL 
`CAST`.
   
   ### Check list
   
   * [ ] If any new Jar binary package adding in your PR, please add License 
Notice according
     [New License 
Guide](https://github.com/apache/seatunnel/blob/dev/docs/en/developer/new-license.md)
   * [x] If necessary, please update the documentation to describe the new 
feature. https://github.com/apache/seatunnel/tree/dev/docs
   * [x] If necessary, please update `incompatible-changes.md` to describe the 
incompatibility caused by this PR.
   


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