Skip to content

Native DECIMAL: support runtime scale arguments to ROUND and TRUNCATE #225

Description

@liuyongvs

Verified on PR #220 after rebasing onto merged #222: commit 16ebb1e5a45cc5420abf90473b785d6c0b908a82, released Apache Flink 2.2.1, JDK 17, default compatibility settings. Each probe uses independent stock-Flink and native-enabled environments with bounded runtime DataStream input. Successful comparisons check output values and resolved result types before classifying execution.

Suggested priority: P2. This is a verified native support gap; the successful probes return equal results through explicit Flink fallback.

Literal-scale support in #88/#149 does not admit a scale column. The successful STRING consumers below isolate this gap without relying on the released host collect serializer for dynamic-scale DECIMAL output.

Runtime probe

Input type:

ROW<`f0` DECIMAL(20, 3), `f1` INT> NOT NULL

Input: [+I[123.456, 2]]

SELECT CAST(ROUND(f0,f1) AS STRING) FROM src;

Flink result: [[123.46]]; resolved type: [STRING]. Native substitutions: 0.

Calc: DECIMAL ROUND requires a literal INT scale

Runtime probe

Input type:

ROW<`f0` DECIMAL(20, 3), `f1` INT> NOT NULL

Input: [+I[123.456, 2]]

SELECT CAST(TRUNCATE(f0,f1) AS STRING) FROM src;

Flink result: [[123.45]]; resolved type: [STRING]. Native substitutions: 0.

Calc: DECIMAL TRUNCATE requires a literal INT scale

Also investigate the direct DECIMAL output contract before admitting it: with DECIMAL(20,3)=123.456 and scale=2, the released collect path reports 12.346/12.345 for direct ROUND/TRUNCATE, whereas the STRING consumers report 123.46/123.45. Both engine configurations reproduce the same behavior. Preserve the released-host contract and distinguish expression evaluation from boundary precision/scale metadata; do not silently substitute an intuitive result. Include negative/NULL scales, scale expansion, precision 38 and nested consumers.

Acceptance

Preserve released Flink values, resolved types, NULL behavior and relevant error/short-circuit semantics. Add runtime-source SQL regressions that assert the specific native operator as well as result parity; do not use constant folding as proof of native support. Keep safe fallback for unverified forms and update the corresponding operator coverage documentation.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions