fix: Handle nested DuckDB TIMESTAMPDIFF rewrites#2097
Merged
Conversation
mateczagany
approved these changes
May 26, 2026
c534aca to
8e4e586
Compare
Codecov Report❌ Patch coverage is
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a DuckDB
TIMESTAMPDIFFtranslation failure where CalciteREINTERPRETnodes could leak into SQL unparsing.Cause
SimpleCallTransformstopped traversal whenever it saw a matching operator, even if the transform returned the original call unchanged.CAST,CASE, andNULLIFaroundTIMESTAMPDIFF(MONTH, ...), this could prevent the DuckDB timestamp diff rewrite from reaching the innerCAST(Reinterpret(MINUS_DATE(...))).REINTERPRETthen failed during SQL generation withSqlSyntax$7: SPECIAL.Fix
SimpleCallTransformto continue visiting child calls when a transform returns the originalRexCall.TIMESTAMPDIFFrewrite reach nested timestamp-diff decomposition patterns.Test coverage:
CAST(TIMESTAMPDIFF(MONTH, ...) AS DECIMAL(...)).TIMESTAMPDIFF(MONTH, ...)insideCASE WHEN ... / NULLIF(..., 0), matching the failing query shape.