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

   ## Description
   
   This PR fixes [Bug #11696](https://github.com/apache/seatunnel/issues/11696) 
where `CEIL`, `FLOOR`, `ROUND`, `MOD`, and `TRUNC`/`TRUNCATE` functions 
silently corrupt `BIGINT` and `DECIMAL` values in the Zeta SQL transform-v2.
   
   ### Root Causes
   
   1. **CEIL/FLOOR** always returned `Integer` via `.intValue()`, truncating 
Long and BigDecimal precision
   2. **ROUND** for BigDecimal cases used 
`BigDecimal.valueOf(v1.doubleValue())`, losing precision through double 
conversion
   3. **MOD** used `BigDecimal.valueOf(leftValue.doubleValue())` for both 
operands, and the divide-by-zero check used `rightValue.doubleValue() == 0` 
which underflows for tiny non-zero divisors
   4. **ZetaSQLType** hardcoded CEIL/CEILING/FLOOR as `INT_TYPE` and 
TRUNC/TRUNCATE as `DOUBLE_TYPE`, regardless of the actual input type
   
   ### Changes
   
   #### NumericFunction.java
   - **CEIL/FLOOR**: Changed return type from `Integer` to `Number`, preserving 
the input type (Integer to Integer, Long to Long, BigDecimal to BigDecimal, 
etc.)
   - **ROUND** (BigDecimal): Changed `BigDecimal.valueOf(v1.doubleValue())` to 
`(BigDecimal) v1` to preserve precision
   - **MOD**: Changed `BigDecimal.valueOf(doubleValue())` to `new 
BigDecimal(toString())` for both operands. Changed divide-by-zero check from 
`doubleValue() == 0` to `BigDecimal.compareTo(BigDecimal.ZERO) == 0`
   
   #### ZetaSQLType.java
   - **CEIL/CEILING/FLOOR**: Changed from `BasicType.INT_TYPE` to return the 
same type as the first argument
   - **TRUNC/TRUNCATE**: Changed from `BasicType.DOUBLE_TYPE` to return the 
same type as the first argument
   
   #### Test updates
   - Updated `NumericFunctionTest` expectations for CEIL/FLOOR of Double inputs 
(now returns Double instead of Integer)
   - Added tests for Long inputs (preserves Long), BigDecimal inputs (preserves 
BigDecimal), and BigDecimal MOD precision preservation
   - Added test for MOD with a divisor that underflows to `0.0` in double
   - Updated `SQLNumericFunctionsTest` expectations for CEIL/FLOOR of Double 
columns
   
   ### Testing
   
   - All 47 tests in the affected test classes pass (ZetaSQLTypeTest, 
ZetaSQLFunctionTest, ZetaSQLEngineTest, SQLNumericFunctionsTest, 
NumericFunctionTest)
   
   ### Checklist
   
   - [x] Bug fix
   - [x] Tests updated
   - [x] Build passes with `mvn compile -pl seatunnel-transforms-v2 -am 
-DskipTests`
   
   Closes #11696


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