Skip to content

[FLINK-41105][runtime] Fix Janino compile error for DECIMAL arithmetic with numeric literals - #4624

Open
xxntti3n wants to merge 3 commits into
apache:masterfrom
xxntti3n:fix/FLINK-41105-decimal-literal-arith
Open

xxntti3n wants to merge 3 commits into
apache:masterfrom
xxntti3n:fix/FLINK-41105-decimal-literal-arith

Conversation

@xxntti3n

@xxntti3n xxntti3n commented Nov 13, 2026 •

Copy link
Copy Markdown

What is the purpose of this pull request?

Fixes FLINK-41105: a transform projection such as price * 1.13 (DECIMAL column × numeric literal) passes schema derivation but fails on the first DataChangeEvent with a Janino CompileException (No applicable constructor/method found for actual parameters "java.math.BigDecimal, double"), so the job restarts forever.

Root cause: when the derived result type is DECIMAL, JaninoCompiler.generateBinaryOperation routes + - * / to ArithmeticFunctions.plus/minus/times/divides, which only have (BigDecimal, BigDecimal) for DECIMAL. A literal like 1.13 is parsed by Janino as double (2 as int), and INT/BIGINT columns are boxed primitives, so no overload matches.

Brief change log

  • JaninoCompiler: in the DECIMAL-result branch of generateBinaryOperation, align each operand to BigDecimal via a new alignOperandToBigDecimal:
    • operands already typed DECIMAL (columns, sub-expressions) are left untouched, except a DECIMAL dividend of /, which is widened to the result scale;
    • decimal literals are built from their exact text with castToBigDecimal("1.13", p, s), never from a double, so no binary floating-point error. A literal dividend is widened to the result scale;
    • integral operands (INT/BIGINT columns, integer literals) go through castToBigDecimal(x, 38, <result scale>).
  • Why the scale matters: ArithmeticFunctions.divides keeps the scale of its dividend, so casting at scale 0 (or at the literal's own scale) truncated colInt / 1.5, 1 / colDecimal, 1.5 / colDecimal and colDecimal / 3.
  • Non-DECIMAL expressions and existing overload sets are unchanged.

Verifying this change

This change added tests and can be verified as follows:

  • PostTransformOperatorTest#testDecimalArithmeticWithNumericLiteral (19 parameterized cases through the real operator): colDecimal * 1.13, * 2, + 1.5, - 1.5, / 2, colInt * 1.5, literal on the left, negative literal, nested expression, DECIMAL x DECIMAL, plus division cases with an integral or decimal dividend (colInt / 1.5, 1 / colDecimal, 1.5 / colDecimal, colDecimal / 3). Without the fix the multiplication/addition/subtraction cases fail with the CompileException above, and the division cases return truncated quotients.
  • FlinkPipelineTransformITCase#testDecimalArithmeticWithNumericLiteral: runs 10 projections through Values source -> transform -> Values sink on a MiniCluster. On the code before this PR 10 of 12 cases fail; with the fix they pass.
  • spotless:check and checkstyle:check pass for flink-cdc-runtime and flink-cdc-composer.
  • FlinkPipelineUdfITCase (52), FlinkPipelineTransformITCase (82), TransformParserTest and PostTransformOperatorTest pass on JDK 17.

Out of scope: the % (MOD) operator on DECIMAL still fails at type inference (validated INTEGER vs converted DECIMAL). It is a separate problem and is not changed here.

Documentation

  • Does this pull request introduce a new feature? no
  • If yes, how is the feature documented? not applicable

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: Claude Code (Claude Sonnet 5.5)

I reviewed the change and the test results myself.

…c with numeric literals

When the result type of a binary arithmetic expression is DECIMAL, the
operation is routed to ArithmeticFunctions.plus/minus/times/divides, which
only accept (BigDecimal, BigDecimal). Numeric literals such as 1.13 were
parsed by Janino as double and non-DECIMAL columns are boxed primitives, so
expressions like `price * 1.13` or `cnt * 1.5` passed schema derivation but
failed on the first event with "No applicable constructor/method found".

Align every operand of a DECIMAL-typed arithmetic expression to BigDecimal.
DECIMAL operands are untouched, decimal literals are built from their exact
text via castToBigDecimal (never from a double), and integral operands are
converted with castToBigDecimal(x, 38, 0).
@xxntti3n
xxntti3n force-pushed the fix/FLINK-41105-decimal-literal-arith branch from 4e30381 to 6d11966 Compare November 13, 2026 15:53
…tegral or literal dividend

ArithmeticFunctions.divides keeps the scale of its dividend, so an operand
cast with scale 0 (integral column/literal) or at its own scale (decimal
literal, DECIMAL column) truncated the quotient. Cast operands to the scale
of the derived result type instead, and cover the cases in
PostTransformOperatorTest.
…hmetic with numeric literals

Runs transform projections such as decimal_c * 1.13, int_c / 1.5 and
1.5 / decimal_c through the Values source -> transform -> Values sink
pipeline on a MiniCluster and asserts the emitted values. Also apply
spotless formatting to JaninoCompiler.

This branch has not been deployed

No deployments
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.

1 participant