Conversation
SQL's NOW()/CURRENT_TIMESTAMP fell into the generic FunctionCall catch-all, giving the IR no signal that a predicate using it is evaluation-time-dependent. Map zero-arg now()/current_timestamp to the same QueryTimestamp leaf PromQL's time() already uses. Exposed two latent gaps in code that assumed every scalar-position QueryExpr was one of a fixed list of variants (never hit before since PromQL's time() never appears inside a scan predicate): columns_referenced() and resolve_expr() both lacked a QueryTimestamp arm. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Contributor
|
If promql doesn't have timestamp set, it should be NOW. |
Contributor
|
TODO: add a test for differentiating these two timestamps for two languages. |
Contributor
|
Addressed both follow-up comments in 93ff568.
Validation: |
zzylol
approved these changes
Aug 25, 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.
Summary
Closes #184.
SQL
NOW()andCURRENT_TIMESTAMPpreviously lowered to the genericFunctionCallcatch-all, so the shared IR could not identify them as runtime-dependent clock expressions. This PR gives SQL current-time expressions an explicit, timestamp-typed representation while preserving PromQL's differenttime()contract.The final IR has two distinct leaves:
EvalTimestamp: PromQLtime(), represented as Unix seconds (Float64). It is the timestamp at which the expression is evaluated—not inherently the current wall-clock time. For an instant Prometheus HTTP query only, omitting the optionaltimerequest parameter makes the API use the server's current time.CurrentTimestamp: SQLNOW()/CURRENT_TIMESTAMP, represented asDataType::Timestamp.Keeping these leaves separate prevents SQL timestamp comparisons such as
ts < NOW()from being incorrectly typed as comparisons against aFloat64.QueryTimestampwas renamed to the more preciseEvalTimestampthroughout the IR, frontends, traversals, CSE hashing, DAG export, devtools, tests, and design documentation.The codebase uses one recursive
QueryExpr<C>enum for relational operators and scalar subexpressions, so both leaves can appear directly inside predicates and projections without introducing a separate scalar IR.Before / after
SQL query:
Before:
After:
PromQL remains semantically distinct:
Implementation
nowandcurrent_timestamptoCurrentTimestamp.CurrentTimestamp.QueryTimestamptoEvalTimestamp.Bare FROM-less
SELECT NOW()still encounters the pre-existingEmptyRelationlowering gap and remains outside this PR.SELECT CURRENT_TIMESTAMP FROM <table>and predicate forms are covered.Test plan
NOW()in a timestamp predicate lowers toCurrentTimestamp.now()in a timestamp predicate lowers toCurrentTimestamp.CURRENT_TIMESTAMPlowers to aTimestamp-typed leaf.time()lowers toEvalTimestamp/Float64, while SQLCURRENT_TIMESTAMPlowers toCurrentTimestamp/Timestamp.cargo check --workspace.cargo test -p asap-types -p asap-frontend-promql -p asap-frontend-sql.