Skip to content

fix: Handle nested DuckDB TIMESTAMPDIFF rewrites#2097

Merged
ferenc-csaky merged 1 commit into
mainfrom
fix/nested-timestampdiff-duckdb
May 26, 2026
Merged

fix: Handle nested DuckDB TIMESTAMPDIFF rewrites#2097
ferenc-csaky merged 1 commit into
mainfrom
fix/nested-timestampdiff-duckdb

Conversation

@ferenc-csaky
Copy link
Copy Markdown
Collaborator

Fixes a DuckDB TIMESTAMPDIFF translation failure where Calcite REINTERPRET nodes could leak into SQL unparsing.

Cause

  • SimpleCallTransform stopped traversal whenever it saw a matching operator, even if the transform returned the original call unchanged.
  • For nested expressions like CAST, CASE, and NULLIF around TIMESTAMPDIFF(MONTH, ...), this could prevent the DuckDB timestamp diff rewrite from reaching the inner CAST(Reinterpret(MINUS_DATE(...))).
  • The unrewritten REINTERPRET then failed during SQL generation with SqlSyntax$7: SPECIAL.

Fix

  • Changed SimpleCallTransform to continue visiting child calls when a transform returns the original RexCall.
  • This lets the existing TIMESTAMPDIFF rewrite reach nested timestamp-diff decomposition patterns.
    Test coverage:
  • Added DuckDB translation coverage for CAST(TIMESTAMPDIFF(MONTH, ...) AS DECIMAL(...)).
  • Added coverage for TIMESTAMPDIFF(MONTH, ...) inside CASE WHEN ... / NULLIF(..., 0), matching the failing query shape.

@ferenc-csaky ferenc-csaky added this to the 0.10.6 milestone May 26, 2026
@ferenc-csaky ferenc-csaky added the bug Something isn't working label May 26, 2026
@ferenc-csaky ferenc-csaky force-pushed the fix/nested-timestampdiff-duckdb branch from c534aca to 8e4e586 Compare May 26, 2026 15:28
@codecov
Copy link
Copy Markdown

codecov Bot commented May 26, 2026

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 14.02%. Comparing base (cc63718) to head (8e4e586).
⚠️ Report is 3 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
.../datasqrl/calcite/convert/SimpleCallTransform.java 0.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2097      +/-   ##
============================================
- Coverage     14.02%   14.02%   -0.01%     
  Complexity      859      859              
============================================
  Files           605      605              
  Lines         17269    17271       +2     
  Branches       2087     2088       +1     
============================================
  Hits           2422     2422              
- Misses        14614    14616       +2     
  Partials        233      233              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ferenc-csaky ferenc-csaky merged commit 74c19d8 into main May 26, 2026
16 checks passed
@ferenc-csaky ferenc-csaky deleted the fix/nested-timestampdiff-duckdb branch May 26, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants