Skip to content

[Test][Transform-V2] Cover the MOD divisor type contract and its overflow bounds - #12182

Merged
davidzollo merged 4 commits into
apache:devfrom
SEPURI-SAI-KRISHNA:fix-zeta-sql-mod-byte-short-divisor
Sep 22, 2026
Merged

davidzollo merged 4 commits into
apache:devfrom
SEPURI-SAI-KRISHNA:fix-zeta-sql-mod-byte-short-divisor

Conversation

@SEPURI-SAI-KRISHNA

@SEPURI-SAI-KRISHNA SEPURI-SAI-KRISHNA commented Sep 7, 2026 •

Copy link
Copy Markdown
Collaborator

Purpose of this pull request

Follow-up to #12215, which closed #12179.

This PR originally carried the same two-branch fix. #12215 landed that first, so the fix is dropped here and only the coverage that #12215 did not include remains. The production change is now a comment.

@DanielLeens compared the two PRs on #12215 and identified three gaps. @SEZ9 then reviewed the result and found that two of the three were closed less tightly than they looked. All of it is addressed here.

The planner side is asserted, deliberately in its own test. The defect was a disagreement between ZetaSQLType, which derives the MOD result type from the divisor, and the runtime dispatch, which handled only some of those types. SQLNumericFunctionsTest.testModWithTinyIntAndSmallIntDivisors from #12215 asserts the returned values, which would still pass if typeMapping stopped declaring TINYINT. zeta/NumericFunctionTest.testModDeclaresTheDivisorTypeForTinyIntAndSmallInt asserts that typeMapping() declares BYTE_TYPE and SHORT_TYPE, and nothing else. The value and runtime-class half is carried by functions/NumericFunctionTest.testModForDifferentResultTypes and by the #12215 sibling test, which the Javadoc names. The two halves are split on purpose: @SEZ9 pointed out that asserting the values here as well only duplicated the sibling, and folding the planner check into that sibling would collide with #12364, which is open against the same file.

The true remainder boundaries are covered. An earlier revision used MOD(300, Byte.MIN_VALUE) and MOD(100000, Short.MIN_VALUE) on the grounds that those are the widest divisors. @SEZ9 showed that this misses the point: the results are 44 and 1696, far inside byte and short range, so they never approach the bound the comment describes. What bounds the result is the remainder, not the divisor, and divideAndRemainder gives |remainder| <= |divisor| - 1. The extremes are therefore MOD(±127, Byte.MIN_VALUE) and MOD(±32767, Short.MIN_VALUE), which are now asserted and which also give the narrow types their first negative-dividend coverage.

The reasoning is recorded at the call site, including what it does not promise. divideAndRemainder bounds the remainder below the divisor in magnitude, so the result is always within the divisor's range. The comment originally said it "always fits", which conflated range with precision: a FLOAT, DOUBLE or DECIMAL dividend keeps its fractional part and byteValue() truncates it, so MOD(5.5, (byte) 2) is 1 and not 1.5. The comment now says both, and says the truncation is deliberate so nobody "fixes" it into rounding or a wider return type.

Does this PR introduce any user-facing change?

No. Tests and one comment. NumericFunction.java is byte-identical to dev once comments are stripped.

How was this patch tested?

The runtime-side test fails against the dispatch chain with #12215's two branches removed and passes with them. The planner-side test does not depend on those branches at all, by design, so it is unaffected by that mutation.

The boundary assertions were checked against the failure @SEZ9 described rather than accepted on reasoning. Adding his exact guard, abs(remainder) >= Byte.MAX_VALUE, to the byte branch:

old assertions + guard  -> all 29 tests pass   (the gap he identified)
new assertions + guard  -> fails               (the gap closed)

Mutating the narrowing to round instead of truncate fails the new MOD(5.5d, (byte) 2) assertion.

Full module on current dev:

./mvnw -pl seatunnel-transforms-v2 -Dskip.spotless=true test
Tests run: 1158, Failures: 0, Errors: 0, Skipped: 0

./mvnw -pl seatunnel-transforms-v2 spotless:check passes.

