Sitelet https://github.com/apache/paimon/pull/10360
Skip to content

[cdc] Reject a non-positive width for the truncate computed column - #10360

Open
jackylee-ch wants to merge 1 commit into
apache:masterfrom
jackylee-ch:cdc-validate-truncate-width
Open

jackylee-ch wants to merge 1 commit into
apache:masterfrom
jackylee-ch:cdc-validate-truncate-width

Conversation

@jackylee-ch

Copy link
Copy Markdown
Contributor

Purpose

The truncate computed column (Expression.TruncateComputer) parses its
width literal but never checks the sign. A non-positive width is only caught
later, at per-row eval, and inconsistently: integer and DECIMAL columns
throw ArithmeticException: / by zero once the sync job is already running,
while CHAR/VARCHAR columns silently produce an empty string. A width of 0
or a negative value is never meaningful for truncation.

This validates width > 0 in the constructor, so a bad definition such as
--computed_column 'x=truncate(amount,0)' fails fast at job build time with a
clear message, mirroring the sibling substring expression that already
validates its indices.

Tests

TruncateComputerTest#testTruncateRejectsNonPositiveWidth asserts the
constructor rejects width 0 and negatives across int/bigint/decimal/varchar.
Existing positive-width coverage is unaffected.

API and Format

No change.

Documentation

No change.

@jackylee-ch
jackylee-ch force-pushed the cdc-validate-truncate-width branch from 6ca3ffb to 9301a4e Compare October 3, 2026 18:13
TruncateComputer parsed the width literal but never checked its sign.
A non-positive width only failed later, at per-row eval: integer and
decimal columns threw ArithmeticException (/ by zero) once the sync job
was already running, while char/varchar columns silently produced an
empty string. Validate width > 0 in the constructor so a bad
computed-column definition fails fast with a clear message, mirroring
the sibling substring expression that already validates its indices.
@jackylee-ch
jackylee-ch force-pushed the cdc-validate-truncate-width branch from 9301a4e to b402dff Compare October 4, 2026 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant