fix: rewrite ordered timestamp widening predicates - #23
Merged
WenyXu merged 1 commit intoJul 29, 2026
Conversation
Signed-off-by: discord9 <discord9@163.com>
Member
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f2a0b22e49
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
evenyag
reviewed
Jul 29, 2026
evenyag
approved these changes
Jul 29, 2026
WenyXu
merged commit Jul 29, 2026
6d6ae9a
into
GreptimeTeam:greptimedb-53.1.0-function-signature-exec-error
This was referenced Jul 29, 2026
discord9
added a commit
that referenced
this pull request
Aug 3, 2026
Ports GreptimeTeam/datafusion PR #23 (source commit f2a0b22) onto the 54.1 thin fork. Ordered comparisons (>=, <, >, <=) over a coarse-to-fine timestamp widening cast now rewrite to a source-domain bound: >= and < use ceil, > and <= use floor, computed with i128 div_euclid/rem_euclid for both aligned and non-aligned target literals (aligned values collapse to the common bound). The rewrite is limited to coarse->fine timestamp units with identical timezone metadata and a target-typed non-NULL literal; it does not extend to equality/IN, timezone changes, or other cast families. Overflow policy: the ordered source bound is equivalent only for source values whose widening is representable. In line with the accepted DF53 fork PR #23 policy, this fork also applies the rewrite outside that domain, where regular CAST can error and TRY_CAST can return NULL. No full-domain equivalence is claimed. Preserved protections: equality/IN, typed NULL, timezone mismatch, dictionary, and non-default physical cast options / target field metadata all retain the cast. Signed-off-by: discord9 <discord9@163.com>
This was referenced Aug 3, 2026
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.
Which issue does this PR close?
Rationale for this change
GreptimeDB metric timestamps use millisecond precision while
now()returns a nanosecond timestamp. After mixed-timestamp coercion began preserving the finer precision, predicates such as:could no longer be unwrapped when the target literal was not aligned to the source timestamp unit. The residual cast prevents native timestamp predicate pushdown.
Although a non-aligned target literal has no singleton value preimage, ordered comparisons have exact source-domain bounds. For example, the predicate above is equivalent under the fork's existing timestamp-widening overflow policy to:
What changes are included in this PR?
i128:>= Land< Luseceil(L / q).> Land<= Lusefloor(L / q).INpredicates unchanged.CAST/TRY_CAST, literal-left operator swaps, negative timestamps, andi64boundaries.This change deliberately follows the fork's existing timestamp-widening overflow policy. It does not claim full-domain equivalence for extreme source values whose regular
CASTwould overflow or whoseTRY_CASTwould produce NULL.Are these changes tested?
Yes:
Are there any user-facing changes?
Yes. Ordered comparisons over timestamp precision-widening casts can now remove the column-side cast for non-aligned literals, enabling predicate pushdown while preserving the comparison boundary within the existing overflow policy. There is no SQL syntax or public API change.