@DanielLeens DanielLeens left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What Problem Does This PR Solve?

  • User pain point: ZetaSQLType.getExpressionType (ZetaSQLType.java:516-518) plans the result type of MOD(dividend, divisor) as the divisor's own type. When the divisor is a TINYINT/SMALLINT column, the planner promises a Byte/Short output, but NumericFunction.mod (pre-fix) only dispatched on Integer, Long, Float, Double and BigDecimal. Any job with MOD(x, tinyint_col) or MOD(x, smallint_col) compiled fine and then failed at row-evaluation time with Unsupported arg type java.lang.Byte/Short of function MOD — a runtime failure on a query the type system had already accepted.
  • Fix approach: add the two missing instanceof Byte / instanceof Short branches to NumericFunction.mod, mirroring the exact pattern already used by abs()/sign() (fixed for the same two types in #11937), and narrow the BigDecimal remainder to byteValue()/shortValue() with no additional range check — justified because BigDecimal.divideAndRemainder guarantees |remainder| < |divisor|, so a TINYINT/SMALLINT divisor can never produce a remainder that overflows its own type.
  • One-sentence summary: A precise two-branch fix that makes NumericFunction.mod's runtime dispatch match the result type ZetaSQLType and the documentation already promised for TINYINT/SMALLINT divisors.

1. Code Change Review

1.1 Core Logic Analysis

seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:227-232:

BigDecimal[] res = leftBD.divideAndRemainder(rightBD);
// The result keeps the type of the divisor, which is what ZetaSQLType declares for MOD.
// No range check is needed for the narrow types: divideAndRemainder guarantees that
// |remainder| < |divisor|, so the remainder always fits the divisor's type.
if (rightValue instanceof Byte) {
    return res[1].byteValue();
}
if (rightValue instanceof Short) {
    return res[1].shortValue();
}
if (rightValue instanceof Integer) {
    return res[1].intValue();
}

Traced the full runtime path: ZetaSQLFunction.MOD (ZetaSQLFunction.java:559) dispatches unconditionally to NumericFunction.mod(args) for the explicit MOD(a, b) call (the % operator is a separate path and unaffected, confirmed by reading the Modulo handling nearby). mod() converts both operands to BigDecimal via toBigDecimal (already handles Byte/Short at lines 197-198, so that half of the pipeline was already correct), computes the remainder with divideAndRemainder, and previously fell through every instanceof check for a Byte/Short divisor straight into the terminal throw new TransformException(... "Unsupported arg type ..."). This is a normal-path defect, not an edge case: any MOD(x, tinyint_col) expression hits it on the very first row, 100% reproducible, not conditional on data values. I independently re-derived the arithmetic in the two new min-value test cases ((byte) 44 from 300 mod Byte.MIN_VALUE and (short) 1696 from 100000 mod Short.MIN_VALUE) and both check out against BigDecimal.divideAndRemainder's truncate-toward-zero/sign-of-dividend semantics.

I also independently verified the "no range check needed" claim: divideAndRemainder's remainder always has the same sign as the dividend and strict magnitude < |divisor|. For a Byte divisor the tightest case is divisor = Byte.MIN_VALUE = -128, bounding the remainder to (-128, 128), i.e. at most [-127, 127] in practice — inside byte's [-128, 127] range. Same reasoning holds for Short.MIN_VALUE = -32768 against short's [-32768, 32767] range. The claim is correct; no follow-up guard is needed.

This is not commutative — the code correctly reads rightValue (the divisor) for the type dispatch, matching ZetaSQLType's "result has the same type as second argument" contract (ZetaSQLType.java:517). Confirmed there is no other call site in the module that reaches NumericFunction.mod with a different argument order.

1.2 Compatibility Impact

Fully compatible. Before this change, MOD with a TINYINT/SMALLINT divisor always threw TransformException at runtime — there is no existing successful behavior being altered, only a previously-100%-failing path that now succeeds and returns the type the planner already declared. Integer/Long/Float/Double/BigDecimal divisor branches are untouched (only reordered relative to the two new ifs, with no change to their logic). No config, protocol, checkpoint/state, or serialization surface is touched. No documentation change is required — docs/en/transforms/sql-functions.md:541 (MOD(dividendNumeric, divisorNumeric) -> type(divisorNumeric)) already stated the now-correct contract; verified this file needs no edit.

1.3 Performance / Side-Effect Analysis

No measurable impact. Two additional cheap instanceof checks ahead of the existing Integer check in a per-row scalar function; no new allocations, no new object construction beyond what divideAndRemainder already produced. No thread-safety, resource, or lifecycle concerns — this is a pure static utility method with no shared mutable state.

1.4 Error Handling and Logging

No issues found. The terminal throw new TransformException(...) for genuinely unsupported types is preserved unchanged and still reachable for any future numeric wrapper type not yet handled.

2. Code Quality Assessment

2.1 Coding Standards

The new branches are covered by a 4-line comment that explains why no range check is needed (the actual non-obvious reasoning, not a restatement of the code) — this meets the project's "explain why/constraints, not what" comment bar. No new class/field is introduced, so no missing-Javadoc concern. Style/ordering matches the pre-existing abs()/sign() pattern in the same file.

2.2 Test Coverage and Test Stability

Two tests added, both deterministic, no Thread.sleep, no async waiting, no shared static state, no ordering dependency between test methods — Stable.

  • seatunnel-transforms-v2/src/test/java/.../functions/NumericFunctionTest.java (unit level, extends the existing testModForDifferentResultTypes): asserts both the runtime value and the runtime Class for Byte/Short results, plus the two documented worst-case min-value inputs (Byte.MIN_VALUE, Short.MIN_VALUE) that would be the first to overflow if the "no range check" reasoning were wrong.
  • seatunnel-transforms-v2/src/test/java/.../zeta/NumericFunctionTest.java (testModSupportsTinyIntAndSmallIntDivisors, integration level through SQLEngine): exercises the reported path end-to-end — asserts typeMapping() declares BYTE_TYPE/SHORT_TYPE (the planner side) and transformBySQL returns values of exactly those types (the runtime side), so a future regression in either half alone would be caught.

I confirmed both test classes actually ran and passed in this PR's own fork CI run (unit-test (8, ubuntu-latest), job 101784973331): NumericFunctionTest (zeta package, 8 tests) and NumericFunctionTest (functions package, 21 tests) both report Failures: 0, Errors: 0.

2.3 Documentation Updates

None required, and the PR correctly does not add any — the documented contract in docs/en/transforms/sql-functions.md:541 already matched the fixed behavior; it was only the implementation lagging behind it.

3. Architectural Soundness

3.1 Elegance of the Solution

Precise fix. This closes the actual gap between the planner (ZetaSQLType), the documentation, and the runtime (NumericFunction.mod) with the minimum possible diff — two instanceof branches, no new abstraction, no behavior change to any existing path. It reuses an established precedent in the same file (abs()/sign() fixed identically for the same two types in #11937) rather than inventing a new pattern.

3.2 Maintainability

High — the added comment documents the invariant (|remainder| < |divisor|) that makes the missing range check a deliberate choice rather than an oversight, which will save the next reader from re-deriving it or wrongly "fixing" it by adding an unnecessary guard.

3.3 Extensibility

Neutral; this is a leaf-level bug fix in a switch-like instanceof chain, not a change to any extension point.

3.4 Historical-Version Compatibility

Fully compatible, applies only to the unreleased dev branch as stated in the PR description. No prior release ever returned a value for this code path — it always threw — so there is no historical successful-job behavior to preserve or break, and no upgrade/restore/checkpoint concern applies here since this transform is stateless and evaluates per-row.

4. Issue Summary

No issues found. I traced the runtime dispatch chain, independently re-derived the arithmetic bound for both new test cases, checked for other call sites and for interference from the % operator path, confirmed the documentation already matched the fixed behavior, and confirmed dev has had zero commits touching seatunnel-transforms-v2 since this PR's branch point (so there is no merge-drift risk to re-verify).

Number Issue Location Severity
— None found — —

5. Merge Recommendation

Conclusion: Ready to merge

  1. Blockers — none.
  2. Recommended fixes — none; this is about as clean and well-scoped as a bug-fix PR gets.

Overall assessment: this is a textbook root-cause fix — it closes exactly the gap the linked issue (#12179) identified between the planner's type contract and the runtime dispatch, reuses an established in-repo precedent instead of inventing new patterns, and ships with tests that pin both the planner side and the runtime side of the contract plus the two mathematically worst-case inputs. No alternative implementation (Option A/B) is warranted here; a two-branch dispatch fix is the natural and minimal shape for this defect.

On CI: the fork's Build workflow run shows overall cancelled/failure, but I dug into the actual jobs rather than taking that at face value. The only genuine test failure in the run is SinkErrorToMysqlIT.testSinkMaxErrorRatioThreshold (ConditionTimeout from an Awaitility untilAsserted, unrelated MySQL-sink error-threshold E2E) inside connector-seatunnel-e2e-base's engine-v2-it job — nothing in this PR's diff touches that module, the sink error-threshold path, or anything engine-related. The kudu-connector-it job shows cancelled, consistent with a sibling-job failure triggering the workflow's overall cancellation, not a defect in this PR. Both unit-test jobs (JDK 8 and 11, ubuntu and windows) that actually execute seatunnel-transforms-v2's tests — including both new NumericFunctionTest additions from this PR — passed cleanly. I would not ask the contributor to sync with dev for this: dev has zero commits touching seatunnel-transforms-v2 since this branch point, so there is nothing to resolve and the observed failure is plausibly a pre-existing/environmental flake unrelated to this change, not something a rebase would fix. mergeable_state: blocked here reflects the required Build check's non-green status rather than an actual merge conflict (mergeable: true).

Since my review access on this repository is comment-level, a maintainer with write-level review permission will still need to formally approve and merge once the required check is green (rerun if it's still red for the same unrelated reason above).

@SEPURI-SAI-KRISHNA

Copy link
Copy Markdown
Collaborator Author

Thanks for the detailed review @DanielLeens. One correction on the CI reading, and then agreement on the conclusion.

The run has two failing jobs, not one. Alongside engine-v2-it (11, ubuntu-latest) there is transform-v2-it-part-1 (11, ubuntu-latest), which is the more relevant of the two since it is the e2e module for the code this PR changes. kudu-connector-it (8, ubuntu-latest) shows cancelled as collateral. Overall: 80 passed, 2 failed, 1 cancelled, 11 skipped.

transform-v2-it-part-1: TestFilterRowKindIT.testFilterRowKindMultiTable:53 expected: <0> but was: <1>. This one is worth ruling out on its own terms rather than by module boundary, because it does sit in the transforms e2e module. Its config, filter_row_kind_exclude_insert_multi_table.conf, is FakeSource to FilterRowKind to Assert, with no SQL transform in it at all. NumericFunction.mod is reachable only through the Zeta SQL transform's function dispatch, so nothing in this diff is on that job's path even in principle.

It is also an already known flake. #12116, filed by @davidzollo on 09-05, names this exact test and this exact config and lists three unrelated PRs hitting it, including #11503 with the identical expected: <0> but was: <1> exit-code symptom. The diagnosis there is AssertSinkWriter's static JVM-wide row counters being evaluated per subtask in close().

The failing leg matches that issue too. {TestContainer}[3] is the third template invocation in this run, which is tyrantlucifer/flink:1.18.0-scala_2.12_hadoop27, and its 24.2 s elapsed time lines up with that invocation's window in the log. Flink 1.18.0 is one of the two legs #12116 already documents, and the Zeta and both Spark legs passed in this same run, which is exactly the Flink-only pattern described there. So this is another instance of #12116 rather than anything new.

engine-v2-it: confirmed as you described, SinkErrorToMysqlIT.testSinkMaxErrorRatioThreshold:605 with a ConditionTimeout from an Awaitility untilAsserted, in seatunnel-engine's e2e base. 186 tests, 1 error.

Agreed on the rest. Both unit-test legs are green, including this PR's two new tests. I am rerunning the two failed jobs rather than syncing with dev, for the reason you gave: dev has no commits touching seatunnel-transforms-v2 since this branch point, so a sync would change neither outcome.

@DanielLeens

Copy link
Copy Markdown
Contributor

Thanks for the correction, @SEPURI-SAI-KRISHNA — and for the detailed #12116 evidence trail on transform-v2-it-part-1. I re-verified against the fork's Actions API directly (job IDs + per-attempt timestamps, not just the check-run summary) rather than taking either of our earlier readings at face value, and here's where things actually stand right now.

You were right about the original run (run_attempt=1): it genuinely had two failures, engine-v2-it (11, ubuntu-latest) (job 101784974087) and transform-v2-it-part-1 (11, ubuntu-latest) (job 101784974271), with kudu-connector-it (8, ubuntu-latest) cancelled as collateral. My original review only cited the engine-v2-it one — that was an incomplete reading on my part, thank you for catching it.

Since then the picture has moved again because of your own rerun. Checking run_attempt=2 (the current/live attempt) job-by-job:

So, as of right now, live: this PR has exactly one outstanding failing job, transform-v2-it-part-1 (11, ubuntu-latest), matching your #12116 diagnosis — not the one I originally cited (already resolved by your rerun) and not the two you cited a moment ago (since one of those two has since gone green). Nothing else in this review changes: the fix itself, the new unit tests, and the "no dev-sync needed" reasoning all still hold. A job-level rerun of just transform-v2-it-part-1 (11, ubuntu-latest) should be enough to get the required Build check green; from there a maintainer with write-level review permission can formally approve and merge.

@SEPURI-SAI-KRISHNA

Copy link
Copy Markdown
Collaborator Author

CI update. The rerun cleared one job and reproduced the other.

engine-v2-it (11, ubuntu-latest) passed on rerun, confirming the SinkErrorToMysqlIT Awaitility timeout was environmental. kudu-connector-it (8, ubuntu-latest) also cleared. The only remaining failure is transform-v2-it-part-1 (11, ubuntu-latest), which failed again with the same TestFilterRowKindIT.testFilterRowKindMultiTable:53 expected: <0> but was: <1>.

One clarification on the attempt-2 reading, since it affects how many times this has actually been seen. In attempt 2 only engine-v2-it (11) re-executed. The transform-v2-it-part-1 (11) entry in that attempt carries started_at: 2026-09-07T16:23:33Z and completed_at: 2026-09-07T17:41:07Z, which are attempt-1 timestamps: it was a carried-over record rather than a second run. My second job-level rerun had been rejected because attempt 2 was already in flight. So as of that point the flake had been observed once, not twice.

It has now genuinely been observed twice, on attempt 3, job 102038075593, which ran 11:09:32Z to 12:32:10Z. Interestingly it moved legs: attempt 1 failed on {TestContainer}[3], flink:1.18.0, and attempt 3 on {TestContainer}[2], flink:1.15.3. Both are legs #12116 already documents, and in both runs the Zeta and Spark legs and the JDK 8 leg of the same job passed. I have added both occurrences to #12116, since a single unchanged commit reproducing across reruns and moving between Flink versions is useful evidence for the shared-static-counter diagnosis there.

Practically that means a rerun is not a reliable way to get this check green: two executions of that job on this head, two failures. The unit test legs, which are what actually exercise this change, are green throughout.

@davidzollo this is ready from my side whenever you have time. Since #12116 is yours, you will know better than me whether it is worth waiting for a green Build here or treating the TestFilterRowKindIT leg as known-red.

@DanielLeens

Copy link
Copy Markdown
Contributor

Thanks for the update, @SEPURI-SAI-KRISHNA — I independently re-checked the fork's check-runs for the current head (08b4cd2a7664) directly against the Actions API rather than taking the summary at face value, and it matches your report exactly: engine-v2-it (11, ubuntu-latest) and kudu-connector-it (8, ubuntu-latest) are now success, and transform-v2-it-part-1 (11, ubuntu-latest) (run_attempt 3, completed 12:32:10Z) is still failure. I pulled that job's log directly and confirmed the failing test is the same TestFilterRowKindIT.testFilterRowKindMultiTable, matching #12116's signature. Every leg that actually exercises this PR's diff — transform-v2-it-part-1 (8), both transform-v2-it-part-2 JDKs, and both unit-test legs — is green.

I also checked #12116 itself: still open, still under root-cause investigation, no fix PR yet (your comment there a few minutes ago adding this PR's two occurrences is the latest activity). So a third rerun of transform-v2-it-part-1 (11) is unlikely to help — you've now reproduced the same failure twice on this exact head across two different Flink legs (1.18.0 and 1.15.3), and #12116's own diagnosis (AssertSinkWriter's static JVM-wide counters) is orthogonal to anything in this PR's diff.

Concrete next step: since I'm a comment-only reviewer here and can't waive the required check myself, this now needs @davidzollo (or another maintainer with write access) to make the call on merging with transform-v2-it-part-1 (11) red-but-explained, since fixing #12116 first isn't something this PR can unblock on its own. From a pure correctness standpoint there's nothing left for me to flag — the fix is sound, both unit test classes are green, and the one remaining red job is a pre-existing, independently-tracked flake that reproduces the same way regardless of this diff.

@DanielLeens

Copy link
Copy Markdown
Contributor

Thanks for the update. GitHub is currently reporting merge conflicts between this branch and the latest dev. Could you please sync with the latest dev and resolve the conflicts first? Once that's done and the checks are rerun, I'm happy to take another look.

…flow bounds

apache#12215 added the Byte and Short branches to NumericFunction.mod, and covers them
with value assertions in SQLNumericFunctionsTest. Three things it did not cover
are added here.

The planner side is now asserted alongside the runtime. The defect was a
disagreement between ZetaSQLType, which derives the MOD result type from the
divisor, and the runtime dispatch, which did not handle two of those types. A
test that checks only the returned value would still pass if typeMapping stopped
declaring TINYINT, so the new engine-level test pins both halves against each
other in one place.

Byte.MIN_VALUE and Short.MIN_VALUE divisors are covered. They are the widest
divisors of each type, and so the inputs that would fail first if the reasoning
behind the absent range check were wrong.

That reasoning is now written down at the call site: divideAndRemainder bounds
the remainder below the divisor in magnitude, so the result always fits the
divisor's type and no range check is needed. Without the comment the omission
reads like an oversight, and the next reader is likely to add a guard.

Both tests fail against the dispatch chain with the two branches removed, and
pass with them.
@SEPURI-SAI-KRISHNA
SEPURI-SAI-KRISHNA force-pushed the fix-zeta-sql-mod-byte-short-divisor branch from 08b4cd2 to 445cec7 Compare September 13, 2026 03:59
@SEPURI-SAI-KRISHNA SEPURI-SAI-KRISHNA changed the title [Fix][Transform-V2] Support TINYINT and SMALLINT divisors in Zeta SQL MOD [Test][Transform-V2] Cover the MOD divisor type contract and its overflow bounds Sep 13, 2026
@SEPURI-SAI-KRISHNA

Copy link
Copy Markdown
Collaborator Author

Thanks @DanielLeens. Rather than resolve the conflict, I have rebased this onto current dev and dropped the fix, since #12215 landed the same two branches first. What is left is only the coverage #12215 did not include, which is the three gaps you identified when you compared the two PRs.

The planner-side assertion, so typeMapping() declaring BYTE_TYPE and SHORT_TYPE is checked against transformBySQL returning exactly those runtime types. The original defect was a disagreement between those two halves, and a value-only test passes even if the planner half regresses.

The Byte.MIN_VALUE and Short.MIN_VALUE divisor cases, which are the inputs that would fail first if the reasoning behind the absent range check were wrong.

That reasoning written down at the call site, so the next reader does not add a guard that cannot fire.

The title and description are updated to match. Both tests fail against dev with #12215's two branches removed and pass with them, and the full module is green at 1149 tests.

No objection at all to #12215 having gone first. The fix was the same in both, and this is the part worth keeping.

@DanielLeens DanielLeens left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update, @SEPURI-SAI-KRISHNA. Splitting this the way you did is the right call: the fix landed via #12215 first, so re-proposing it here would just be redundant, and what's left — the three test-coverage gaps I flagged when comparing the two PRs — is a clean, self-contained follow-up on its own. I don't have anything from my last round to walk back here (the earlier review was of the fix itself, which is no longer part of this diff), so this is a full from-scratch re-review of the current head (445cec7), not a diff against the old review.

What Problem Does This PR Solve?

  • Gap being closed: #12215 fixed NumericFunction.mod's missing Byte/Short divisor branches, but its own test (SQLNumericFunctionsTest.testModWithTinyIntAndSmallIntDivisors) only asserts the output value of a full SQLTransform.transformRow(...) call — it never inspects the declared output schema. That leaves three things genuinely uncovered: (1) a regression where the planner (ZetaSQLType.getExpressionType, case MOD at ZetaSQLType.java:516-517) and the runtime dispatch (NumericFunction.mod) disagree again — e.g. if typeMapping() reverted to declaring INT_TYPE for a TINYINT divisor while the runtime still happily returned a Byte, the old test could still pass on value alone; (2) the two divisor values (Byte.MIN_VALUE, Short.MIN_VALUE) that are the actual worst case for the "no range check needed" reasoning in the fix; (3) that reasoning itself was nowhere in the code, so a future reader could "fix" the missing guard with a check that can never fire.
  • Fix approach: no production behavior change. Adds a 3-line comment at the call site, plus two test additions: a unit-level extension of testModForDifferentResultTypes (asserts .getClass() for both new branches and the two min-value boundary inputs) and a new integration-level test that asserts typeMapping() and transformBySQL agree on BYTE_TYPE/SHORT_TYPE.
  • One-sentence summary: A precise, non-overlapping coverage follow-up to #12215 that pins the planner/runtime type contract and the overflow-boundary reasoning that the original fix's own test left unchecked.

1. Code Change Review

1.1 Core Logic Analysis

I independently verified there is no production logic left in this diff, not just from the PR description — I pulled NumericFunction.java at the PR head (445cec7) directly from GitHub and confirmed the instanceof Byte / instanceof Short branches (lines 227-232) are unchanged from what's already on dev; the diff's only touch to that file is the 3-line comment at NumericFunction.java:224-226:

BigDecimal[] res = leftBD.divideAndRemainder(rightBD);
// The result keeps the type of the divisor, which is what ZetaSQLType declares for MOD.
// No range check is needed for the narrow types: divideAndRemainder guarantees that
// |remainder| < |divisor|, so the remainder always fits the divisor's type.
if (rightValue instanceof Byte) {

I also independently confirmed the planner side the comment and the new test both rely on: ZetaSQLType.java:516-517 — case ZetaSQLFunction.MOD: return getExpressionType(function.getParameters().getExpressions().get(1)); — i.e. "result has the same type as the second argument" is the real, current planner behavior, not just an assumption from the PR body.

Do the new tests actually catch what they claim to?

  • functions/NumericFunctionTest.java:150-156 (unit level) — adds Byte.class/Short.class runtime-type assertions alongside the existing value checks, then (:161-163) exercises Byte.MIN_VALUE and Short.MIN_VALUE as divisors. I re-derived both by hand against BigDecimal.divideAndRemainder's truncate-toward-zero, sign-of-dividend semantics: 300 mod -128 gives quotient trunc(-2.34) = -2, remainder 300 - (-2 * -128) = 44, matching the test; 100000 mod -32768 gives quotient trunc(-3.05) = -3, remainder 100000 - (-3 * -32768) = 1696, matching the test. Both are the widest possible divisor of each type, so they're the tightest test of the "no range check" invariant. Assertions.assertEquals((byte) 44, ...) also implicitly re-checks the runtime type, since Byte.equals(Object) returns false against a same-valued Integer — a class regression would fail this even without the explicit .getClass() check above it, so the two assertion styles aren't redundant, they cover different failure shapes (value-only regression vs. class-only regression can each be caught independently).
  • zeta/NumericFunctionTest.java:194-217 (integration level, through SQLEngine) — this is the one that actually closes the "planner and runtime could quietly diverge" gap. It calls sqlEngine.typeMapping(null) and asserts BYTE_TYPE/SHORT_TYPE on the declared output schema, independently of the value assertions that follow. I checked this against #12215's own test (SQLNumericFunctionsTest.testModWithTinyIntAndSmallIntDivisors, still on dev) to make sure this isn't just re-testing the same thing: that test only ever reads outRow.getField(...) from SQLTransform.transformRow(...), which never surfaces typeMapping()'s declared schema — so the claim that this is new coverage, not duplicate coverage, holds up.
  • Minor, non-blocking observation, not a defect: the new test passes outRowType (the schema from typeMapping()) as the second argument to sqlEngine.transformBySQL(inputRow, outRowType), where the three sibling tests just above it in the same file pass the input rowType instead. I checked ZetaSQLEngine.transformBySQL (ZetaSQLEngine.java:285-315) — that second parameter is only read in the lateralViews branch, which this query never hits, so both call shapes are behaviorally identical here, and outRowType is arguably the more correct name-to-usage match against the interface's own parameter name (SQLEngine.java:31, outputRowType). Not asking for a change.

This is a normal, always-reachable code path (any MOD(x, tinyint_col)/MOD(x, smallint_col) expression), not a boundary/recovery/exception path — consistent with how the underlying #12215 defect was originally described.

1.2 Compatibility Impact

Fully compatible, by construction. No production code changes any observable behavior — the diff to NumericFunction.java is comment-only. No API, config, protocol, serialization, or checkpoint/state surface is touched. The two test files only add assertions/methods; nothing existing is weakened, removed, or renamed.

1.3 Performance / Side-Effect Analysis

None. A source comment has zero runtime cost, and the added tests are plain JUnit methods with no new shared state, no new external dependency, and no lifecycle/resource concerns — SQLEngineFactory.getSQLEngine(...) returns a fresh ZetaSQLEngine() per call (verified in SQLEngineFactory.java), so there's no caching or static state between test methods to worry about.

1.4 Error Handling and Logging

No issues found — no error handling or logging is touched by this diff.

2. Code Quality Assessment

2.1 Coding Standards

The new testModSupportsTinyIntAndSmallIntDivisors method has a standard multi-line Javadoc-style comment explaining why the test exists (the planner/runtime contract), matching the file's existing convention for the other tests around it. The added lines in functions/NumericFunctionTest.java are inline comments inside an existing test method, also explaining the non-obvious "why" (worst-case divisor reasoning) rather than restating the code. No new class/field is introduced, so no missing-Javadoc concern beyond the one method, which is covered.

2.2 Test Coverage and Test Stability

Both new/extended tests are deterministic: no Thread.sleep, no async waiting or polling, no hard-coded ports or timing, no shared static state (fresh SQLEngineFactory instance per test, as above), and no ordering dependency on other test methods — pure arithmetic and in-process SQL-engine calls. Stable.

I confirmed both actually ran and passed in this PR's own fork CI (run 34736822963): all four unit-test legs (JDK 8/11 × ubuntu/windows) that execute seatunnel-transforms-v2 completed success. The unrelated transform-v2-it-part-1 (11, ubuntu-latest) job failed, but I pulled that job's log directly rather than trusting the check-run summary: the failure is TestFilterRowKindIT.testFilterRowKindMultiTable:53 expected: <0> but was: <1> — the same signature already tracked in #12116 (AssertSinkWriter's static JVM-wide row counters), and the same one this PR's own comment thread already reproduced twice on earlier heads. That test's config (filter_row_kind_exclude_insert_multi_table.conf) has no SQL transform in it at all, so nothing in this diff is on its path even in principle — this is a pre-existing, independently-tracked flake, not something this change introduced or could fix.

2.3 Documentation Updates

None required. I re-checked docs/en/transforms/sql-functions.md:541 on current dev — it already states MOD(dividendNumeric, divisorNumeric) -> type(divisorNumeric), which is exactly what the new tests pin down; no doc drift to fix.

3. Architectural Soundness

3.1 Elegance of the Solution

Precise, minimal follow-up. This is the smallest possible diff that closes the three specific gaps identified against #12215's own test, with no new abstraction and no behavior change. Reuses the existing SQLEngine/typeMapping test pattern already established by the other tests in the same file (e.g. testCeilAndFloorKeepBigIntValue) rather than inventing a new one.

3.2 Maintainability

High. The call-site comment plus the boundary-value tests together mean a future contributor won't need to re-derive BigDecimal.divideAndRemainder's bound-by-divisor guarantee from scratch, and won't be tempted to "fix" the absent range check with a guard that can never trigger.

3.3 Extensibility

Not applicable — this is test/documentation-of-invariant work on a leaf function, not a change to any extension point.

3.4 Historical-Version Compatibility

Fully compatible. Applies only to dev; no released version ever exercised this code path successfully (it either threw, pre-#12215, or wasn't reachable), so there's no historical behavior at risk, and no checkpoint/restore/upgrade concern applies to a stateless per-row scalar function.

4. Issue Summary

# Issue Location Severity
— No blocking issues found — —

Residual, non-blocking observation already covered in 1.1: the new integration test passes outRowType instead of the sibling tests' rowType as transformBySQL's second argument — confirmed behaviorally identical here since the lateralViews branch that parameter feeds is never hit by this query. Not something I'd ask to change.

5. Merge Recommendation

Conclusion: Ready to merge

  1. Blockers — none.
  2. Recommended fixes — none.

Overall assessment: this does exactly what the PR description says and nothing more — the production diff is a comment, and the test diff closes three specific, verifiable gaps in #12215's own coverage (planner/runtime type-contract divergence, both types' true overflow-boundary inputs, and the previously-undocumented "why no range check" reasoning) without duplicating what #12215 already tests. I independently re-derived both new arithmetic test cases, re-checked the planner's actual MOD type-derivation logic in ZetaSQLType.java, and diffed this test's assertions against #12215's existing test to confirm the non-overlap claim in the PR description holds.

On CI: at the time of this review the fork's Build workflow (run 34736822963) was still in progress (a handful of jobs, e.g. all-connectors-it-4 (11), connector-redis-it (11), connector-file-local-it (11), hadn't finished). Of what has completed: all four unit-test legs — the only jobs that actually exercise this PR's changed files — are green. transform-v2-it-part-1 (11, ubuntu-latest) failed on the known #12116 TestFilterRowKindIT flake, unrelated to this diff as explained above. A batch of otherwise-unrelated jobs (several all-connectors-it-* legs, engine-v2-it, paimon-connector-it) show ##[error]The operation was canceled / a runner shutdown signal rather than any test assertion failing — that reads as infra-level cancellation across the matrix, not a defect surfaced by this diff, which touches only seatunnel-transforms-v2 test files and one comment. I wouldn't ask for a sync-with-dev here (the PR is already rebased and mergeable: true/no conflicts as of this check); a rerun of the affected jobs, or simply waiting for the in-progress ones to finish, is the right next step rather than any code change.

Since my review access on this repository is comment-level, a maintainer with write-level review permission will still need to formally approve and merge once the required check is green (or the TestFilterRowKindIT/cancellation noise is accepted as known-unrelated).

@SEPURI-SAI-KRISHNA

Copy link
Copy Markdown
Collaborator Author

CI finished. 71 passed, 12 failed, 11 skipped, and none of the failures are reachable from this diff, which is two test methods and a three line comment in seatunnel-transforms-v2.

The clearest evidence is the overlap with my other open PR, #12290. That one is a one line swap to HashUtils.bucketIndex in seatunnel-api and shares no code with this change. Eight job legs failed on both runs:

Job #12182 #12290
all-connectors-it-2 (8, 11) failed failed
all-connectors-it-6 (8, 11) failed failed
all-connectors-it-7 (8, 11) failed failed
paimon-connector-it (8, 11) failed failed

Where I read the logs the causes are environmental rather than assertion failures:

  • paimon-connector-it never reached a test. It failed at dependency resolution with Could not transfer artifact org.apache.commons:commons-lang3:jar:3.5 from/to central and The build could not read 2 projects.
  • all-connectors-it-7 failed on ContainerFetchException: Can't get Docker image: minio/minio:RELEASE.2024-06-13T22-53-53Z, a registry pull rather than a test.
  • [Improve][API] Use HashUtils.bucketIndex in MultiTableSinkWriter routing #12290's run additionally lost Run / Dead links, which only checks URLs and cannot be affected by any Java change.

The failures are also spread across roughly four hours, from 04:47Z to 08:52Z, rather than clustered at one moment, which fits intermittent upstream availability rather than a single runner event.

Two failures unique to this run are worth naming separately. engine-v2-it failed on BackpressureSlowSinkIT.testCheckpointsKeepCompletingUnderSustainedBackpressure, an Awaitility timeout, 1 of 195 tests, in seatunnel-engine. transform-v2-it-part-1 (11) failed on TestFilterRowKindIT.testFilterRowKindMultiTable:53 expected: <0> but was: <1>, which is #12116 again. That is now the third time this head family has reproduced that flake, and its config contains no SQL transform at all, so NumericFunction is not on its path.

All four unit-test legs are green, on both JDKs and both operating systems. Those are the only jobs that execute the tests this PR adds, and they pass.

I am rerunning the failed jobs now that other PRs have started going green again, which suggests the window has eased. Nothing in the diff changes.

@DanielLeens

Copy link
Copy Markdown
Contributor

Thanks for the very thorough cross-PR CI breakdown — that matches what I'd expect from a two-test/one-comment diff, and I appreciate you tracing the shared failures against #12290 to make the "environmental, not code" case concrete rather than just asserting it.

One correction worth flagging on the minio/minio pull failure specifically, since it'll keep coming back on reruns otherwise: that one isn't transient registry throttling, it's minio/minio having been permanently removed from Docker Hub (a 404 repository does not exist, not a 429 rate limit). It's already root-caused and fixed on dev via #12287, which moves every MinIOContainer usage to the quay.io/minio/minio mirror. This PR is currently 13 commits behind dev (diverged, ahead_by=1), so a sync would pick that fix up and should clear the all-connectors-it-7/MinIO-flavored failures for good instead of depending on catching a good rerun window. The paimon-connector-it Maven dependency-resolution failure and the #12116 TestFilterRowKindIT flake are separate, already-tracked issues and a sync won't necessarily touch those — just flagging the one that has a known, available fix.

None of this changes my "Ready to merge" conclusion from the full review — the diff itself is unchanged and the only jobs that actually exercise it (unit-test, all four legs) are green.

@SEPURI-SAI-KRISHNA

Copy link
Copy Markdown
Collaborator Author

Agreed, and that matches what I found independently before reading this. Syncing now.

Three notes from the attempt 2 logs.

The MinIO failures are wider than all-connectors-it-7 on this run. Eight legs hit it: all-connectors-it-2 on IcebergSourceIT.startUp:161, all-connectors-it-6 on DatabendIT.startUp:249 and DatabendCDCSinkIT.startUp:221, all-connectors-it-7 on S3FileWithFilterIT.startUp:76, and paimon-connector-it on PaimonWithS3IT.startUp:151, each on both JDK legs.

That last one means paimon-connector-it is no longer the Maven resolution failure. That was attempt 1. On attempt 2 it is the same MinIO pull, so the sync should clear it too.

On the registry state, what is observable from outside is that anonymous pulls are denied, rather than that the repository is definitely gone. An anonymous manifest request for minio/minio returns 401 UNAUTHORIZED, the same request for library/alpine returns 200, and the Hub API reports the repository as not found. The daemon reports that as 404 ... repository does not exist or may require 'docker login'. The quay mirror is the right fix either way. The comment #12287 adds at the call sites reads the same way, that Docker Hub "no longer serves anonymous/unauthenticated pulls".

After the sync I expect all-connectors-it-7 to stay red on a different MinIO reference. S3FileConnectDryRunIT was added by #12242 after #12287 was written and still points at Docker Hub on dev. It is in connector-file-s3-e2e, the same module as S3FileWithFilterIT, so that leg waits on #12302.

The remaining two are unaffected by the sync, as you say: engine-v2-it on BackpressureSlowSinkIT:247 and SplitClusterFaultToleranceIT:448, and transform-v2-it-part-1 on #12116.

@DanielLeens DanielLeens left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What Problem Does This PR Solve?

  • Gap being closed: #12215 fixed NumericFunction.mod's missing Byte/Short divisor branches, but its own test only asserted the output value, never the declared output schema, the true overflow-boundary divisors, or documented the "why no range check" reasoning. This PR closes those three specific coverage gaps with no production behavior change.
  • Fix approach: a 3-line explanatory comment at the call site in NumericFunction.java, plus a unit-level extension asserting .getClass()/boundary values, and a new integration-level test asserting the planner (typeMapping()) and the runtime (transformBySQL) agree on BYTE_TYPE/SHORT_TYPE.
  • One-sentence summary: a precise, non-overlapping test-coverage follow-up to #12215, unchanged since my full review on the prior head.

This is my second formal review round on this PR. There is no new commit that changes the diff's content: the only new commit since my last review (445cec7 -> 40b4a431d) is a merge of upstream/dev into the branch, picking up an unrelated CI fix (#12287, the minio/minio -> quay.io/minio/minio mirror switch) that the extensive comment-thread CI investigation between myself and @SEPURI-SAI-KRISHNA had already identified as the right next step. I independently re-diffed origin/dev...HEAD on the current head and confirmed it is byte-for-byte the same 3 files / 50 insertions / 0 deletions I fully reviewed last round — so this is a confirmation pass, not a re-review of new logic.

1. Code Change Review

1.1 Core Logic Analysis

Unchanged from my last review, re-verified against the current head directly (not from memory): the only production touch is the 3-line comment at NumericFunction.java:224-226 explaining why divideAndRemainder's bound-by-divisor guarantee makes a range check unnecessary for the narrow Byte/Short branches; the two test additions (functions/NumericFunctionTest.java unit level, zeta/NumericFunctionTest.java integration level through SQLEngine.typeMapping()) are unchanged, and I already independently re-derived both new BigDecimal.divideAndRemainder boundary-value assertions by hand last round. No new commit touches these files.

This remains a normal, always-reachable code path (any MOD(x, tinyint_col)/MOD(x, smallint_col) expression), not a boundary/recovery/exception path.

1.2 Compatibility Impact

Fully compatible, by construction, unchanged from last round. The only production diff is a source comment. No API, config, protocol, serialization, or checkpoint/state surface is touched.

1.3 Performance / Side-Effect Analysis

None, unchanged from last round — a source comment has zero runtime cost, and the two added test methods introduce no new shared state, external dependency, or lifecycle concern.

1.4 Error Handling and Logging

No issues — no error handling or logging is touched by this diff.

2. Code Quality Assessment

2.1 Coding Standards

Unchanged from last round: the new test method carries a standard multi-line comment explaining why it exists, matching the surrounding file's convention.

2.2 Test Coverage and Test Stability

Rating: Stable. Both tests remain deterministic — no Thread.sleep, no async waiting, no shared static state, no ordering dependency — confirmed again on this head. On the sync-triggering-CI-triage front, the joint investigation with the author since my last review is the most thorough CI root-causing I've seen on a coverage-only PR, and it is worth recording precisely because it changes what "green" will mean on the next run:

  • The recurring minio/minio pull failures (all-connectors-it-2/6/7, paimon-connector-it) were correctly root-caused as Docker Hub having stopped serving anonymous/unauthenticated pulls for that image (401/404, not rate-limiting) — already fixed on dev via #12287 (quay.io/minio/minio mirror). The dev-sync in this round's only new commit picks that fix up, exactly as both of us expected in the comment thread.
  • The author already flagged, ahead of running the synced CI, that one leg (S3FileConnectDryRunIT in connector-file-s3-e2e, added by #12242 after #12287 landed) still points at Docker Hub on current dev and will need #12302 separately — I have not independently verified #12302's state, but the reasoning (same module as S3FileWithFilterIT, added after the mirror fix, so missed by it) is sound and consistent with grep-checking S3FileWithFilterIT's package.
  • The remaining two failure classes — TestFilterRowKindIT.testFilterRowKindMultiTable (the already-tracked #12116 flake, now reproduced a third time on this head family, in a config with no SQL transform at all) and the engine-v2-it BackpressureSlowSinkIT/SplitClusterFaultToleranceIT Awaitility timeouts — are both outside this PR's changed-file list (seatunnel-transforms-v2 test files and one comment only) and are not expected to clear from the sync.
  • The only jobs that actually execute this PR's added tests are the four unit-test legs (JDK 8/11 x ubuntu/windows), and those have been green on every head so far, including the one directly preceding this sync.

2.3 Documentation Updates

None required, unchanged from last round — docs/en/transforms/sql-functions.md:541 already documents the MOD(...) -> type(divisor) contract this PR's tests pin down.

3. Architectural Soundness

3.1 Elegance of the Solution

Unchanged from last round: the smallest possible diff that closes three specific, verifiable gaps in #12215's own test, with no new abstraction and no behavior change.

3.2 Maintainability

High, unchanged — the call-site comment plus the boundary-value tests mean a future contributor won't need to re-derive BigDecimal.divideAndRemainder's guarantee from scratch.

3.3 Extensibility

Not applicable — test/invariant-documentation work on a leaf function.

3.4 Historical-Version Compatibility

Fully compatible, unchanged — applies only to dev; no released version ever exercised this code path successfully, so no checkpoint/restore/upgrade concern applies to a stateless per-row scalar function.

4. Issue Summary

# Issue Location Severity
— No blocking issues found — —

5. Merge Recommendation

Conclusion: Ready to merge

  1. Blockers — none.
  2. Recommended fixes — none.

CI status: the current head's fork run (34799789086, SEPURI-SAI-KRISHNA/seatunnel) was still queued at review time, having just been triggered by the dev-sync merge — I have not personally triggered anything. Based on the joint root-causing above, I expect it to clear the MinIO-related legs and continue to show only the two already-tracked, diff-unrelated flakes (#12116's TestFilterRowKindIT, and the engine-v2-it Awaitility timeouts) plus possibly the separately-tracked S3FileConnectDryRunIT/#12302 gap — none of which are reachable from this PR's seatunnel-transforms-v2-only diff. The four unit-test legs, which are the only jobs that actually exercise this PR's added tests, have been green on every prior head.

Overall assessment: nothing has changed in the substance of this PR since my full review last round — it remains a precise, minimal, non-overlapping coverage follow-up to #12215 with zero production behavior change. The dev-sync in this round's sole new commit is exactly the CI housekeeping step both the author and I had already converged on in the comment thread, and the thoroughness of that joint CI investigation (correctly distinguishing a real, fixed infra regression from pre-existing unrelated flakes, log by log rather than by check-run summary) reflects well on the coverage claims in the PR description too. I'm approving this.

@SEZ9 SEZ9 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this. I reviewed the latest head 7c343d90c9be.

What this PR fixes

  • User pain: After #12215 fixed MOD with TINYINT/SMALLINT divisors, nothing in the test suite pinned the planner half (ZetaSQLType declaring the divisor's type as the result type, ZetaSQLType.java:516-518) together with the runtime half (NumericFunction.mod returning Byte/Short, NumericFunction.java:227-231), so either side could regress independently; the absence of a range check on the narrow branches also read like an oversight to anyone skimming the code.
  • Fix approach: Test-only PR plus a comment. Adds NumericFunctionTest.testModSupportsTinyIntAndSmallIntDivisors (zeta package) asserting typeMapping() yields BYTE_TYPE/SHORT_TYPE and transformBySQL returns (byte) 2/(short) 3; extends functions/NumericFunctionTest.testModForDifferentResultTypes with .getClass() assertions and Byte.MIN_VALUE/Short.MIN_VALUE divisors; documents at NumericFunction.java:224-226 that divideAndRemainder bounds |remainder| < |divisor| so no range check is needed.
  • One-line summary: The typeMapping() assertions are genuinely new coverage, but the "widest divisor" cases (300 % -128 = 44, 100000 % -32768 = 1696) never approach ±127/±32767 so they do not exercise the bound the comment describes; the comment's "always fits" overstates the guarantee for fractional dividends, where byteValue()/shortValue() still truncate; and the engine-level test largely duplicates SQLNumericFunctionsTest.testModWithTinyIntAndSmallIntDivisors (lines 88-106) rather than extending it.

Runtime chain I rechecked

Planner side (what the new typeMapping assertions pin):
  ZetaSQLEngine.typeMapping()                                  ZetaSQLEngine.java:215
    -> zetaSQLType.getExpressionType(expression)               ZetaSQLEngine.java:262
      -> ZetaSQLType.getFunctionType(Function)
        -> case ZetaSQLFunction.MOD: return getExpressionType(params.get(1))   ZetaSQLType.java:516-518  (result type = divisor type)

Runtime side (what the value/class assertions pin):
  ZetaSQLEngine.transformBySQL(inputRow, outRowType)           ZetaSQLEngine.java:285  (outRowType only forwarded to lateralView at :313-314; no coercion of projected values)
    -> project(inputFields)                                    ZetaSQLEngine.java:322
      -> zetaSQLFunction.computeForValue(expression, inputFields) ZetaSQLEngine.java:339
        -> ZetaSQLFunction.executeFunctionExpr case MOD
          -> NumericFunction.mod(args)                         NumericFunction.java:208
            -> toBigDecimal(left/right)                        NumericFunction.java:217-218 (Byte/Short/Integer/Long -> exact via longValue(); Float/Double -> BigDecimal.valueOf(double))
            -> leftBD.divideAndRemainder(rightBD)              NumericFunction.java:223
            -> [new comment]                                   NumericFunction.java:224-226
            -> rightValue instanceof Byte  -> res[1].byteValue()  NumericFunction.java:227-228
            -> rightValue instanceof Short -> res[1].shortValue() NumericFunction.java:230-231

Existing sibling coverage the new engine test overlaps:
  SQLNumericFunctionsTest.testModWithTinyIntAndSmallIntDivisors  SQLNumericFunctionsTest.java:88-106 (INT/BYTE/SHORT schema, MOD(a, tiny)/MOD(a, small); asserts (byte) 2 / (short) 10 values only, not the declared row type)

Findings

Issue 1: The "widest divisor" assertions never produce a remainder near the type boundary, so they cannot detect the overflow they claim to guard against

  • Location: seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunctionTest.java:161
  • Why it matters: - The new assertions use dividends 300 and 100000 against Byte.MIN_VALUE / Short.MIN_VALUE, which yield remainders 44 and 1696. Both sit far inside the byte (±127) and short (±32767) ranges, so res[1].byteValue() / res[1].shortValue() at NumericFunction.java:228/231 would return the same value even if the narrowing were lossy for out-of-range numbers. The test therefore only proves that the divisor-type branch is dispatched, which the (byte) 1 / (short) 1 assertions a few lines above already prove.
  • The boundary the comment talks about is the remainder magnitude, not the divisor magnitude. divideAndRemainder gives |remainder| ≤ |divisor| - 1, so the extreme outputs are MOD(127, Byte.MIN_VALUE) == 127, MOD(-127, Byte.MIN_VALUE) == -127, MOD(32767, Short.MIN_VALUE) == 32767 and MOD(-32767, Short.MIN_VALUE) == -32767. None of those, and no negative dividend at all, is exercised for the narrow types in either test file, so BigDecimal's sign-follows-dividend behaviour is also unasserted for Byte/Short results.
  • Impact: if someone later adds a guard such as abs(remainder) >= Byte.MAX_VALUE, or switches to byteValueExact() with an off-by-one, these tests stay green while MOD(127, tiny_col) starts failing jobs at runtime.
  • Fix: replace or complement the two assertions with the four boundary cases above (max positive and max negative remainder for each type), and reword the comment at lines 158-160 so it points at the remainder bound rather than the divisor width.
  • Evidence: seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunctionTest.java:163 (short) 1696, NumericFunction.mod(Arrays.asList(100000, Short.MIN_VALUE)));; seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunctionTest.java:160 // would fail first if that reasoning were wrong.; seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunctionTest.java:158 // The remainder is always smaller in magnitude than the divisor, so even the widest
  • Suggested fix: These two inputs don't actually reach the boundary the comment describes: 300 % -128 is 44 and 100000 % -32768 is 1696, both far inside the byte/short range, so a lossy byteValue()/shortValue() or a mis-written range guard would still pass. The extreme remainders are what matter (|remainder| ≤ |divisor| - 1), so I'd assert MOD(127, Byte.MIN_VALUE) == (byte) 127, MOD(-127, Byte.MIN_VALUE) == (byte) -127, MOD(32767, Short.MIN_VALUE) == (short) 32767 and MOD(-32767, Short.MIN_VALUE) == (short) -32767. That also gives us the first negative-dividend coverage for the narrow types (sign follows the dividend).
  • Severity: Medium

Issue 2: New engine-level MOD test duplicates SQLNumericFunctionsTest.testModWithTinyIntAndSmallIntDivisors from #12215; only the typeMapping() assertions are new

  • Location: seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/zeta/NumericFunctionTest.java:194
  • Why it matters: - testModSupportsTinyIntAndSmallIntDivisors (seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/zeta/NumericFunctionTest.java:194) builds the same INT/BYTE/SHORT schema, runs the same MOD(int, tiny), MOD(int, small) projection and asserts (byte)/(short) output values, exactly as SQLNumericFunctionsTest.testModWithTinyIntAndSmallIntDivisors (lines 88-106, landed with #12215) already does with different input values.
  • The genuinely new coverage is the two typeMapping() assertions at lines 211-212. In ZetaSQLEngine.transformBySQL (lines 285-315) the outRowType argument is only forwarded to lateralView and never coerces projected values, so the runtime-type check at lines 215-216 is real — but it is the same runtime check the #12215 test already performs.
  • Our convention is to extend the existing test that owns the scenario rather than spread near-identical cases across classes. I'd either fold the planner-side check into the #12215 test (the produced row type is reachable through the SQLTransform it already builds), or keep this test but trim it to the typeMapping() assertions and reference the sibling test in its Javadoc so future readers know where the value assertions live.
  • Evidence: seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/zeta/NumericFunctionTest.java:208 "select MOD(int_v, tiny_v) as tiny_mod, MOD(int_v, small_v) as small_mod from test");; seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/zeta/NumericFunctionTest.java:215 Assertions.assertEquals((byte) 2, outRow.getField(0));; seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/zeta/NumericFunctionTest.java:210 SeaTunnelRowType outRowType = sqlEngine.typeMapping(null);
  • Suggested fix: This mirrors SQLNumericFunctionsTest.testModWithTinyIntAndSmallIntDivisors (from #12215) almost line for line — same INT/BYTE/SHORT schema, same query shape, same (byte)/(short) value assertions. The only new coverage is the typeMapping() check at lines 211-212, which is the valuable part. Could we either add that planner-side assertion to the existing #12215 test (the produced row type is reachable through the SQLTransform it already builds) or trim this one down to the typeMapping() assertions and point to the sibling test in the Javadoc? That keeps the MOD scenario in one place, per our "extend the existing test" convention.
  • Severity: Low

Issue 3: New comment says the remainder "always fits the divisor's type", but byteValue()/shortValue() silently truncate a fractional remainder when the dividend is FLOAT/DOUBLE/DECIMAL

  • Location: seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:226
  • Why it matters: - The statement is correct for integer range: |remainder| < |divisor| guarantees no overflow of byte/short.
  • It is not lossless, though. toBigDecimal (NumericFunction.java:193-206) keeps the fractional part of a FLOAT/DOUBLE/DECIMAL dividend, so with a Byte/Short divisor res[1] can carry a fraction and res[1].byteValue() / res[1].shortValue() drop it: MOD(5.5, (byte) 2) returns 1, not 1.5. The same applies to the pre-existing Integer/Long branches, and it is consistent with ZetaSQLType declaring the divisor's type for the result — but "fits" reads as "no information is lost" to the next maintainer.
  • Since the explicit goal of the comment is to stop a future reader from adding an unnecessary guard, it should also make the deliberate fractional truncation explicit so nobody "fixes" it in the other direction or files it as a bug.
  • Fix: extend the comment with one sentence, e.g. "A fractional remainder (FLOAT/DOUBLE/DECIMAL dividend) is truncated to the divisor's integral type, matching the type ZetaSQLType declares." and pin it with Assertions.assertEquals((byte) 1, NumericFunction.mod(Arrays.asList(5.5d, (byte) 2))) in testModForDifferentResultTypes.
  • Evidence: seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:226 // |remainder| < |divisor|, so the remainder always fits the divisor's type.; seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:225 // No range check is needed for the narrow types: divideAndRemainder guarantees that
  • Suggested fix: "always fits" is true for range, but not for precision: when the dividend is FLOAT/DOUBLE/DECIMAL and the divisor is Byte/Short, res[1].byteValue() / shortValue() drop the fractional part (MOD(5.5, (byte) 2) -> 1). Since the point of this comment is to stop the next reader from adding a guard, please also spell out that fractional remainders are intentionally truncated to the divisor's integral type (consistent with what ZetaSQLType declares), and pin that with a MOD(5.5d, (byte) 2) == (byte) 1 assertion in testModForDifferentResultTypes.
  • Severity: Low

Review conclusion

Conclusion: final approval remains pending on the previous comments

2. Remaining follow-ups

  • Issue 1: The "widest divisor" assertions never produce a remainder near the type boundary, so they cannot detect the overflow they claim to guard against
  • Issue 2: New engine-level MOD test duplicates SQLNumericFunctionsTest.testModWithTinyIntAndSmallIntDivisors from #12215; only the typeMapping() assertions are new
  • Issue 3: New comment says the remainder "always fits the divisor's type", but byteValue()/shortValue() silently truncate a fractional remainder when the dividend is FLOAT/DOUBLE/DECIMAL

Thanks for the updates so far. Happy to discuss the remaining points.

Assert the real remainder boundaries. The previous inputs, 300 % -128 and
100000 % -32768, give 44 and 1696, both far inside byte and short range, so
they only proved the divisor-type branch was dispatched. What bounds the
result is the remainder: divideAndRemainder gives |remainder| <= |divisor| - 1,
so the extremes are MOD(+-127, Byte.MIN_VALUE) and MOD(+-32767,
Short.MIN_VALUE). Those are now asserted, which also gives the narrow types
their first negative-dividend coverage.

Record that a fractional remainder is truncated rather than rounded. The
comment said the remainder "always fits" the divisor's type, which is true of
range but not of precision: a FLOAT, DOUBLE or DECIMAL dividend keeps its
fraction and byteValue() drops it, so MOD(5.5, (byte) 2) is 1. Pinned with an
assertion so it is not "fixed" into rounding later.

Trim the engine-level test to the planner side. Its value assertions duplicated
SQLNumericFunctionsTest#testModWithTinyIntAndSmallIntDivisors from apache#12215; only
the typeMapping() check was new. The Javadoc now points at the sibling test.

No behaviour change. NumericFunction.java is byte-identical to dev once
comments are stripped.
@SEPURI-SAI-KRISHNA

Copy link
Copy Markdown
Collaborator Author

Thanks @SEZ9, all three are right and all three are addressed in the push above.

Issue 1. You were right that the inputs never reached the boundary. 300 % -128 is 44 and 100000 % -32768 is 1696, so those assertions only proved the divisor-type branch was dispatched, which the (byte) 1 cases above already did. Replaced with the four extremes you named, MOD(±127, Byte.MIN_VALUE) and MOD(±32767, Short.MIN_VALUE), which also gives the narrow types their first negative-dividend coverage.

I checked your failure scenario directly rather than taking it on reasoning. Adding the exact guard you described, abs(remainder) >= Byte.MAX_VALUE, to the byte branch: with the old assertions all 29 tests still pass, and with the new ones it fails. That is your point reproduced.

Issue 3. Agreed, "always fits" conflated range with precision. The comment now says the remainder is within the divisor's range but that a FLOAT, DOUBLE or DECIMAL dividend keeps its fraction and byteValue() truncates it, that this is deliberate, and that it should not be turned into rounding or a wider return type. Pinned with MOD(5.5d, (byte) 2) == (byte) 1; mutating the branch to round instead fails it.

Issue 2. Taken, but via your second option rather than the first. You offered either folding the planner-side assertion into the #12215 test or trimming this one to the typeMapping() assertions and pointing at the sibling in the Javadoc. I took the second, because #12364 is currently open and adds 50 lines to SQLNumericFunctionsTest.java, so editing that file now would collide with it for no benefit. The duplicated value assertions are gone and the Javadoc names the sibling test.

1158 tests pass in seatunnel-transforms-v2, verify is clean on JDK 11, and a forced spotless:check passes. NumericFunction.java is still byte-identical to dev once comments are stripped.

@DanielLeens DanielLeens left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for missing this in the last review: in my earlier approval I described the Byte.MIN_VALUE / Short.MIN_VALUE dividend inputs (300 and 100000) as the tightest test of the "no range check needed" reasoning, and @SEZ9 is right that they were not. 300 mod -128 = 44 and 100000 mod -32768 = 1696 sit far inside the byte and short ranges, so they never approached the remainder bound the comment talks about. I re-derived the arithmetic but did not ask which quantity the invariant actually bounds. Thanks @SEPURI-SAI-KRISHNA for taking the point on board so quickly, and thanks @SEZ9 for the careful review. This is a re-review of the current head af865a73ad0b; all three points from @SEZ9's review are resolved in the new commit, and my earlier APPROVED still stands at this head.

What Problem Does This PR Solve?

  • User pain point: #12215 made NumericFunction.mod return Byte / Short for TINYINT / SMALLINT divisors, matching what ZetaSQLType declares for MOD (ZetaSQLType.java:516-518, "Result has the same type as second argument"). Nothing pinned the planner-declared row type, the exact boundary outputs, or the reason the narrowing needs no range check.
  • Fix approach: no production behavior change. A comment at the call site (NumericFunction.java:224-230) plus test additions in two existing test classes: boundary and type assertions in functions/NumericFunctionTest#testModForDifferentResultTypes, and a planner-side typeMapping() test in zeta/NumericFunctionTest.
  • One-sentence summary: a coverage and documentation follow-up to #12215 that pins the divisor-type contract and the true extreme remainders for narrow divisors.
  • Before / after (test behavior): before, MOD(127, Byte.MIN_VALUE) and MOD(-127, Byte.MIN_VALUE) were unasserted, so a guard such as abs(remainder) >= Byte.MAX_VALUE would have passed the suite; after, both inputs are asserted and such a guard fails.

1. Code Change Review

1.1 Core Logic Analysis

Effective diff vs dev (merge base ea3df1667, no stacked or foreign commits): 3 files, 61 insertions, 0 deletions. The only production-file change is the comment block at NumericFunction.java:224-230. NumericFunction.mod itself is unchanged: toBigDecimal for both operands, Mod by zero check on rightBD.signum(), divideAndRemainder, then the instanceof chain keyed on the divisor type (:231-258).

Changes since the approved head 7c343d90c9be (one commit, af865a73ad0b):

  • functions/NumericFunctionTest.java:158-174: the 300 / 100000 cases are replaced by the four extreme remainders and one fractional case.
  • zeta/NumericFunctionTest.java:189-213: the test is renamed testModDeclaresTheDivisorTypeForTinyIntAndSmallInt and trimmed to the typeMapping() assertions only, with a Javadoc that points at SQLNumericFunctionsTest#testModWithTinyIntAndSmallIntDivisors.
  • NumericFunction.java:224-230: comment reworded from "always fits" to "in range, not lossless".

Verification of the asserted numeric semantics against the implementation at this head (hand-derived from BigDecimal.divideAndRemainder, truncate toward zero, remainder takes the sign of the dividend; I did not run the code):

  • MOD(127, Byte.MIN_VALUE): quotient 0, remainder 127, byteValue() gives (byte) 127. Correct, and it is the maximum positive remainder for a byte divisor of magnitude 128.
  • MOD(-127, Byte.MIN_VALUE): quotient 0, remainder -127, gives (byte) -127. Correct; first negative-dividend coverage for the narrow types.
  • MOD(32767, Short.MIN_VALUE) gives (short) 32767, MOD(-32767, Short.MIN_VALUE) gives (short) -32767. Correct for the same reason.
  • MOD(5.5d, (byte) 2): toBigDecimal(5.5d) is BigDecimal.valueOf(5.5), the remainder is 1.5, BigDecimal.byteValue() truncates the fraction, so the result is (byte) 1. Correct. It also matches the comment: truncation is deliberate, not rounding.
  • Assertions.assertEquals((byte) 127, <Number>) resolves to assertEquals(Object, Object) after boxing, and Byte.equals(Integer) is false, so the value assertions also pin the runtime class. The explicit getClass() checks at :151 and :155 cover the ordinary 5 mod 2 case.
  • Type promotion: the result type follows the divisor only (ZetaSQLType.java:516-518 and the instanceof chain agree), never the dividend. MOD(5, (byte) 2) returns Byte, and MOD(5.5d, (byte) 2) also returns Byte, consistent with the planner.
  • Zero divisor is not part of this diff. It is already covered by functions/NumericFunctionTest#testModByZeroThrows (:86) and SQLNumericFunctionsTest#testModByZero (:109), so nothing is missing there.

Key Findings:

  • The invariant that matters is |remainder| <= |divisor| - 1, and the extreme outputs are reached with dividends +/-127 and +/-32767 against the MIN_VALUE divisors; the new assertions hit exactly those.
  • The comment now says the narrowing is in range but not lossless for FLOAT / DOUBLE / DECIMAL dividends, and that this must not be "fixed" into rounding or a wider type. That is accurate against NumericFunction.java:231-236.
  • The planner-side test asserts BYTE_TYPE and SHORT_TYPE from typeMapping(null) and nothing else, which is the part of the contract the existing tests could not see.
  • Normal path: MOD(x, tinyint_col) is an always-reachable user path, so the invariant guarded here is on the main path and not only on recovery or error handling.

1.2 Compatibility Impact

Fully compatible. The only production change is a source comment. No config option, default, serialization, checkpoint state, or public API is touched. No existing test was removed or weakened; the diff contains 0 deletions.

1.3 Performance / Side-Effect Analysis

None. A comment has no runtime cost, and the tests are in-process and cheap. SQLEngineFactory.getSQLEngine(...) creates a fresh engine per call, so there is no shared state across test methods.

1.4 Error Handling and Logging

Status of the points raised by other reviewers on the previous head:

  • @SEZ9 Issue 1 (Medium), boundary assertions never reached the remainder bound: FIXED. functions/NumericFunctionTest.java:158-170 now asserts (byte) 127, (byte) -127, (short) 32767, (short) -32767, and the comment at :158-162 points at the remainder bound rather than the divisor width. +1 @SEZ9: this was a real gap and my earlier review missed it (carryover, not introduced by the new commit). The author also reports that adding an abs(remainder) >= Byte.MAX_VALUE guard passes the old assertions and fails the new ones; I did not run that, but it follows directly from the arithmetic above (127 mod -128 = 127 trips that guard).
  • @SEZ9 Issue 2 (Low), duplicate engine-level value assertions: FIXED. zeta/NumericFunctionTest.java:196-213 keeps only typeMapping() assertions and the Javadoc at :189-194 names the sibling test. The author chose the "trim and reference" option so that the file that #12364 is editing is not touched; that is a reasonable reading of the "extend the existing test" convention.
  • @SEZ9 Issue 3 (Low), comment overstated "always fits": FIXED. NumericFunction.java:227-230 spells out the deliberate fractional truncation, pinned by functions/NumericFunctionTest.java:174.

Formal issue for the current head:

Issue 1: PR description no longer matches the diff

  • Location: PR description, "How was this patch tested?" and "The planner side is asserted alongside the runtime" paragraphs.
  • Problem: the description still names testModSupportsTinyIntAndSmallIntDivisors, says it asserts that transformBySQL returns exactly BYTE_TYPE / SHORT_TYPE, and quotes Tests run: 29 / 1149 and a failure at NumericFunctionTest.testModSupportsTinyIntAndSmallIntDivisors:214. After the latest commit the method is testModDeclaresTheDivisorTypeForTinyIntAndSmallInt, it no longer calls transformBySQL, and the value / runtime-class half is carried by functions/NumericFunctionTest#testModForDifferentResultTypes and the #12215 sibling test. The claim that "both new tests fail against the dispatch chain with #12215's two branches removed" is also no longer true for the planner-only test, which does not depend on the runtime branches at all.
  • Potential risk: a future reader (or the merge commit message) will look for a test that does not exist under that name and will assume the planner and runtime halves are asserted in one place.
  • Best improvement: refresh the description to the current test names, the current counts, and say explicitly that the planner half (typeMapping()) and runtime half (value plus getClass()) are covered by different tests on purpose.
  • Severity: Low
  • Raised by another reviewer: No

2. Code Quality Assessment

2.1 Coding Standards

Good. New comments explain why (remainder bound, deliberate truncation) rather than restating code. The new test method has a Javadoc explaining the contract it pins. No new class or field is introduced, no license-header issue, and formatting is confirmed by the green Code style job on the fork run.

2.2 Test Coverage and Test Stability

Coverage: the ordinary case (5 mod 2), the four extreme remainders, the negative-dividend sign rule, the fractional-truncation case, and the planner-declared row type are all pinned for both narrow divisor types. Zero divisor and the wide-type branches were already covered on dev.

Stability rating: Stable. Evidence: all assertions are pure arithmetic or a single in-process SQLEngine.init / typeMapping call (zeta/NumericFunctionTest.java:197-212); no Thread.sleep, no polling or unbounded waits, no ports, no files, no static mutable state (a fresh engine per test via SQLEngineFactory), no ordering dependency between methods (functions/NumericFunctionTest.java:143-174).

2.3 Documentation Updates

None required. docs/en/transforms/sql-functions.md already documents MOD(dividendNumeric, divisorNumeric) -> type(divisorNumeric), which is what the tests pin; the behavior is unchanged, so docs/zh needs no change either.

3. Architectural Soundness

3.1 Elegance of the Solution

Precise fix. Test and comment only, in the existing test classes, with no new abstraction.

3.2 Maintainability

High. The comment now states both the range guarantee and the precision caveat, and the boundary tests make a wrong "defensive" guard fail immediately. One trade-off worth naming: the planner and runtime halves now live in two classes, so no single test fails for both; that is acceptable because each half is independently pinned.

3.3 Extensibility

Not applicable; leaf scalar function.

3.4 Historical-Version Compatibility

Fully compatible. Nothing in the runtime, config, state, or serialization changes, and NumericFunction.mod behavior is identical to dev.

4. Issue Summary

Number Issue Location Severity
1 PR description no longer matches the diff (test name, counts, "both tests fail" claim) PR description Low

No blocking issues found. Remaining risk is CI only, described below.

5. Merge Recommendation

Conclusion: Ready to merge

  1. Blockers - none.
  2. Recommended fixes - non-blocking: refresh the PR description (Issue 1).

Overall assessment: the update does what @SEZ9 asked, and the arithmetic checks out against the implementation. My earlier APPROVED at 7c343d90c9be still stands at af865a73ad0b, with the correction above that the earlier boundary inputs were weaker than I said. @SEZ9's review is still in the "pending" state, so a quick re-look from @SEZ9 would close that out. No better alternative is needed.

CI status at this head (fork run 35583085561 in SEPURI-SAI-KRISHNA/seatunnel; the apache-side Build check is still in progress and is only a pointer):

  • Transforms : V2 module: SUCCESS in the JDK 11 ubuntu unit-test job, with zeta.NumericFunctionTest (8 tests), zeta.functions.NumericFunctionTest (21 tests) and SQLNumericFunctionsTest (16 tests) all at 0 failures. unit-test (8, windows-latest) is green, and Code style, License header, Dead links and Dependency licenses are green.
  • unit-test (8, ubuntu-latest) failed before any test ran: wget got 429 Too Many Requests fetching the Maven wrapper jar from Maven Central, then Could not find or load main class org.apache.maven.wrapper.MavenWrapperMain. Infrastructure, not this PR. A rerun of that job should pass.
  • unit-test (11, ubuntu-latest) failed in seatunnel-engine-server: TaskExecutionServiceTest.testStaleTaskDoneCleansOnlyOwnedGenerationResources:639 (Wanted but not invoked: scheduledFuture.cancel(false)). That test came in with #12238, this PR touches nothing under seatunnel-engine, and #12394 is an open PR that describes this exact test failing from execution-ID reuse across fixtures. This reads as a known engine test flake, not caused by this diff (my inference from the test source and #12394's description; I did not run it). Rerun the failed job.
  • unit-test (11, windows-latest) failed in connector-http-paypal: PayPalClientTest.closeWakesRetryWait:416 expected: <true> but was: <false>, a timing test in a connector this PR does not touch. Unrelated; rerun the failed job.
  • The remaining fork jobs (connector and engine ITs) were still queued or running when I looked, so I am not treating them as failures.

The contributor should rerun only the failed unit-test jobs (no code change and no dev sync needed for these; a sync would not change any of the three).

@SEPURI-SAI-KRISHNA

Copy link
Copy Markdown
Collaborator Author

Thanks @DanielLeens. Description refreshed for Issue 1: the renamed test, the removed transformBySQL half, the corrected count, and an explicit note that the planner and runtime halves are asserted in different tests on purpose.

@SEZ9 SEZ9 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the follow-up. I checked the latest changes at af865a73ad0b against my previous review comments.

The scope of this pass is limited to the findings from the previous review; it does not introduce a new set of review items.

What this PR fixes

The commits since the previous review touch only the three files already under review: a comment expansion in NumericFunction.java (no executable change), a rewrite of the boundary assertions plus one truncation assertion in functions/NumericFunctionTest#testModForDifferentResultTypes, and a trimmed, renamed planner-side test in zeta/NumericFunctionTest that asserts only typeMapping() returns BYTE_TYPE/SHORT_TYPE. Each change maps directly onto one of the three prior findings, and no new concerns were introduced.

Resolved previous findings

  • PR12182-F1 The "widest divisor" assertions never produce a remainder near the type boundary, so they cannot detect the overflow they claim to guard against
  • PR12182-F2 New engine-level MOD test duplicates SQLNumericFunctionsTest.testModWithTinyIntAndSmallIntDivisors from #12215; only the typeMapping() assertions are new
  • PR12182-F3 New comment says the remainder "always fits the divisor's type", but byteValue()/shortValue() silently truncate a fractional remainder when the dividend is FLOAT/DOUBLE/DECIMAL

Review conclusion

Conclusion: LGTM, can merge

Nice work — the previous concerns are addressed. Thanks again for the contribution.

@SEPURI-SAI-KRISHNA

Copy link
Copy Markdown
Collaborator Author

@davidzollo this one is ready whenever you have a moment, if you are happy to take it.

It has two approvals, @DanielLeens on 09-14 and again after the latest commit, and @SEZ9 on 09-22 after his three findings were addressed. CI is green on the current head af865a73a.

The four failures on the previous attempt were all environmental and cleared on a rerun with no code change: a 429 from Maven Central that stopped the wrapper downloading at all, TaskExecutionServiceTest (tracked in #12394), PayPalClientTest (tracked in #12381), and an SSL handshake failure during the paimon job's setup. None of them reached this diff.

The change itself is three files in seatunnel-transforms-v2 and no behaviour change: NumericFunction.java is byte-identical to dev once comments are stripped, and the other two are test additions.

It is 8 commits behind dev and still shows as mergeable. Happy to sync and rerun first if you would rather see a green run on a fresher base, just say so.

@DanielLeens

Copy link
Copy Markdown
Contributor

Thanks @SEPURI-SAI-KRISHNA. Confirmed the description now matches the diff - that closes out Issue 1 from my last review, and I have nothing further on the code or tests.

Also thanks @SEZ9 for the quick re-check and approval - glad the three findings are fully resolved.

I independently re-checked the current head (af865a73ad0b, unchanged) directly against the Actions API rather than taking the rollup at face value: Build is now SUCCESS and the PR shows mergeable: MERGEABLE. That matches your report that the earlier failures (the Maven Central 429, the TaskExecutionServiceTest flake, and the PayPalClientTest timing flake) were environmental and cleared without a code change, as expected.

No need to sync with dev first on my account - the diff is unchanged and green. Since my review access here is comment-level, this is over to @davidzollo to make the call on formal approval and merge.

@davidzollo davidzollo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1
LGTM, appreciate your solid contribution, keep up the excellent work

@davidzollo
davidzollo added this pull request to the merge queue Sep 22, 2026
Merged via the queue into apache:dev with commit e78be4c Sep 22, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] [Transform-V2] Zeta SQL MOD rejects TINYINT and SMALLINT divisors, contradicting its declared result type

4 participants