Skip to content

[Test][Transform-V2] Add SQL-level coverage for CEIL/FLOOR/TRUNC on TINYINT columns - #12007

Merged
davidzollo merged 4 commits into
apache:devfrom
zhangshenghang:fix-zeta-sql-small-integer-functions
Oct 21, 2026
Merged

davidzollo merged 4 commits into
apache:devfrom
zhangshenghang:fix-zeta-sql-small-integer-functions

Conversation

@zhangshenghang

@zhangshenghang zhangshenghang commented Aug 30, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Supplements the already-merged #11937 (which delivered TINYINT/SMALLINT support for Zeta SQL numeric functions) with test-only additions:

  • Adds an SQL-level regression test (testSmallIntegerNumericFunctions) proving that ABS, SIGN, ROUND, CEIL, FLOOR, and TRUNC resolve and execute correctly for TINYINT/SMALLINT columns through the full SQL parsing-to-execution pipeline.
  • Adds unit assertions for small-integer boundary overflow and exact BigDecimal sign handling in NumericFunctionTest.

No production code changes: after syncing with dev, NumericFunction.java and ZetaSQLType.java are byte-for-byte identical to the implementation already merged via #11937.

Tests

  • Added an SQLTransform regression test covering ABS, SIGN, ROUND, CEIL, FLOOR, and TRUNC with TINYINT/SMALLINT columns.
  • Added unit coverage for small integer values, boundary overflow, and exact BigDecimal sign handling.

Validated with:

./mvnw spotless:apply
./mvnw -pl seatunnel-transforms-v2 -Dtest=NumericFunctionTest,SQLNumericFunctionsTest test
./mvnw -q -DskipTests verify

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

NumericFunction (backing the Zeta SQL ABS, ROUND, CEIL, CEILING, FLOOR, TRUNC, TRUNCATE, and SIGN functions) dispatches on the runtime Java type of its argument with instanceof chains and a switch on the class simple name. Byte/Short (i.e. TINYINT/SMALLINT) were missing from most of these branches:

  • ABS/SIGN threw Unsupported arg type java.lang.Byte/Short for TINYINT/SMALLINT columns, even though ABS's own doc comment names TINYINT/SMALLINT as supported.
  • The shared round() helper had no BYTE case, so ROUND/CEIL/FLOOR/TRUNC on a TINYINT column silently returned the value unrounded (no exception, no log).
  • SIGN on BigDecimal went through doubleValue(), so a magnitude below Double.MIN_VALUE underflowed to 0.0 and lost its sign.

This PR closes #11935 by adding Byte/Short branches to abs()/sign(), adding a BYTE case (with an overflow-checked narrowing) to the shared round()/convertTo() helpers, adding a default branch to round()'s switch so an unhandled type now throws instead of silently passing through, and switching SIGN's BigDecimal branch to BigDecimal.signum().

Important duplicate-scope note before the rest of this review: #11935 is already being fixed by the open PR #11937 ("Handle TINYINT and SMALLINT in Zeta SQL numeric functions", opened 2026-08-22, i.e. 8 days before this PR), which touches the exact same methods in the exact same file and is already approved by two reviewers (@goutamadwant and myself, @DanielLeens), pending only its stacked dependency #11927 landing first. See Issue 1 below — this materially affects the merge recommendation.

1. Code Change Review

