datafusion-contrib / datafusion-contrib/StreamFusion

Native exact numerics: support DECIMAL unary minus and integral ABS/SIGN/FLOOR/CEIL/TRUNCATE

Open
#208 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
120
Forks
8
Avg merge
7h 29m
Merged PRs (30d)
76

Description

Rechecked on 2026-09-20 against canonical main 89da01cdad7342c4d825e36eaf4e8dc73bc7af9f, released Apache Flink 2.2.1, JDK 17, default compatibility settings. Each expression was run against independent stock-Flink and StreamFusion-enabled streaming environments with bounded runtime DataStream input (parallelism 1), so source values cannot be folded away. Results and resolved result types agree through Flink fallback; this is a native support gap, not a demonstrated wrong-result bug.

Basic exact numeric expressions still reject native Calc. Reproduced using adapted SQL cases from Flink's ScalarFunctionsTest / DecimalTypeTest and minimal runtime probes.

For runtime columns i INT=-3, n BIGINT=-4, d DECIMAL(20,3)=-12.345, execute each projection separately:

Expression Flink result Fallback reason
ABS(i), ABS(n), ABS(d) 3, 4, 12.345 ABS: only float/double operands admitted
SIGN(i), SIGN(n), SIGN(d) -1, -1, -1.000 SIGN: only float/double operands admitted
FLOOR(i), FLOOR(n) -3, -4 FLOOR: only float/double operands admitted
CEIL(i), CEIL(n) -3, -4 CEIL: only float/double operands admitted
TRUNCATE(i), TRUNCATE(n,-1) -3, 0 TRUNCATE requires a DECIMAL operand

Example: SELECT ABS(d) FROM src.

Separately, SELECT -d FROM src with d DECIMAL(7,2)=123.45 returns -123.45 via Calc: -: only float/double operands admitted. This gate also blocks composed MOD/ROUND expressions.

Preserve Flink's exact types and overflow behavior: runtime ABS(INT_MIN) returns INT_MIN and ABS(BIGINT_MIN) returns BIGINT_MIN. DECIMAL TRUNCATE already runs natively (#149); this ticket's TRUNCATE work is integral.

DECIMAL FLOOR/CEIL are excluded from the confirmed successful cases: both baseline and native-enabled jobs hit an AbstractBinaryWriter.writeDecimal assertion in this audit's collect sink. Investigate that released-host contract separately before expanding their admission.

Suggested priority: P2, first within the basic-type support backlog.

Acceptance: add runtime-source SQL parity tests that assert native Calc execution as well as values and resolved types; include NULLs and boundary/error cases; retain safe fallback for unverified forms and update docs/operators/calc-filter.md with the admitted scope.

Latest-main validation: rebuilt the debug native library from this commit and ran 562 targeted runtime SQL cases covering these support gaps and adjacent controls. This issue group contains 47 successful comparisons that still record explicit fallback. Host-rejected/both-error cases are excluded from that count. This validates released Flink 2.2.1; it does not claim execution of the Flink 1.18 profile. No implementation is included.

Distinct from closed #62 (binary DECIMAL arithmetic overflow correctness): these expressions currently execute through a planner fallback.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the adapted Flink ScalarFunctionsTest and DecimalTypeTest cases and the native Calc admission paths for unary numeric functions. Add runtime-source SQL parity coverage for values, resolved types, NULLs, and boundary or error cases, while preserving fallback for unverified forms. Update docs/operators/calc-filter.md with the admitted scope and verify native Calc execution.

Written by the indexing model from the issue text.

Assessment

Tech stack
sql
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.