SEPURI-SAI-KRISHNA opened a new pull request, #12182: URL: https://github.com/apache/seatunnel/pull/12182
### Purpose of this pull request Close #12179 `ZetaSQLType` derives the `MOD` result type from the second argument, so `MOD(int_col, tinyint_col)` is planned as `TINYINT`. `NumericFunction.mod` dispatched only on `Integer`, `Long`, `Float`, `Double` and `BigDecimal`, so the same expression failed at runtime: ``` Unsupported arg type java.lang.Byte of function MOD ``` `docs/en/transforms/sql-functions.md` already documents the contract as `MOD(dividendNumeric, divisorNumeric) -> type(divisorNumeric)`, so the planner and the documentation already agreed with each other, and only the runtime disagreed. This adds the two missing branches so the runtime matches both. No range check is needed. `BigDecimal.divideAndRemainder` guarantees that the remainder is smaller in magnitude than the divisor, so a remainder produced from a `TINYINT` divisor always fits a `byte` and one from a `SMALLINT` divisor always fits a `short`. That is different from the rounding family in #11926, where the result can genuinely exceed the argument type. ### Does this PR introduce _any_ user-facing change? Yes, as a bug fix within the unreleased `dev` branch. `MOD` with a `TINYINT` or `SMALLINT` divisor previously threw at runtime even though the transform planned successfully, so the job failed only once rows started flowing. It now returns a `TINYINT` or `SMALLINT` result, matching the declared output schema. No documentation change is required because the documented behavior was already the correct one. ### How was this patch tested? Two tests were added, and both fail on `dev` before the fix with `TransformException` and pass after it. `NumericFunctionTest.testModSupportsTinyIntAndSmallIntDivisors` covers the reported path end to end through `SQLEngine`. It asserts that `typeMapping` declares `TINYINT` and `SMALLINT` for the two projections and that `transformBySQL` then returns values of exactly those types, so the schema and the runtime are checked against each other in one place. `NumericFunctionTest.testModForDifferentResultTypes` was extended with the unit level cases, including `Byte.MIN_VALUE` and `Short.MIN_VALUE` divisors. Those are the widest possible divisors of each type and are the inputs that would overflow if the remainder were not bounded, so they pin the reasoning behind the missing range check. ``` ./mvnw -pl seatunnel-transforms-v2 -Dskip.spotless=true test Tests run: 1110, Failures: 0, Errors: 0, Skipped: 0 ``` `./mvnw -pl seatunnel-transforms-v2 spotless:check` passes. -- 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]