1.1 Core Logic Analysis

  • abs(): the new Byte/Short branches correctly guard Byte.MIN_VALUE/Short.MIN_VALUE (whose absolute value doesn't fit the same type) before calling Math.abs, mirroring the existing pattern. Correct.
  • sign(): folding Byte/Short into the existing Integer branch via Integer.signum(v1.intValue()) is correct — a Byte/Short value always fits in an int without precision loss, so signum is unaffected by the widening.
  • sign() on BigDecimal: switching from v1.doubleValue() (sign-testing after double conversion) to ((BigDecimal) v1).signum() is a real correctness fix, not just a TINYINT/SMALLINT addition — the previous code underflowed any magnitude below Double.MIN_VALUE to 0.0. Covered by the new 1E-400 test.
  • round()'s new BYTE case follows the exact same negative-scale-only rounding path already used for INTEGER/SHORT/LONG, and routes the narrowed result through convertTo("BYTE", ...), which now range-checks against Byte.MIN_VALUE/Byte.MAX_VALUE before narrowing. Verified: round(Byte.MAX_VALUE, -1) (127 → 130) now throws instead of wrapping — good, this closes a real overflow-wrap hole for the newly-added type.
  • New default: throw branch on round()'s switch: previously, an argument type matching none of the case labels fell straight through the switch with no side effect, and the method returned the input unrounded with no exception, no log. This is a genuine bug fix (confirmed via git diff against origin/dev: no default existed before). The new default is exercised by the added BigInteger test.

1.2 Compatibility Impact

Partially incompatible — and not fully documented (see Issue 3). Two independent behavior changes ship in this diff:

  1. ROUND/CEIL/FLOOR/TRUNC on a TINYINT column previously returned the value unrounded with no error; it is now correctly rounded, and now throws if the rounded value overflows TINYINT. A job that happened to rely on the old (buggy) unrounded pass-through will see different output after upgrading.
  2. ABS/SIGN on TINYINT/SMALLINT previously always threw; they now succeed and return a value. Any existing job with a workaround (e.g. casting to INT first) is unaffected but now redundant.
  3. Any numeric type not covered by round()'s switch (previously silently passed through) now throws a TransformException.

Per this repo's own CLAUDE.md doc rule ("Any incompatible change MUST ... be documented in docs/en/introduction/concepts/incompatible-changes.md"), and per the precedent already set by #11937 for this exact same change (see its diff to that file), this PR should add an entry there (and in the docs/zh counterpart) but does not. See Issue 3.

1.3 Performance / Side-Effect Analysis

No concerns. The added branches are a handful of instanceof checks and a new switch case on the hot path of scalar SQL function evaluation — negligible CPU cost, no new allocations beyond what the existing code already does, no locks/retries/IO involved.

1.4 Error Handling and Logging

Consistent with the existing style in this class: TransformException with CommonErrorCodeDeprecated.UNSUPPORTED_OPERATION and a message naming the function, the value, and the target type. No secrets logged, appropriate for a transform-evaluation failure (surfaces to the user via the SQL engine's expression-evaluation wrapper). No exceptions are swallowed.

One incompleteness rather than an error-handling defect: the new overflow guard in convertTo() is added only for the new "BYTE" case. The pre-existing "SHORT" case (column.shortValue()) still narrows without a range check, so the identical overflow-wrap bug that this PR fixes for TINYINT remains live for SMALLINT immediately next to it. See Issue 2.

2. Code Quality Assessment

2.1 Coding Standards

Clean, minimal, consistent with the surrounding code's existing conventions (same instanceof ordering style, same exception message format, same switch-case style). No wildcard imports, no stray changes outside the intended scope.

2.2 Test Coverage and Test Stability

Good coverage for what's in scope: NumericFunctionTest adds unit cases for Byte/Short abs()/sign(), the Byte.MIN_VALUE/Short.MIN_VALUE abs() overflow exceptions, Byte rounding for ROUND/CEIL/FLOOR/TRUNC, the Byte.MAX_VALUE round-overflow exception, the BigInteger unsupported-type exception (exercising the new default branch), and the BigDecimal("1E-400") sign-underflow fix. SQLNumericFunctionsTest adds an end-to-end SQLTransform case exercising ABS/SIGN/ROUND/CEIL/FLOOR/TRUNC against real TINYINT/SMALLINT columns, which is the right level to also prove the type-dispatch path (ZetaSQLType.getFunctionType) resolves to the same branches.

Stability rating: Stable. All new tests are deterministic pure-function/unit-level assertions — no Thread.sleep, no timing dependencies, no shared mutable state, no floating-point-without-delta comparisons (the one BigDecimal assertion is assertEquals on decimal values, which is exact).

Gap: no test for SMALLINT round-overflow (e.g. CEIL(Short.MAX_VALUE, -1)), which — per Issue 2 — would currently fail to throw and instead return a silently wrapped negative value.

2.3 Documentation Updates

docs/en/transforms/sql-functions.md doesn't strictly need a content change here — as PR #11937 established while fixing the same issue, that page's ROUND overflow note is already written generically for "an integral type" and its ABS section already names TINYINT/SMALLINT. However, docs/en/introduction/concepts/incompatible-changes.md (and docs/zh) is not updated, and per Section 1.2 above, it should be. See Issue 3.

3. Architectural Soundness

3.1 Elegance of the Solution

The approach (mirror the existing Integer/Long handling for Byte/Short) is the right shape and reuses the existing round()/convertTo() structure rather than introducing a parallel code path. Appropriately minimal for the stated scope.

3.2 Maintainability

Fine on its own terms, but see Issue 1: landing this independently of #11937/#11927 would leave the file in an inconsistent state where TINYINT is overflow-guarded through round() but the otherwise-identical SMALLINT path is not — future maintainers would reasonably expect symmetric handling given how closely the two case blocks sit.

3.3 Extensibility

No concerns beyond what's noted above; the default branch added to round()'s switch is good practice for extensibility (any future numeric type added to the type system will now fail loudly here instead of being silently mishandled).

3.4 Historical-Version Compatibility

See Section 1.2 — this is a behavior change for jobs currently relying on the (buggy) old TINYINT pass-through or the old ABS/SIGN rejection, and it is not yet documented in incompatible-changes.md as the project's own convention requires.

4. Issue Summary

Issue 1 — Duplicate/overlapping scope with already-approved PR #11937

  • Location: whole PR vs. apache/seatunnel#11937 (stacked on #11927)
  • Problem: Both PRs close the same issue (#11935) by editing the same methods in the same file (NumericFunction.java: abs(), round(), convertTo(), sign()). #11937 was opened 8 days earlier and already carries two approvals (@goutamadwant, @DanielLeens), and is strictly more complete: (a) it stacks on #11927's shared checkIntegralRange helper, which range-checks BYTE, SHORT, INTEGER, and LONG uniformly — this PR only range-checks the new BYTE case (see Issue 2); (b) it fixes the pre-existing t.toUpperCase()/valueType.toUpperCase() default-locale dispatch bug (breaks under a Turkish JVM locale) via a follow-up commit pinning to Locale.ROOT — this PR inherits the same locale-dependent switch unchanged; (c) it documents the breaking-change behavior in docs/en(zh)/introduction/concepts/incompatible-changes.md — this PR does not (Issue 3).
  • Potential risk: merging both would produce a direct file-level conflict on the same switch/instanceof chains; reviewer and maintainer time gets split across two competing fixes for one bug.
  • Best improvement: the author should check with the maintainers / @SEPURI-SAI-KRISHNA before proceeding — either close this PR in favor of #11937 (once its dependency #11927 merges), or, if there's a concrete reason to prefer this PR's approach, explicitly call that out and close #11937 instead. Either way, only one should move forward.
  • Severity: High
  • Raised by another reviewer: No (new finding from this review; I am also a reviewer on #11937, disclosed above).

Issue 2 — SMALLINT overflow-wrap left unguarded

  • Location: seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java, convertTo(), case "SHORT": (pre-existing line, unchanged by this diff, a few lines below the new case "BYTE": block)
  • Problem: The new "BYTE" case in convertTo() range-checks against Byte.MIN_VALUE/Byte.MAX_VALUE before narrowing, throwing on overflow. The adjacent, pre-existing "SHORT" case still does an unchecked column.shortValue(). Since this PR's own stated goal is TINYINT+SMALLINT support, and the negative-scale rounding path (round()) is shared by both types, CEIL(Short.MAX_VALUE /* SMALLINT */, -1) (32767 → 32770) will still silently wrap to -32766 instead of throwing — the exact class of bug this PR fixes for TINYINT, left in place for SMALLINT one case-label away.
  • Potential risk: a job rounding a SMALLINT column near its max/min with a negative scale silently produces a wrong (and sign-flipped) result instead of failing loudly — worse than the TINYINT case this PR is fixing, since it now looks "fixed" for small integers in general.
  • Best improvement: add the same range check to the "SHORT" case (this is exactly what #11927's shared checkIntegralRange helper already does across BYTE/SHORT/INTEGER/LONG uniformly).
  • Severity: Medium
  • Raised by another reviewer: No.

Issue 3 — Missing incompatible-changes.md entry for the breaking behavior change

  • Location: docs/en/introduction/concepts/incompatible-changes.md, docs/zh/introduction/concepts/incompatible-changes.md (not touched by this PR)
  • Problem: Per Section 1.2, this PR changes observable behavior for existing jobs (silent TINYINT pass-through → rounded-or-throws; ABS/SIGN rejection → success). The project's own CLAUDE.md requires such changes to be documented here, and the parallel PR #11937 already set the precedent by adding a detailed entry (with before/after tables and a migration guide) for this identical change.
  • Potential risk: users upgrading won't know why a previously-silent TINYINT ROUND now changes its output, or why a previously-failing ABS/SIGN on TINYINT/SMALLINT now succeeds.
  • Best improvement: add an entry mirroring #11937's (adjusted for this PR's actual diff, e.g. it does not need the Locale.ROOT mention since that fix isn't included here).
  • Severity: Medium
  • Raised by another reviewer: No.

5. Merge Recommendation

Not recommended for merge, primarily due to Issue 1: this duplicates the scope of the already twice-approved PR #11937, and merging this PR as-is would either conflict with #11937 at the file level or ship a materially less complete fix (missing the SMALLINT overflow guard from Issue 2, missing the locale-independence fix, missing the required incompatible-changes.md documentation from Issue 3) for the exact same underlying issue #11935. I'd suggest the author coordinate with the maintainers and with @SEPURI-SAI-KRISHNA on #11937 before either PR proceeds further.

Separately, CI on this PR's head (034a3f47) shows one failing job — unit-test (8, windows-latest) — but it fails in FileCollectReaderBehaviorTest.rediscoversFileAfterInactiveCursorClosed inside seatunnel-edge-agent-connector, a module this PR does not touch, with an AssertionFailedError: expected: <1> but was: <0> from what looks like a timing-sensitive file-watch test; this is unrelated to this PR's diff. All other jobs (including unit-test on the other three OS/JDK combinations, and the full connector/JDBC/engine IT matrix) passed. The PR is also behind_by=10 commits from dev (diverged, ahead_by=1); a rebase/sync is worth doing but is not itself a blocker given the above.

@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 034a3f474cbd.

What this PR fixes

  • User pain: Zeta SQL numeric functions mishandle TINYINT/SMALLINT columns (#11935) — ABS silently widens Byte/Short, ROUND/CEIL/FLOOR/TRUNC return TINYINT inputs unchanged instead of rounding, and SIGN rejects small integer types while losing the sign of tiny DECIMAL values via lossy double conversion.
  • Fix approach: Adds Byte/Short branches to abs() with MIN_VALUE guards, adds a "BYTE" case to the shared round helper's type dispatch plus a BYTE overflow check in convertTo(), replaces the previously-silent pass-through with a default-throw for unsupported Number types, widens sign() to accept Byte/Short, and switches DECIMAL sign to BigDecimal.signum().
  • One-line summary: The TINYINT path and SIGN/ABS fixes are correct and well-tested, but the fix is asymmetric — SMALLINT/INTEGER rounding overflow still wraps silently in convertTo(), the new default-throw in the shared helper is a behavior break for previously pass-through Number types, the overflow error message hardcodes ROUND for all callers of the shared helper, and ZetaSQLType is not updated so the declared output type may not match the new Byte runtime values.

Findings

Issue 1: ZetaSQLType is not updated — declared output types for ROUND/CEIL/FLOOR/TRUNC/SIGN on TINYINT/SMALLINT may not match the actual runtime values

  • Location: seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:490
  • Why it matters: - Root cause: this PR changes the runtime return types of the functions (round(...) now returns Byte for TINYINT input via the new case "BYTE": at NumericFunction.java:259, and sign(...) now accepts Byte/Short but always returns Integer at line 490), yet ZetaSQLType.java — which declares the output SeaTunnelDataType of each function — is untouched. The related fix #11712 for BIGINT/DECIMAL had to change ZetaSQLType.java alongside NumericFunction.java for exactly this reason.
  • Impact: if the declared output type for these functions over TINYINT/SMALLINT arguments does not match the Byte/Short/Integer values now produced at runtime, downstream schema-driven consumers (sink converters, subsequent transforms) can fail or corrupt data.
  • Suggested action: align ZetaSQLType#getFunctionType for ABS/SIGN/ROUND/CEIL/FLOOR/TRUNC with BYTE/SHORT arguments, and add a row-type assertion to the tests so declared and runtime types stay in sync.
  • Evidence: seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:489 if (v1 instanceof Byte || v1 instanceof Short || v1 instanceof Integer) {; seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:490 return Integer.signum(v1.intValue());; seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:329 return column.byteValue();
  • Suggested fix: sign() now accepts Byte/Short inputs but still returns Integer, and round() now returns Byte for TINYINT input — yet ZetaSQLType.java (which declares the SQL output types) is not touched in this PR. #11712 had to update ZetaSQLType together with NumericFunction for the same class of fix. Please align ZetaSQLType#getFunctionType for ABS/SIGN/ROUND/CEIL/FLOOR/TRUNC with BYTE/SHORT args so the declared output type matches the actual runtime value, and add a row-type assertion in SQLNumericFunctionsTest to lock this in.
  • Severity: Medium

Issue 2: round() helper now throws for previously pass-through Number types — a silent behavior break that also affects CEIL/FLOOR/TRUNC/TRUNCATE

  • Location: seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:316
  • Why it matters: - Root cause: the new default: branch in the shared round(Number, Number, RoundingMode) helper (NumericFunction.java:311-316) turns what used to be a silent pass-through into a hard TransformException. This helper backs ROUND, CEIL, FLOOR, TRUNC and TRUNCATE, so all five functions change behavior at once.
  • Impact: any existing Zeta SQL transform pipeline that fed an unusual Number implementation (e.g. BigInteger coming from a connector's custom type mapping) through these functions previously received the input back unchanged; after upgrade the same pipeline fails at runtime. Additionally, the exception message hardcodes ZetaSQLFunction.ROUND, so a failure in CEIL(x) is reported as a ROUND error, misleading users during triage.
  • Suggested action: keep the fail-fast behavior but pass the actual function name into the helper for the error message, and call out the behavior change in the release notes.
  • Evidence: seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:315 "Unsupported arg type %s of function %s",; seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:316 v1.getClass().getName(), ZetaSQLFunction.ROUND));; seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:327 String.format("Rounded value %s is out of range for TINYINT", column));
  • Suggested fix: Two points here:
  1. This default: branch is a behavior change — types like BigInteger used to pass through ROUND/CEIL/FLOOR/TRUNC unchanged and will now fail the job. I agree fail-fast is correct, but please mention it in the release notes so users upgrading are not surprised.
  2. This helper is shared by CEIL/FLOOR/TRUNC/TRUNCATE, yet the message hard-codes ZetaSQLFunction.ROUND. A user calling CEIL(x) will get an error blaming ROUND. Please pass the actual function name into the helper and use it in the message.
  • Severity: Medium

Issue 3: Runtime return types changed to Byte/Short without touching ZetaSQLType — possible mismatch between declared output schema and produced values

  • Location: seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:39
  • Why it matters: - Root cause: abs now returns (byte)/(short) (NumericFunction.java:39, 45) and the ROUND/CEIL/FLOOR/TRUNC family now returns column.byteValue() for TINYINT input (NumericFunction.java:329), but this PR does not modify ZetaSQLType, which is where SQLTransform derives the output column type for these functions (PR #11712 had to change ZetaSQLType for the analogous BIGINT/DECIMAL fix).
  • Impact: if ZetaSQLType.getFunctionType still maps ABS/ROUND over TINYINT/SMALLINT args to a wider type such as INT, the output schema will declare INT while rows actually carry Byte/Short values, which can break sink converters at runtime.
  • Suggested action: verify and align the ZetaSQLType mapping for these functions, and extend testSmallIntegerNumericFunctions to assert the transform's produced row type in addition to the values.
  • Evidence: seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:45 return (short) Math.abs(arg.shortValue());; seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:329 return column.byteValue();
  • Suggested fix: abs/round now produce Byte/Short at runtime, but the PR doesn't touch ZetaSQLType, which drives the declared output column type for these functions (compare #11712, which had to update ZetaSQLType alongside NumericFunction). Please confirm ZetaSQLType.getFunctionType maps ABS/ROUND/CEIL/FLOOR/TRUNC over TINYINT/SMALLINT to the matching type; otherwise the output schema will say INT while rows carry Byte, breaking sink converters at runtime. It would also help if testSmallIntegerNumericFunctions asserted the transform's produced row type, not only the values.
  • Severity: Medium

Issue 4: No documentation update for the new TINYINT/SMALLINT support and new failure modes in docs/transform-v2/sql-functions.md

  • Location: seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:37
  • Why it matters: - Root cause: the PR changes user-visible SQL function behavior — ABS now throws on Byte.MIN_VALUE/Short.MIN_VALUE (NumericFunction.java:35-43 plus the new cannotRepresentAbsoluteValue helper at 341-347), ROUND/CEIL/FLOOR/TRUNC now actually round TINYINT and fail on overflow, and unsupported Number types now error — but no file under docs/ is changed.
  • Impact: users reading the SQL functions reference (docs/transform-v2/sql-functions.md and its zh counterpart) have no way to know these functions now support TINYINT/SMALLINT or that valid inputs like ABS(-128) on TINYINT will now fail the job.
  • Suggested action: update the ABS/SIGN/ROUND/CEIL/FLOOR/TRUNC entries in both the English and Chinese SQL functions docs to document the new small-integer support and the explicit error conditions.
  • Evidence: seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:37 throw cannotRepresentAbsoluteValue(arg, "TINYINT");; seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:344 "Function %s cannot represent the absolute value of %s for %s",
  • Suggested fix: This introduces a new user-visible failure mode: ABS on a TINYINT/SMALLINT column now fails the job for the minimum value instead of returning a result. Please update the ABS/SIGN/ROUND/CEIL/FLOOR/TRUNC entries in docs/transform-v2/sql-functions.md (English and Chinese) to document the new TINYINT/SMALLINT support and these explicit error conditions — right now the PR ships no docs change at all.
  • Severity: Medium

Issue 5: New default-throw in the shared rounding helper turns previously-silent pass-through into a runtime failure for ROUND/CEIL/FLOOR/TRUNC/TRUNCATE

  • Location: seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:311
  • Why it matters: - Root cause: the added default: branch (NumericFunction.java:311-316) makes the shared round(Number, Number, RoundingMode) helper throw TransformException(UNSUPPORTED_OPERATION) for any Number subtype not in the switch, where previously the helper fell through and returned v1 unchanged.
  • Impact: this is the right hardening for #11935, but it is a behavior change on upgrade — any pipeline feeding a non-standard Number (e.g., BigInteger) through ROUND/CEIL/FLOOR/TRUNC/TRUNCATE will now fail at runtime instead of silently passing the value through.
  • Suggested action: document the change in the transform SQL-functions docs and release notes so upgrading users can attribute the new exception correctly.
  • Evidence: seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:312 throw new TransformException(; seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:315 "Unsupported arg type %s of function %s",; seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:316 v1.getClass().getName(), ZetaSQLFunction.ROUND));
  • Suggested fix: Failing fast here is the right call, but note this flips behavior from "return the input unchanged" to "fail the job" for any Number subtype outside the switch (e.g., BigInteger), and it applies to CEIL/FLOOR/TRUNC/TRUNCATE too since they share this helper. Please call this out in the transform SQL-functions docs / release notes so upgrading users can attribute the new exception correctly.
  • Severity: Medium

Issue 6: Asymmetric overflow handling: TINYINT rounding overflow throws, but SMALLINT rounding still silently wraps via shortValue()

  • Location: seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:324
  • Why it matters: - Root cause: the new case "BYTE" in convertTo (NumericFunction.java:323-329) adds an explicit range guard before narrowing, but the adjacent case "SHORT" path that this same PR routes small integers through (the case "BYTE": case "INTEGER": case "SHORT": case "LONG": fall-through added at NumericFunction.java:259) still returns column.shortValue() with no range check.
  • Impact: ROUND(smallint_col, -1) on a value like (short) 32767 produces 32770, which shortValue() silently wraps to a negative value — the exact silent-corruption pattern this PR fixes for TINYINT remains for SMALLINT.
  • Suggested action: add the equivalent Short.MIN_VALUE/Short.MAX_VALUE guard for SHORT (and consider INTEGER, which wraps the same way via intValue()), with a mirrored overflow test.
  • Evidence: seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:324 if (column.longValue() < Byte.MIN_VALUE || column.longValue() > Byte.MAX_VALUE) {; seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:327 String.format("Rounded value %s is out of range for TINYINT", column));; seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:259 case "BYTE":
  • Suggested fix: This range guard is a good addition for TINYINT, but the SHORT case right below still does an unchecked column.shortValue(), so ROUND(smallint_col, -1) on 32767 will silently wrap to a negative value — the same silent-corruption pattern this PR fixes for TINYINT. Since the PR is titled "small integer" support, please add the equivalent Short.MIN_VALUE/Short.MAX_VALUE guard for SHORT (and ideally INTEGER, which has the same wrap via intValue()), plus a mirrored overflow test.
  • Severity: Medium

Issue 7: Overflow guard in convertTo() is added only for BYTE; SHORT and INTEGER results from the same rounding path still wrap silently

  • Location: seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:329
  • Why it matters: - Root cause: this PR adds an explicit range check before narrowing to byte in convertTo(), but the sibling branches in the same switch (case "INTEGER": return column.intValue(); and case "SHORT": return column.shortValue();) still perform unchecked narrowing on the rounded BigDecimal.
  • Impact: the exact bug class this PR fixes for TINYINT remains for SMALLINT/INT on Zeta. For example ROUND(smallint_col, -1) with input 32767 rounds to 32770, and column.shortValue() silently wraps it to a negative value instead of failing.
  • Suggested action: apply the same bounds check and TransformException to the SHORT and INTEGER cases so all fixed-width integer types behave consistently.
  • Evidence: seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:324 if (column.longValue() < Byte.MIN_VALUE || column.longValue() > Byte.MAX_VALUE) {; seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:329 return column.byteValue();
  • Suggested fix: Nice to see the explicit range check for TINYINT, but the SHORT and INTEGER branches right below still narrow with column.shortValue()/column.intValue() unchecked. ROUND(CAST(32767 AS SMALLINT), -1) rounds to 32770 and silently wraps to a negative value — the exact silent-corruption bug this PR fixes for BYTE. Please add the same bounds check (and TransformException) for the SHORT and INTEGER cases so all fixed-width integers behave consistently.
  • Severity: Medium

Issue 8: Value-overflow conditions are reported with the deprecated UNSUPPORTED_OPERATION error code, which misclassifies data-range errors

  • Location: seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:326
  • Why it matters: - Root cause: both the new ABS overflow helper and the TINYINT rounding-overflow guard use CommonErrorCodeDeprecated.UNSUPPORTED_OPERATION, an error code meant for unsupported operations/types, to signal an out-of-range data value.
  • Impact: operators triaging Zeta job failures will see an 'unsupported operation' code for what is actually a data-quality/overflow condition (e.g., a legitimate TINYINT value of -128 hitting ABS), which makes log-based alerting and troubleshooting misleading; the code is also already marked deprecated.
  • Suggested action: use a data/overflow-oriented error code from the current CommonError set for both cannotRepresentAbsoluteValue and the rounding-overflow guard.
  • Evidence: seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:326 CommonErrorCodeDeprecated.UNSUPPORTED_OPERATION,; seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunction.java:327 String.format("Rounded value %s is out of range for TINYINT", column));
  • Suggested fix: This is an out-of-range data condition, not an unsupported operation — reporting it as CommonErrorCodeDeprecated.UNSUPPORTED_OPERATION (a deprecated code, too) will mislead users triaging failures. Consider using a data/overflow-oriented error code from the current CommonError set here and in cannotRepresentAbsoluteValue, and documenting that ABS(-128) on TINYINT now fails explicitly since -128 is a valid input value.
  • Severity: Low

Review conclusion

Conclusion: final approval remains pending on the previous comments

2. Remaining follow-ups

  • Issue 1: ZetaSQLType is not updated — declared output types for ROUND/CEIL/FLOOR/TRUNC/SIGN on TINYINT/SMALLINT may not match the actual runtime values
  • Issue 2: round() helper now throws for previously pass-through Number types — a silent behavior break that also affects CEIL/FLOOR/TRUNC/TRUNCATE
  • Issue 3: Runtime return types changed to Byte/Short without touching ZetaSQLType — possible mismatch between declared output schema and produced values
  • Issue 4: No documentation update for the new TINYINT/SMALLINT support and new failure modes in docs/transform-v2/sql-functions.md
  • Issue 5: New default-throw in the shared rounding helper turns previously-silent pass-through into a runtime failure for ROUND/CEIL/FLOOR/TRUNC/TRUNCATE
  • Issue 6: Asymmetric overflow handling: TINYINT rounding overflow throws, but SMALLINT rounding still silently wraps via shortValue()
  • Issue 7: Overflow guard in convertTo() is added only for BYTE; SHORT and INTEGER results from the same rounding path still wrap silently
  • Issue 8: Value-overflow conditions are reported with the deprecated UNSUPPORTED_OPERATION error code, which misclassifies data-range errors

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

@DanielLeens

Copy link
Copy Markdown
Contributor

Thanks for the deep independent pass, @SEZ9 — really useful to have a second set of eyes on this file. Went through all eight points against the current head (034a3f47) and want to reconcile them with my own review above rather than just say "thanks":

Corroborates my Issue 2 (SMALLINT overflow-wrap unguarded) — your Issues 6 and 7. Same finding, independently reached: the new case "BYTE" in convertTo() range-checks before narrowing, but the adjacent case "SHORT"/case "INTEGER" still narrow unchecked, so ROUND(smallint_col, -1) on 32767 silently wraps to a negative value instead of throwing. Two independent reviewers landing on the identical NumericFunction.java:324 vicinity is good confirmation this needs fixing regardless of which PR ends up carrying the fix (more on that below).

Corroborates my Issue 3 (missing incompatible-changes.md entry) — your Issues 2 and 5. Agreed on the underlying gap (the new default: throw in round()'s switch, and the TINYINT pass-through-to-rounded change generally, are real behavior breaks on upgrade), though I'd fold your two into the same numbered issue as mine rather than count them separately — they're the same "needs a documented breaking-change entry" ask, just illustrated with different call sites.

I'd push back on Issues 1 and 3 (ZetaSQLType mismatch), with evidence. I checked ZetaSQLType.java at this head before agreeing this was a gap, and I don't think it is one:

  • ABS/ROUND/CEIL/CEILING/FLOOR/TRUNC/TRUNCATE all fall into the same case block at ZetaSQLType.java:463-473, which returns getExpressionType(function.getParameters().getExpressions().get(0)) — i.e. "the type of whatever the first argument's schema type already is." There's even an existing code comment right above it explaining why: "These functions all return the type of their first argument... declaring INT/DOUBLE for them would truncate BIGINT and DECIMAL results." For a TINYINT column, getExpressionType() already resolves to BasicType.BYTE_TYPE, which is exactly what this PR's abs()/round() now return at runtime ((byte) Math.abs(...), column.byteValue()). No mismatch — this dispatch was already generic before this PR, unlike [Bug][Transform-V2] Fix CEIL/FLOOR/ROUND/MOD/TRUNC silently corrupting BIGINT and DECIMAL values (#11696) #11712's BIGINT/DECIMAL fix, which needed a ZetaSQLType change for a different reason (that one wasn't a pass-through case).
  • SIGN is hardcoded at ZetaSQLType.java:376 to BasicType.INT_TYPE, independent of the argument type. This PR's sign() still returns Integer.signum(...) (an Integer) for the new Byte/Short branches, and the BigDecimal branch's signum() also returns int/Integer. So the declared type (INT) and the runtime type (Integer) still agree.

So I don't think ZetaSQLType.java needs a change here — happy to be shown a concrete failing case if I've missed one, but I checked both the pass-through functions and SIGN specifically and both line up.

I'd also push back on Issue 4 (missing docs), with a path correction. The file doesn't exist at docs/transform-v2/sql-functions.md — the real path is docs/en/transforms/sql-functions.md (and its docs/zh counterpart), which is the same file I checked in my own review. Its ABS section (line ~413) already reads: "Note that TINYINT, SMALLINT, INT, and BIGINT data types cannot represent absolute values of their minimum negative values... It leads to an exception." — that already documents both the TINYINT/SMALLINT support and the exact ABS(Byte.MIN_VALUE) failure mode you flagged, and it predates this PR (this PR's diff doesn't touch docs/). ROUND's section similarly already says "same type as argument" generically. So I don't think this file needs an update either — the only doc gap I found is the incompatible-changes.md one above.

Issue 8 (deprecated error code) — fair, taking it as a reasonable low-severity addition. No disagreement there.

One thing your review doesn't touch on that I'd like your read on: the bigger-picture Issue 1 from my own review — this PR duplicates the scope of the already twice-approved #11937 (opened 8 days earlier, same file, same methods, stacked on #11927's shared checkIntegralRange helper which already range-checks BYTE/SHORT/INTEGER/LONG uniformly — which would resolve your/my SMALLINT-overflow finding in one shot — plus it already has an incompatible-changes.md entry and a Locale.ROOT fix this PR doesn't have). Given that, I'd rather we get the author and maintainers to settle which PR moves forward before we keep stacking incremental fixes onto this one — several of the open items here (SMALLINT overflow guard, incompatible-changes.md doc) are already solved on the other PR. Would appreciate your take on that before we ask for more changes here.

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

This PR originally aimed to fix issue #11935: Zeta SQL numeric functions (ABS, ROUND, CEIL, FLOOR, TRUNC, TRUNCATE, SIGN) mishandled TINYINT/SMALLINT (Byte/Short) columns — ABS/SIGN rejected them outright, and ROUND/CEIL/FLOOR/TRUNC silently returned TINYINT values unrounded.

Important update since the last review round: between my previous review (commit 034a3f47) and the current head (a2512938), a competing PR that fixed the exact same issue — #11937, "Handle TINYINT and SMALLINT in Zeta SQL numeric functions" — was merged into dev and closed #11935 (2026-09-01, ~07:29 UTC). The author of this PR then pushed a merge commit here, a2512938 ("Sync numeric functions with dev"), which merges the latest dev into this branch. I verified by diffing this PR's actual head against that merge-base that this had a real, material effect: NumericFunction.java and ZetaSQLType.java in this PR are now byte-for-byte identical to dev. The author's own original implementation was superseded by dev's (via #11937) during that merge, and only test-file changes remain.

So, concretely, the official diff of this PR (gh pr diff 12007) today is exactly two files, 57 net inserted lines, both test-only:

  • seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/SQLNumericFunctionsTest.java
  • seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunctionTest.java

There is no longer any production-code change in this PR. Example of the actual current diff (not a fix, just an added unit assertion):

// NumericFunctionTest.java, inside the existing testAbsForDifferentNumberTypes()
Assertions.assertEquals(
        (byte) 10, NumericFunction.abs(Collections.singletonList((byte) -10)));

1. Code Change Review

1.1 Core Logic Analysis

Since there is no production-code diff, "core logic" here means: do the two remaining test files still add value, and are their assertions correct against the actual (now dev-identical) runtime behavior?

I traced the runtime path independently of the two prior reviews' conclusions, against the current source:

  • SQLTransform parses the SQL, resolves each function via ZetaSQLFunction, and asks ZetaSQLType#getFunctionType (seatunnel-transforms-v2/.../zeta/ZetaSQLType.java:458-471) for the declared output type. For ABS/ROUND/CEIL/CEILING/FLOOR/TRUNC/TRUNCATE, this returns getExpressionType(function.getParameters().getExpressions().get(0)) — i.e. the type of the first argument, so a TINYINT (BYTE) argument declares a BYTE output. SIGN is hardcoded at ZetaSQLType.java:376 to BasicType.INT_TYPE.
  • At execution time, NumericFunction.abs()/round()/sign() (.../zeta/functions/NumericFunction.java) dispatch on the runtime Number type. round()'s shared switch (line ~265) now has case "BYTE": case "INTEGER": case "SHORT": case "LONG": sharing one code path, narrows via convertTo(), which now calls a shared checkIntegralRange(value, min, max, sqlType, function) helper (line ~356) uniformly for BYTE/INTEGER/SHORT/LONG — this is #11937's checkIntegralRange helper, already merged.
  • I independently re-verified (not just trusted the prior review's rebuttal) that sign()/abs() output types line up with ZetaSQLType's declarations for the Byte/Short branches: abs((byte)-10) returns a Byte, matching the declared BYTE output type; sign() always returns an Integer, matching the hardcoded INT_TYPE. No mismatch found.
  • This confirms the normal user path (a SELECT ROUND(tiny_col, -1) ... query against a TINYINT column) does reach this dispatch chain end-to-end, not just a rarely-hit branch.

Given that, the two remaining test files:

  • NumericFunctionTest.java additions (lines ~95-97, 109-112, 205-208, 211-216, 290, 307 in the current PR branch) add unit assertions for Byte/Short abs()/sign(), MIN_VALUE overflow, Byte round()/ceil()/floor()/trunc(), Byte.MAX_VALUE round-overflow, an unsupported-BigInteger case, and a BigDecimal("1E-400") sign() case. I checked every one of these against dev's own test suite (added by #11937) and every single assertion here duplicates an assertion already present in dev — same inputs, same expected outputs — just organized inside older, more generically-named test methods instead of #11937's new, purpose-named ones (testAbsAndSignAcceptTinyIntAndSmallInt, testRoundingFamilyHandlesTinyInt, testTinyIntRoundingRejectsResultsThatDoNotFit, testRoundingRejectsUnhandledNumericTypes, testSignIsExactForDecimalsBelowDoubleRange, all already in dev). All values are correct (verified against the real, merged checkIntegralRange-based logic), just redundant.
  • SQLNumericFunctionsTest.java's new testSmallIntegerNumericFunctions() (line 74) is the one genuinely useful addition: it is, as of right now, the only test anywhere (including dev's own suite) that exercises CEIL/FLOOR/TRUNC on a TINYINT column through the full SQLTransform pipeline (SQL parsing → ZetaSQLType dispatch → NumericFunction execution → row value). I confirmed this by grepping dev's SQLNumericFunctionsTest.java: its own testTinyIntAndSmallIntFlowThroughNumericFunctions() only exercises ROUND/ABS/SIGN at the SQL level, and CEIL/FLOOR elsewhere in that file are only exercised against DOUBLE columns. I hand-checked the new test's expected values against -44 with scale -1: ABS=44, SIGN(-12)=-1, ROUND=-40, CEIL=-40, FLOOR=-50, TRUNC=-40 — all correct for standard half-up rounding / ceiling-toward-+inf / floor-toward-−inf / truncate-toward-zero semantics.

1.2 Compatibility Impact

None from this PR's current diff — it is test-only. The behavior changes originally described in this PR's own description (TINYINT rounding, ABS/SIGN acceptance, BigDecimal sign fix, default-throw for unhandled types) are real, but they shipped via #11937, which is already merged, already documented in docs/en(zh)/introduction/concepts/incompatible-changes.md, and out of scope for re-litigating here since this PR's diff no longer contains them.

One process-level compatibility concern specific to this PR: its title and description are now stale and materially misleading relative to its actual diff. The PR body (fetched from GitHub) still reads "Adds TINYINT and SMALLINT support to Zeta SQL numeric functions" with a bulleted list of behavior changes and "Closes #11935" — but #11935 is already closed (by #11937), and none of the described behavior changes are in this PR's diff anymore. Since this project squash-merges with the PR title becoming the permanent commit message (per this repo's own commit convention: [Type][Module] Description), merging as-is would write a misleading entry into git log claiming this PR delivered functionality it did not deliver — the real fix's authorship and history belong to #11937.

1.3 Performance / Side-Effect Analysis

None. Test-only diff; no new allocations, threads, locks, or I/O in the production path (which is unchanged from dev).

1.4 Error Handling and Logging

No new error handling in this PR's diff. For completeness, I re-checked (independently, not trusting the earlier reviews) whether SEZ9's Issue 8 from the previous round — that overflow conditions are reported via the deprecated CommonErrorCodeDeprecated.UNSUPPORTED_OPERATION rather than a data/overflow-specific code — is still true in the merged checkIntegralRange helper (NumericFunction.java, checkIntegralRange). It is still true, but it's now purely a dev/#11937 characteristic, not something introduced or fixable by this PR, since this PR no longer touches that file.

2. Code Quality Assessment

2.1 Coding Standards

Clean, minimal test additions, consistent with the surrounding code. One note carried over from checking the file's own history rather than a new-to-this-PR problem: the new assertions use fully-qualified org.apache.seatunnel.transform.exception.TransformException.class and java.math.BigInteger inline instead of using the file's own existing import org.apache.seatunnel.transform.exception.TransformException;. I checked the merge-base version of this file and confirmed this FQN-inline pattern already existed throughout the file before this PR, so it is a pre-existing file convention, not a new problem introduced here — not counted as a blocking issue, just noted for completeness per this project's "explain why, don't just restate" comment standard (no comment issue found; the added assertions are self-explanatory one-liners consistent with the surrounding style).

2.2 Test Coverage and Test Stability

Stability rating: Stable. Every new assertion (in both files) is a deterministic, pure-function or in-memory SQLTransform evaluation: no Thread.sleep, no timing dependencies, no shared mutable state across tests, no floating-point comparison without a delta (the one BigDecimal case uses assertEquals on exact decimal semantics, which is appropriate). No flakiness risk.

Coverage: as detailed in 1.1, most of the NumericFunctionTest.java additions duplicate coverage dev already has via #11937 — they don't hurt, but they don't help either, and create a second, disconnected place that would need updating if this behavior ever changes again. The SQLNumericFunctionsTest.java addition is a real, narrow coverage gap-filler (SQL-level CEIL/FLOOR/TRUNC on TINYINT) that is worth keeping.

2.3 Documentation Updates

Not applicable to this PR's current diff (test-only, no user-visible behavior change). The user-visible documentation for the actual TINYINT/SMALLINT support (in docs/en(zh)/transforms/sql-functions.md and incompatible-changes.md) was already handled by #11937.

3. Architectural Soundness

3.1 Elegance of the Solution

The author's decision to merge dev and let it override their own now-superseded implementation, rather than fighting for a duplicate fix, is the right call and matches the outcome my own previous review (and SEZ9's) recommended — coordinate rather than ship two competing fixes for the same file. What's left is a small, targeted test-coverage supplement, which is the right shape for a follow-up, but it is currently packaged under a PR title/description that no longer matches its contents (see Issue 1).

3.2 Maintainability

The duplicate assertions in NumericFunctionTest.java (Issue 2 below) are a minor, low-risk maintainability tax: two sets of assertions for the same TINYINT/SMALLINT values, organized differently, that a future change would need to keep in sync by hand.

3.3 Extensibility

No concerns; nothing here changes any shared code path.

3.4 Historical-Version Compatibility

No concerns from this PR's current diff. The compatibility-relevant work (round/abs/sign behavior changes, incompatible-changes.md entries) already shipped and is already reviewed/merged via #11937.

4. Issue Summary

# Issue Location Severity
1 PR title/description are stale and materially misleading relative to the actual (test-only) diff; squash-merging as-is would write an inaccurate permanent commit message claiming this PR delivered TINYINT/SMALLINT support that actually shipped via #11937 PR title & description (GitHub metadata) Medium
2 NumericFunctionTest.java additions duplicate assertions already present in dev's own test suite (merged via #11937): same TINYINT/SMALLINT abs/sign/round/overflow/BigInteger/BigDecimal-1E-400 cases, just under older/more generic test method names seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/zeta/functions/NumericFunctionTest.java (new lines ~95-97, 109-112, 205-208, 211-216, 290, 307) Low
3 Two SQL-level tests now cover overlapping TINYINT/SMALLINT ground with different names/scopes: dev's own testTinyIntAndSmallIntFlowThroughNumericFunctions and this PR's new testSmallIntegerNumericFunctions — worth consolidating into one method for future readability seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/SQLNumericFunctionsTest.java:74 vs dev's testTinyIntAndSmallIntFlowThroughNumericFunctions Low

5. Merge Recommendation

Conclusion: Ready to merge after fixes

1. Blockers — must be fixed

  • Issue 1: Update the PR title and description before merge. Since #11935 is already closed by the merged #11937, and this PR's diff is now test-only, the title/description should no longer claim to add TINYINT/SMALLINT support or "Closes #11935" — please retitle along the lines of [Test][Transform-V2] Add SQL-level coverage for CEIL/FLOOR/TRUNC on TINYINT columns (or similar) and rewrite the body to say this supplements the already-merged #11937 with one additional end-to-end SQL-level test. This matters concretely because this repo squash-merges using the PR title as the permanent commit message.

2. Recommended fixes — non-blocking

  • Issue 2: Consider dropping the duplicate assertions added to NumericFunctionTest.java — they add no coverage beyond what dev already has via #11937 and just create a second place to maintain the same values.
  • Issue 3: Consider folding the new testSmallIntegerNumericFunctions into dev's existing testTinyIntAndSmallIntFlowThroughNumericFunctions (or clearly differentiating the two by name/comment) rather than leaving two similarly-scoped SQL-level tests for the same feature area.

Overall assessment: This PR started as a duplicate fix for an issue that a competing, already-approved PR (#11937) also targeted — my previous review flagged that duplication as the primary blocker. That risk has now fully materialized and resolved itself the right way: #11937 merged first, and the author's own merge commit here (a2512938, "Sync numeric functions with dev") correctly let dev's implementation win, leaving NumericFunction.java and ZetaSQLType.java byte-for-byte identical to dev. What remains is low-risk, test-only, and mostly redundant, but it does contain one small piece of genuine value: testSmallIntegerNumericFunctions is currently the only test anywhere that proves CEIL/FLOOR/TRUNC resolve correctly through the full SQL-parsing-to-execution pipeline for TINYINT columns, which is worth keeping. I'd merge this readily once the title/description are corrected to reflect what the PR actually does today — thank you for the good-faith sync with dev rather than pushing a duplicate implementation, @zhangshenghang.

@zhangshenghang zhangshenghang changed the title [Fix][Transform-V2] Support small integer Zeta SQL functions [Test][Transform-V2] Add SQL-level coverage for CEIL/FLOOR/TRUNC on TINYINT columns Sep 9, 2026
Jelana and others added 2 commits October 17, 2026 16:08
The previous Build workflow run (created 2026-09-01) can no longer be
re-run because GitHub rejects re-runs of runs created over a month ago.
Its only failing job was all-connectors-it-4 (8, ubuntu-latest), where
AzureCosmosDBSourceIT timed out talking to the Cosmos DB emulator
(CosmosException 408/10002, ReadTimeoutException) - unrelated to the
test-only changes in this PR. Re-trigger the build with an empty commit.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>
The branch was 400 commits behind dev and missing two upstream CI fixes:
- apache#12287 and follow-ups: Docker Hub minio/minio no longer serves anonymous
  pulls, S3-backed e2e tests now use a digest-pinned ghcr.io mirror
- apache#12830: self-host the DeepWiki badge image

Both caused failures unrelated to this PR's test-only changes (all
transform-v2 jobs passed on the old head). PR test additions unchanged;
verified with JDK 17: NumericFunctionTest + SQLNumericFunctionsTest green
(46 tests), spotless:check clean.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

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

Review conclusion

Reviewed commit: 612d91b

No source-level blocking finding found in the complete test-only diff. The new SQL-level test exercises the public transform path for BYTE/SHORT inputs, while the function-level assertions cover type preservation, overflow rejection, negative-scale rounding, and tiny non-zero BigDecimal sign handling. This is the correct regression boundary: it checks both parser/type propagation and the underlying numeric functions without changing production behavior.

Compatibility: no runtime, API, configuration, or serialization change.

Validation performed: fetched the current ref; inspected both changed test classes and the covered NumericFunction/SQL transform call paths. No local build/test was run because the review scope is test coverage only.

CI gate: Build timed out, so final merge remains blocked pending a successful rerun.

Conclusion

No source-level blocking finding. Final merge gate: green CI required.

@DanielLeens

Copy link
Copy Markdown
Contributor

Quick follow-up on the CI fact I cited in my previous review: the Build check on this head (612d91b) timed out at that time, and it has since completed successfully.

My earlier review found no source-level blocking issue in this test-only diff, and CI was the only remaining gate. With the check now green, I have nothing further on my side, so I am updating my conclusion to approve. Thanks again for keeping this in sync with dev and for the focused SQL-level coverage, @zhangshenghang!

Note: I only have read-level permissions on this repository, so GitHub may keep showing earlier review states; a committer with write access can complete the final merge step.

Conclusion: Ready to merge

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

Re-checked current head 612d91b590b7, which is unchanged since my last review. In that review I found no source-level blocker, and the only remaining item was CI (my review recorded that Build had timed out). CI was previously the only remaining blocker, and it is now passing: the fork Build run 39086475909 completed with success for exactly this head SHA, and the apache-side Build check reports success as well. So my conclusion changes to approve. This is a test-only change with no runtime, API, configuration or serialization impact. Thanks again for the focused SQL-level coverage, @zhangshenghang!

Note: my reviewer account is read-only on this repository, so a maintainer with write access still needs to do the final merge. The branch being behind dev is merge metadata only and does not by itself need a source change.

@davidzollo davidzollo added the impact: low Docs, tests, tooling, a new connector, or an internal change to one connector label Oct 21, 2026

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

基本信息

  • 标题:[Test][Transform-V2] Add SQL-level coverage for CEIL/FLOOR/TRUNC on TINYINT columns
  • 中文释义:为已合入的 #11937(TINYINT/SMALLINT 数值函数支持)补充 SQL 层回归测试和单测断言
  • 作者:zhangshenghang
  • 目标分支:dev
  • 变更量:+57 / -0,2 个文件
  • 状态:OPEN,可合并
  • Review 报告时间:2026-10-21 09:20:53 EDT (UTC-04:00)
  • 本地分支:pr-12007(head 612d91b590b7)
  • PR 链接:#12007

PR 解决了什么问题(小白示例)

  • 用户痛点:#11937 让 ABS、SIGN、ROUND、CEIL、FLOOR、TRUNC 支持 TINYINT/SMALLINT 列,但缺少一条从 SQL 解析到执行的完整回归测试;以后谁改坏了类型分发,单测可能仍是绿的。
  • 修复方式:在 SQLNumericFunctionsTest 增加 testSmallIntegerNumericFunctions,用真实 SQL 对 (byte) -44 和 (short) -12 跑六个函数并断言返回类型与值;在 NumericFunctionTest 增加 Byte/Short 的 abs/sign/round/ceil/floor/trunc 断言、Byte.MIN_VALUE / Short.MIN_VALUE 的溢出异常、BigInteger 不支持异常以及 1E-400 的精确符号判断。
  • 一句话:纯测试补充,没有生产代码变化。

一、代码变更审查

1.1 核心逻辑分析

变更内容精确描述

  • SQLNumericFunctionsTest.java:+28,新增一个 @Test。
  • NumericFunctionTest.java:+29,在三个现有测试方法中增加断言。
  • 作者说明同步 dev 后 NumericFunction.java 与 ZetaSQLType.java 与 #11937 合入版本逐字节相同;git diff --stat upstream/dev...pr-12007 确认本 PR 只含两个测试文件。

关键发现

  • 无生产代码变化,正常路径不受影响。
  • 新断言都具备失败能力:例如 ROUND((byte) 44, -1) 期望 (byte) 40,若类型分发回退到 int 就会因返回类型不同而失败;Byte.MIN_VALUE 的 abs 溢出期望抛 TransformException。
  • 现有断言未被删除或放宽,只有新增。

逻辑正确性深度分析

  • SQL 层测试通过 runSql 构造 SeaTunnelRowType {BYTE_TYPE, SHORT_TYPE},断言输出字段类型为 Byte / Integer(SIGN 返回 int),与 #11937 的实现一致。
  • 1E-400 的 BigDecimal 符号测试验证的是 signum() 而非 double 转换(double 下会是 0),有意义。

1.2 兼容性影响

完全兼容,测试代码。

1.3 性能 / 副作用分析

无。

1.4 错误处理与日志

不适用。

1.5 引擎改动专项检查

不适用。

二、代码质量评估

2.1 代码规范

测试中两处以全限定名引用 org.apache.seatunnel.transform.exception.TransformException.class 和 new java.math.BigInteger("1"),同文件已有 import 的情况下可改为简名;属于风格细节,非阻塞。

2.2 测试覆盖

  • 单测:覆盖 Byte/Short 的六个函数、溢出边界、不支持类型、精确符号。
  • SQL 层:覆盖解析到执行的完整链路。
  • E2E:不需要;transform 函数的 SQL 层测试已是最接近用户路径的层级。

本地验证结果

  • git fetch upstream pull/12007/head:pr-12007:通过;head 612d91b590b7。
  • git diff --stat upstream/dev...pr-12007:通过;2 个测试文件,+57 / -0。
  • git diff upstream/dev...pr-12007:通过;逐行阅读全部新增断言,确认无删除或放宽。
  • gh pr checks 12007:通过;Build SUCCESS。
  • 编译 / 测试:未执行。原因:Review PR 默认不做本地编译;当前 head 的 GitHub CI 已运行这两个测试类并通过。

2.3 文档更新

不需要。

三、架构合理性

3.1 解决方案的优雅性

最佳改动位置评估

  • 当前改动位置:seatunnel-transforms-v2 的两个现有测试类。
  • 根因位置:根因不适用(测试补充);职责归属是把 SQL 层回归测试放在 SQLNumericFunctionsTest,把函数级断言放在 NumericFunctionTest,与现有分层一致。
  • 是否为最佳改动:是。
  • 全局最佳改动位置:同当前位置。
  • Merge 影响:不阻塞。

3.2 可维护性

在现有测试方法内追加断言,符合项目“扩展现有测试类”的惯例。

3.3 扩展性

不涉及。

3.4 历史版本兼容性

不涉及。

四、问题汇总

全量问题穷尽自检

  • PR diff / changed files:2 个文件已逐行审查完。
  • 关键调用链:测试到 NumericFunction / ZetaSQLFunction 的调用已核对;无生产代码变化。
  • 根因 / 当前改动位置 / 最佳改动位置 / 方案取舍:已判断(根因不适用)。
  • 兼容性 / 升级路径 / 协议或配置契约:不涉及。
  • 测试分层 / 文档 / 示例 / 默认配置:已核对。
  • Whale 协同仓库:不涉及。
  • CI / Review / 冲突 gate:Build SUCCESS,DanielLeens 已 APPROVE,无冲突。
  • 无法审查范围:无。

问题清单:

  1. 测试中以全限定名引用 TransformException 与 BigInteger(NumericFunctionTest.java 新增断言处),可改为 import 简名。严重程度:低。是否阻塞:否。

五、是否可以 Merge 的结论

结论:可以 merge

阻塞项(必须修复):无。
建议修复(非阻塞):问题 1,纯风格,可在后续任意 PR 顺手处理。
整体评价:具备失败能力的测试补充,不触及生产代码,CI 已绿。

@davidzollo
davidzollo merged commit d62b980 into apache:dev Oct 21, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

impact: low Docs, tests, tooling, a new connector, or an internal change to one connector reviewed Transform-v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants