Repository navigation
feat(query): @time: as the canonical timestamp selector; @iso: stays an alias - #1897
Conversation
576c638 to
5b32af2
Compare
aaj3f
left a comment
There was a problem hiding this comment.
This all looks good to me, @bplatz. The drift fixes (besides the product choise re @time) are particularly nice: the multi-query rewriter silently re-pinning @recorded: to @t:, and "at": "t:5" failing as a bad timestamp, were both real, and routing them through TIME_TRAVEL_TAGS / parse_at removes the parallel grammars rather than teaching them one more tag. The alias is done at the right altitude (one arm in the shared parser, same value), every surface that accepted @iso: still does, and nothing stored or on the wire changes shape. The one thing I'd fold in before merge is fluree export --at to a remote: it forwards the raw string, so time: bypasses the @iso: wire rule the body describes and fails against an older server (commands/export.rs:439-440). Beyond that, there's a stale bare-form rule in server-integration.md, and a naming question on time vs event that's worth deciding on purpose, since this spelling will be permanent.
Adherence to repo commitments:
- Patterns/abstractions: ✔ Extends the shared grammar and deletes two hand-kept tag lists plus the object form's private split; no new parser.
- Performance (speed first, memory second): ✔ Parser and envelope-validation only, allocation-free recognizer; no engine or hot-path change. No performance-degradation risk.
- Testing: ✔ Unit coverage for every new spelling on both object-form shapes, multi-query rewriter and validator, CLI help and wire spelling; Iceberg integration runs
time:andiso:side by side on JSON-LD and SPARQL. CI'stestjob ran with the new tests visible by name; the multi-query tests go red under mutation. (Nit: no native-ledger end-to-end@time:query.) - Conventions:
⚠️ Thorough commit body and ~20 doc pages updated consistently;server-integration.md's bare-form rule wasn't updated alongside the code.
Verified locally at 5b32af2f: core ledger_id 12/12, API dataset:: / query::multi / time_spec 207/207, TIME_TRAVEL_TAGS mutation caught by both new multi-query tests; CI test job 13 028/13 028 on the stacked merge ref.
Approving so you can merge when ready (after #1896), but maybe worth folding in the export wire fix and the doc line first.
| | `--context <JSON>` | JSON-LD context for prefix declarations. Overrides the ledger's default context. | | ||
| | `--context-file <FILE>` | Read context from a JSON file. Overrides the ledger's default context. | | ||
| | `--at <TIME>` | Export data as of a specific point in time. `t:<N>` (transaction number), `t:latest` or `latest`, `iso:<ISO-8601>` (commit event time), `recorded:<ISO-8601>` (the wall-clock time the commit was recorded), or `commit:<hex-prefix>`. A bare transaction number, ISO-8601 timestamp or commit prefix also works; a commit prefix must be at least 6 characters in either spelling; a bare integer is read as a transaction number, so use `commit:<prefix>` to force an all-digit prefix. If omitted, exports at the latest committed time (including data committed but not yet persisted to index). | | ||
| | `--at <TIME>` | Export data as of a specific point in time. `t:<N>` (transaction number), `t:latest` or `latest`, `time:<ISO-8601>` (commit event time), `recorded:<ISO-8601>` (the wall-clock time the commit was recorded), or `commit:<hex-prefix>`. A bare transaction number, ISO-8601 timestamp or commit prefix also works; a commit prefix must be at least 6 characters in either spelling; a bare integer is read as a transaction number, so use `commit:<prefix>` to force an all-digit prefix. If omitted, exports at the latest committed time (including data committed but not yet persisted to index). | |
There was a problem hiding this comment.
fluree-db-cli/src/commands/export.rs:439-440 — Optional (recommended) — fluree export --at time:… against a remote server doesn't get the @iso: wire treatment. The real location is fluree-db-cli/src/commands/export.rs:439-440 (run_remote_rdf), which puts the user's raw --at string into the request body instead of going through time_spec_to_suffix. So the rule in the body — "the CLI keeps sending @iso: to remote servers … a CLI is routinely newer than the server it talks to" — holds for query and history but not for export, and this line now tells export users to write time:.
Against a server older than this PR, TimeSpec::parse_at("time:2024-01-15T10:30:00Z") doesn't know the tag, falls through to the bare-timestamp arm (the string contains - and :), and dies later as Invalid ISO-8601 timestamp for time travel: time:2024-…, returned as a 500. It's loud, but it's precisely the version-skew case the wire-spelling rule was written for.
Minimally, parse and re-render before sending, e.g.
if let Some(at_str) = at {
let spec = crate::commands::query::parse_time_spec(at_str)?;
let wire = crate::commands::query::time_spec_to_suffix(&spec);
body["at"] = serde_json::Value::String(wire.trim_start_matches('@').to_string());
}which also gets --at validated client-side, the way query --at already is. A small unit test alongside timestamp_renders_with_the_universally_accepted_tag would pin it. This is minor and non-blocking, but if you agree it's right, I'd rather see it folded in now than lost in the backlog.
Commenting here because fluree-db-cli/src/commands/export.rs is not in this diff.
| `time:<ISO-8601>`, `recorded:<ISO-8601>` and `commit:<hex-prefix>` (min 6 | ||
| characters) — the same grammar a ledger address carries after `@`, minus | ||
| the `@`. For compatibility also accept three untagged forms, tried in this | ||
| order: `latest`; a bare integer (a `t`); a string containing both `-` and |
There was a problem hiding this comment.
Optional (doc) — this paragraph still documents the old bare-form rule.
This paragraph still specifies the old bare-form rule — "a string containing both - and : (an ISO-8601 timestamp)" — but TimeSpec::parse_at now classifies anything containing - as a timestamp (fluree-db-api/src/dataset.rs:593). Since this page is the contract for alternative server implementations, it probably wants the same change the code got — lines 2115–2116 becoming something like:
order: `latest`; a bare integer (a `t`); a string containing `-` (an
ISO-8601 timestamp or date); anything else as a commit hex-digest prefix.Tiny, and worth folding in with the rest.
There was a problem hiding this comment.
Addressed in 6cd06e0. The contract also now lists iso: as an alias servers must accept, since that's the spelling the CLI sends.
| /// bare ISO-8601 timestamp — can tell "the user reached for a canonical tag and | ||
| /// got it wrong" apart from "the user typed one of the bare forms". | ||
| pub const TIME_TRAVEL_TAGS: [&str; 5] = ["t:", "iso:", "commit:", "recorded:", "snapshot:"]; | ||
| pub const TIME_TRAVEL_TAGS: [&str; 6] = |
There was a problem hiding this comment.
Question (naming) — @time: vs @event: for the canonical event-time tag.
This is more of a question than a suggestion, and it's really about product direction rather than the code. The body's organizing idea is that the tags name coordinate kinds — t, time, recorded, commit, snapshot. But recorded is also a time, so time ends up being the one generic word among specific ones, and @event: would read as the natural pair of @recorded:. I can see the counter-argument (on every ledger without caller-supplied event times, and on every table source, the two axes coincide, so plain "time" is what most people mean). Since @iso: stays accepted "indefinitely", whatever we make canonical now is effectively permanent — so I just want to make sure we're picking time on purpose, not by default. Happy to talk it through.
There was a problem hiding this comment.
Keeping @time:: --at time:… reads naturally, and it is the axis users mean. If anything, @recorded: is the one that could be improved, but we won't align the canonical name to it.
| // the COUNT agreeing with the scan. | ||
| let honored: Vec<(String, TimeSpec)> = vec![ | ||
| (format!("snapshot:{first}"), TimeSpec::AtSnapshot(first)), | ||
| (format!("time:{between}"), TimeSpec::AtTime(between.clone())), |
There was a problem hiding this comment.
Nit — no native-ledger end-to-end @time: query.
The only end-to-end @time: queries are the Iceberg ones in it_iceberg_local_fs; native ledgers get time: through unit tests only. Since time: and iso: produce the identical LedgerIdTimeSpec::AtIso, I don't think there's real risk here, but the docs now lead with @time: for ledgers, and the SPARQL FROM route is a separate entry point. One @time: case (JSON-LD from plus SPARQL FROM) in it_query_time_travel.rs would be cheap insurance.
| /// [`TIME_TRAVEL_TAGS`]) starts in `s`, if it carries one. One source of truth | ||
| /// with the parser, so a tag added there is recognised here and by the | ||
| /// envelope validator in `mod.rs`. | ||
| pub(super) fn explicit_pin_at(s: &str) -> Option<usize> { |
There was a problem hiding this comment.
Praise — deriving the envelope's pin detection from TIME_TRAVEL_TAGS, and having the validator reuse the same helpers, is exactly the fix — it removes the class of drift rather than patching the one missing tag. I checked: drop recorded: / snapshot: from TIME_TRAVEL_TAGS and both new multi-query tests go red.
| /// The exact inverse of [`parse_time_spec`] on the canonical spellings; the | ||
| /// round trip is pinned by `time_spec_suffix_round_trips_through_parse`. | ||
| /// An inverse of [`parse_time_spec`]; the round trip is pinned by | ||
| /// `time_spec_suffix_round_trips_through_parse`. `AtTime` renders as `@iso:`, |
There was a problem hiding this comment.
Praise — keeping @iso: on the wire, with a test that pins it and a comment saying when to flip it, is the right call for a CLI that's routinely newer than its server.
…an alias `@time:<ISO-8601>` replaces `@iso:` as the documented spelling of the event-time selector on every surface: ledger addresses, SPARQL FROM, the `from` object form, CLI `--at`, and HTTP `at=`. `@iso:` parses to the same value and remains accepted indefinitely; error text and help list `time:` and note the alias. The multi-query envelope advises `@time:` for pinning. The CLI keeps rendering a timestamp as `@iso:` on the wire: every server release accepts that, while one older than the alias rejects `@time:`, and a CLI is routinely newer than the server it talks to. Two spots kept their own copy of the grammar and are now routed through the shared one. The multi-query snapshot rewriter and envelope validator each recognised pinned FROM clauses by a hand-kept list (`@t:`/`@iso:`/`@commit:`) that never learned `@recorded:`, so a recorded-axis pin was silently re-pinned to `@t:` and escaped the asOf-collision check; both now derive from `TIME_TRAVEL_TAGS`. The `from` object form's `"at"` key read anything untagged as a timestamp, so `"at": "t:5"` or `"at": "time:..."` became an invalid timestamp downstream; it now takes `TimeSpec::parse_at`, the same grammar as `--at`, whose bare-form rule also learns that a value with `-` is a timestamp (a date-only `2024-01-15` was read as a commit prefix). Docs use `@time:` throughout and state the alias where the selector is introduced.
5b32af2 to
de0481c
Compare
`fluree export --at` put the raw string into the remote request body, so `time:<ISO>` bypassed the rule that the CLI sends `iso:` (which every server accepts) and failed against a server older than the `time:` alias. It is now parsed and re-rendered the way `query --at` is, which also rejects a malformed value before the request. The server-integration contract now lists `iso:` as an alias servers must accept, since it is what the CLI sends, and states the bare-form rule the parser uses: a string containing `-` is a timestamp or date. Adds a native-ledger end-to-end test: a pin between two commits selects the same state as `@time:` and `@iso:`, through JSON-LD `from` and SPARQL `FROM`.
Dataset-spec parse errors from JSON-LD `from`/`fromNamed` and SPARQL `FROM`/`FROM NAMED` went through ApiError::query, an Internal 500, though every one is a caller error: an invalid value, a malformed or unknown time-travel tag, a duplicate alias, an ambiguous graph selector. That includes a CLI sending `@time:` to a server that predates the alias. They now go through ApiError::invalid_query (400). The invalid-format and missing-value time-travel tests assert the 400, cover SPARQL FROM, and include `@time:`.
Summary
@time:<ISO-8601>becomes the canonical spelling of the event-time selector on every surface — ledger addresses, SPARQLFROM, thefromobject form's"at", CLI--at, HTTPat=.@iso:parses to the identical value and stays accepted indefinitely; error text and--helplisttime:and name the alias.Stacked on #1896. The rename came out of that work: pinning Iceberg history and planning the same for Delta tables put every selector side by side, and the set only reads coherently as names of coordinate kinds —
@t:(transaction),@time:(event time),@recorded:(recorded time),@commit:(commit hash),@snapshot:(table snapshot / version) — withatbeing the slot that holds any of them (--at t:5,--at time:…,--at commit:…).isonamed the encoding, not the coordinate, and was the odd one out.What changes
time:added toparse_time_travel_specandTIME_TRAVEL_TAGS;iso:is parsed by the same arm. Both report their own tag in the "missing value" error.@iso:→@time:across the query, CLI, API, and concept docs, with the alias stated where the selector is introduced. The Iceberg time-travel section from feat(iceberg): time-pinned graph-source reads via @iso: and @snapshot: #1896 is rewritten in the new spelling.@iso:to remote servers. Every server release accepts it, while a server older than this alias rejects@time:outright, and a CLI is routinely newer than the server it talks to.@time:is the documented input; the wire spelling flips once@time:is the floor of supported servers. Pinned by a test.Two drift bugs the rename surfaced, fixed by sharing the grammar
@t:/@iso:/@commit:) in two places — the snapshot rewriter and the validator — that never learned@recorded:. A recorded-axis pin was silently re-pinned to@t:by the rewriter and escaped the validator'sasOfcollision check;@time:would have failed outright (the unstripped suffix madeledgerA:main@time:…look like a branch name containing:). Both now derive fromTIME_TRAVEL_TAGSthrough one pair of helpers, allocation-free.fromobject form's"at"key had its own three-way split that read anything untagged as a timestamp, so"at": "t:5"or"at": "time:…"became an invalid-timestamp error downstream. It now takesTimeSpec::parse_at, the same grammar as--at. That grammar's bare-form rule also learns that a value containing-is a timestamp: a date-only"2024-01-15"used to be classified as a commit-hash prefix and fail with a misleading "commit not found".Verification
time:andiso:parse to the same value; each reports its own tag; both are inTIME_TRAVEL_TAGS.time:/snapshot:; malformedtime:/snapshot:are rejected; the object form's"at"accepts all nine spellings on bothfromandfromNamedshapes, plus the date-only case and a malformed-tag error.jsonld_string_from_with_any_grammar_tag_left_untouched) and the validator (validator_recognises_every_grammar_tag_as_a_pin, which also checks distinct-ledger counting strips it). The rewriter test was mutation-checked against the old three-tag list.@iso:;--helpliststime:<ISO-8601>and the alias on query/export/history.time:andiso:pins side by side.Gates: workspace
cargo check --all-targets,clippy --all --all-features --all-targets -D warnings, the wasm clippy gate,fmt --checkclean. Suites: coreledger_id, API lib 1074,grp_query471,grp_graphsource161,grp_query_history64,grp_index93,it_iceberg_local_fs, CLI (incl.time_travel_spec), server — pass.