Skip to content

feat(iceberg): time-pinned graph-source reads via @iso: and @snapshot: - #1896

Merged
bplatz merged 3 commits into
mainfrom
feat/iceberg-snapshot-time-travel
Sep 22, 2026
Merged

bplatz merged 3 commits into
mainfrom
feat/iceberg-snapshot-time-travel

Conversation

@bplatz

@bplatz bplatz commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A time specification on an Iceberg graph-source alias now selects the snapshot the query reads, on every route. Previously the from-driven route refused any time spec on a graph source, while the lazy graph_at() handle's graph-source fallback dropped the pin and silently answered from the latest snapshot — the MCP sparql_query tool reached that path when re-sending the envelope's t. The Iceberg docs also described @snapshot: / @timestamp: selectors the grammar never accepted.

Selectors on a graph-source alias

Selector Selects
@snapshot:<id> (new tag) exactly that Iceberg snapshot id; any retained snapshot, including one later rolled back
@iso: / @recorded: the snapshot that was the table's current state at that instant — the latest snapshot-log entry at or before it (Iceberg's own TIMESTAMP AS OF rule), falling back to the current snapshot's ancestry when a table has no log. A rolled-back or branch-only snapshot is never selected by time.

@iso: and @recorded: coincide on a table source (one time axis, the writer's commit time), the same rule as a ledger that never used caller-supplied event times.

Refusals — never a fallback to the current or oldest snapshot

  • @t: / @commit: on a graph source (they name ledger states); @snapshot: on a native ledger.
  • Any pin on a source that is not an Iceberg-backed table (SQL-backed R2RML, BM25, vector): those read their current state and would otherwise accept the pin and ignore it. Classified at view construction from the nameservice record.
  • An unknown snapshot id → SnapshotNotFound; an instant before the oldest retained snapshot → new typed NoSnapshotAtTime, naming the oldest. A table with no snapshots reads as empty unpinned and errors when pinned.
  • One source read at two states in one query — two different pins, or pinned in one view and unpinned in another across from/fromNamed. A pin applies to every read of a source for the whole query, so the alternative is one pin silently deciding for the other view.

Every refusal is a 400: the ones built at view construction are InvalidQuery (new ApiError::invalid_query), not the Internal 500 that ApiError::query produces.

Mechanics

  • fluree_db_query::r2rml::SourceTime { SnapshotId | AsOfTimestampMs } and R2rmlTableProvider::pin_source_time, whose default implementation refuses, so no provider can let a pinned query run at its current state by omission.
  • Both routes build the graph-source view through one resolve_graph_source_at; the view carries the pin and each execution core pushes it into the provider before running.
  • The provider resolves the pin in one select_snapshot used by both the scan and the manifest COUNT shortcut, so a count and a scan in one query cannot disagree. Columns resolve through field ids: the selected snapshot's schema is read under current column names, so the current R2RML mapping still finds a column renamed since the pin, and a column added since reads as absent.
  • On a REST catalog, the cross-query caches cannot answer a pin they predate: the disk metadata pointer applies the as-of rider and is used only when its metadata lists the pinned snapshot id or has a current snapshot at or after the instant; the in-memory loadTable cache (location only, uncheckable) is skipped for pinned reads.
  • The scan-files and count-stats caches are keyed by snapshot, so a historical pin warms like the current snapshot instead of bypassing the caches.
  • Graph-source results carry no t on either the plain or tracked route: the genesis view's 0 named no state a client could pin to, and the MCP pagination protocol was echoing it back.
  • The three hand-copied ledger time-spec resolvers collapse onto time_resolve::resolve_time_spec; the ISO parse/render helpers are unified (a malformed timestamp is now a 400 on ledgers too, not a 500).

Verification

Fixture: the committed two-snapshot silver/people table (3 rows, then +2), so a pin that were dropped would still return all five.

it_iceberg_local_fs::pinned_query_on_a_graph_source_reads_that_snapshot covers, on the JSON-LD from, SPARQL FROM <…>, and graph_at() routes: four honored pins (rows = 3, COUNT = 3, explicit GRAPH <alias> block), before-oldest / unknown-id / @t: / @commit: refusals, two-pins and pinned+unpinned conflicts, a no-snapshots table (empty unpinned, refused pinned), @snapshot: on a ledger, a BM25 source, a malformed timestamp on a ledger, a 400 on every refusal, tracked execution on both routes, and no t on results.

graph_source::r2rml::tests::time_pinned_rest_read_bypasses_caches_too_stale_for_the_pin drives load_table_context against a REST source with a stale disk pointer and a stale loadTable entry: pins the cached metadata can't answer reach the catalog; unpinned reads and answerable pins stay on cache. read_schema_resolves_current_names_by_field_id covers rename, add, and drop-with-name-reuse.

Every new path was mutation-checked — reverting each fix makes the test fail: pin ignored in select_snapshot (→ 5 rows), pin ignored in the COUNT path (→ [[5]], which also proves the manifest shortcut fired), pin push dropped from the single-view core or either tracked core (single-view and dataset), t suppression removed, unpinned view following a pin, non-Iceberg refusal removed (→ [] silently).

Iceberg unit tests pin the lineage rule: a rolled-back table resolves AS OF per the snapshot log, and a table without a log walks current ancestry so an orphaned branch snapshot is never chosen by time.

Gates: cargo check --workspace --all-targets, clippy --all --all-features --all-targets -D warnings, the wasm clippy gate, and fmt --check clean. Suites: iceberg lib 266, API lib 1074, grp_graphsource 161, grp_query 471, grp_query_history 64, grp_index 93, grp_export 225, grp_query_sparql 388, it_graph_source_r2rml 67, it_iceberg_policy 15, it_iceberg_local_fs 5, CLI, server.

Not covered by a test: the streaming execution core receives the same one-line pin push as the tested cores but has no pinned-graph-source case of its own; no end-to-end fixture has a renamed column (the reader names output columns from the task schema by field id, so the unit test covers the mapping).

Notes for review

  • Docs at this commit spell the timestamp selector @iso:; a follow-up PR (stacked) makes @time: the canonical spelling with @iso: as an alias, and rewrites these docs.
  • A deeper shape was considered and deferred: carrying the pin on the engine's GraphRef per view instead of a per-query side table on the provider, which would remove pin_source_time and the two-states refusal. Larger refactor across the query crate; the current shape is correct and tested.

Follow-up: #1906 — per-view pins, so one query can read a table at two snapshots (the aliased snapshot-diff shape is refused today).

  • Delta later: the same two selectors map onto Delta versions and commit timestamps; the contract here (typed errors, no fallback, one resolver for scan and count) is what that provider will implement.

A time specification on a graph-source alias now selects the Iceberg
snapshot the query reads. `@iso:` / `@recorded:` resolve to the state the
table presented at that instant — the latest snapshot-log entry at or
before it, Iceberg's own `TIMESTAMP AS OF` rule, so a rolled-back or
branch-only snapshot is never selected by time (it stays addressable by
id). The new `@snapshot:<id>` tag selects an exact snapshot and is rejected
on native ledgers. `@t:` and `@commit:` remain rejected on graph sources,
and so is any pin on a source that is not an Iceberg-backed table (SQL,
BM25, vector): those read their current state and would otherwise accept
the pin and ignore it.

Every table of the source is read at the selected snapshot for the whole
query, and the manifest COUNT shortcut selects through the same resolver as
the scan, so the two cannot disagree. One source read at two states in one
query — two pins, or pinned in one view and unpinned in another — is
refused rather than letting one pin decide for the other view. The
scan-files and count-stats caches are keyed by snapshot, so a historical
pin warms like the current snapshot.

A pin that no retained snapshot satisfies is a typed error (SnapshotNotFound
or the new NoSnapshotAtTime), never the current or oldest snapshot; a table
with no snapshots reads as empty unpinned and errors when pinned. The
default `R2rmlTableProvider::pin_source_time` refuses, so a provider that
cannot honor a pin cannot let the query run against its current state.

Before this, the `from`-driven route rejected any time spec on a graph
source while the lazy `graph_at()` handle's graph-source fallback dropped
the pin and silently answered from the latest snapshot; the MCP
`sparql_query` tool reached that path when re-sending the envelope's `t`.
Graph-source results now carry no `t` on either the plain or tracked
route, since the genesis view's 0 named no state a client could pin to.

Both routes now build the view through one resolver, and the three
hand-copied ledger time-spec resolvers collapse onto `resolve_time_spec`.

The Iceberg docs described `@snapshot:` / `@timestamp:` selectors that the
grammar never accepted; they now describe the implemented syntax and its
failure modes.
@bplatz bplatz added enhancement New feature or request area:iceberg Iceberg catalogs/credentials, R2RML, virtual datasets, materialize labels Sep 19, 2026
@bplatz
bplatz requested review from aaj3f and zonotope September 19, 2026 14:06
@bplatz
bplatz added this pull request to stack #1898 September 19, 2026 14:14
`fluree query <graph-source> --at …` was refused outright by a guard written
when a graph source could only be read at its live state. Iceberg sources now
take `snapshot:` and `iso:` pins, but the CLI had no way to send one: the
guard rejected `--at`, and a `FROM <alias@…>` naming the target itself stays
on the single-source path, which refuses FROM.

The local graph-source path now resolves the target through `graph_at` with
the parsed spec. The API already decides which selectors a source honors and
refuses the rest (`t:`, `commit:`, or any pin on a source without history)
with its own error, so the CLI guard only keeps the flags the path genuinely
cannot serve: `--explain` and the streaming/delimited formats.

A binary-level test maps the committed two-snapshot Iceberg fixture and
checks the unpinned count (5), the count at its first snapshot (3), an
unknown snapshot id and a `t:` pin. It fails against the old guard.

@aaj3f aaj3f left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, @bplatz, and no notes on the "problem/issue --> design". The one thing aside from the full review below that I'd spotlight is that it does seem to me that, while generally we're extending our previous pattern for time travel, etc, in this case the graph-source pins seem to be per-query, per-source and so aren't carried on the engine's GraphRef per-view. I think the only consequence of that is that it refuses w/ an error on something like a "diff this between two snapshot times" (e.g. it refuses if using two aliased fromNamed views of the same table at different snapshots). Could easily be a follow-up issue, since your code here at least presents a refusal rather than a silent incorrect result. Just wanted to name it clearly just in case


This is a really nice piece of work, @bplatz — the pin extends the one address grammar rather than growing a graph-source dialect, scan and COUNT select through one resolver, the refusing default on pin_source_time is the right contract to hand #1899, and the snapshot-log as-of rule is more correct than what we had. There are two things I'd like to see before merge. First, on REST catalogs load_table_context still passes None as the pointer rider (graph_source/r2rml.rs:3155) and consults the 60 s loadTable cache without regard to the pin, so a pin to a recent instant can silently read an older snapshot, and a just-committed @snapshot: id can be refused. The r2rml-as-of-t breadcrumb there says in so many words that this PR has to thread the pin through, and the rider already exists. Second, the new user-error refusals (@t:/@commit: on a graph source, @snapshot: on a ledger, a non-Iceberg pin, a malformed timestamp) come back as 500 because ApiError::query is an Internal — so the "now a 400" line in the body doesn't hold, and the refusals are split 400/500 depending on which constructor built them.

Adherence to repo commitments:

  • Patterns/abstractions: ✔ Extends parse_time_travel_spec / TIME_TRAVEL_TAGS and the R2rmlTableProvider trait; collapses three hand-copied resolvers onto resolve_time_spec; no parallel parser.
  • Performance (speed first, memory second): ✔ No hot-path change — per-query view iteration and per-table-scan lock/allocation only; historical snapshots get their own cache keys, so pinned reads warm normally. No performance-degradation risk.
  • Testing: ⚠️ Strong integration and unit coverage across JSON-LD/SPARQL/graph_at, green in CI with the new tests visible by name; but the tracked cores are unguarded (mutating their pin push away leaves the suite green), and nothing exercises the REST metadata-cache path.
  • Conventions: ⚠️ Thorough multi-line commits and docs updated (Iceberg, time-travel concept, CLI); the refusal status codes don't match the body's claim.

Verified locally at 21d49741: it_iceberg_local_fs (PR test passes), iceberg snapshot unit tests 15/15, core ledger_id 11/11; probes for named-graph pins, tracked routes, offsets/future instants and per-refusal status codes; a tracked-core mutation that the suite does not catch. CI's test job ran all 13 023 tests with --all-features, green.

Just be sure to thread the pin into load_table_context's cache lookups and move the four refusals onto a 400-mapped error before this merges. The rest are small and yours to take or leave, though I'd fold in the tracked-route test while you're there.

}
})?)
}
Some(SourceTime::AsOfTimestampMs(ms)) => Some(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fluree-db-api/src/graph_source/r2rml.rs:3146-3155 — Blocking — a pinned read on a REST-catalog source can resolve against stale metadata, and the code already says it must not. The real location is load_table_context, graph_source/r2rml.rs:3146-3155 (and resolve_rest_load_and_storage, :2784-2789), which this diff doesn't touch.

select_snapshot here is only as good as the TableMetadata it's handed, and on a REST catalog that metadata comes through two cross-query layers that don't know the query is pinned: the persisted lt_key → metadata_location pointer (disk.get_metadata_location(&lt_key, None), TTL 300 s, on by default) and then the in-memory loadTable cache (cache.get_rest_load_table(&lt_key), TTL 60 s). The comment right above the pointer lookup spells out the contract — "GREP: r2rml-as-of-t — when Iceberg snapshot time-travel lands, the requested snapshot's timestamp_ms MUST be threaded here as min_snapshot_ms so bounded staleness can never downgrade a time-travel request" — and disk_catalog_cache::pointer_is_usable already implements that rider. This PR updated the two sibling r2rml-as-of-t breadcrumbs in table_row_count_inner and scan_table_inner, but not this one, so the rider is still passed None.

Concretely: a table commits snapshot S2 at 12:00:10; a query at 12:00:05 had cached the pointer/loadTable response with S1 current. For the next 60–300 s, alias@iso:2026-…T12:00:20Z resolves against S1-era metadata and silently returns S1 (the docs say it returns "the snapshot that was the table's current state at that instant", which is S2), and alias@snapshot:<S2> is refused as SnapshotNotFound even though the catalog has it. It bites exactly the "pin to just now" pattern — e.g. the agent-JSON pagination hint, which tells agents to re-issue with @iso:<now> on each FROM. Direct mode has the same shape with a 2 s TTL (DIRECT_METADATA_LOCATION_TTL), which is probably fine to leave. The same call sites are unchanged through #1902.

Suggested fix, all inside load_table_context since self.source_time(graph_source_id) is in scope there: for SourceTime::AsOfTimestampMs(ms) pass Some(ms) to get_metadata_location, and apply the same rider to the in-memory loadTable hit (skip it when the cached response's current snapshot is older than ms); for SourceTime::SnapshotId(id), when the id isn't in cached metadata, reload once without the cross-query layers before returning SnapshotNotFound. Then point the breadcrumb at whatever you land. pointer_ttl_and_as_of_rider already covers the pure rider logic, so the new test mostly needs to prove the call site passes the pin.

Commenting here because load_table_context (fluree-db-api/src/graph_source/r2rml.rs:3146-3155) is not in this diff.

@bplatz bplatz Sep 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 901c385

Comment thread fluree-db-api/src/graph_source/mod.rs Outdated
Ok(Some(SourceTime::AsOfTimestampMs(dt.timestamp_millis())))
}
crate::TimeSpec::AtT(_) | crate::TimeSpec::AtCommit(_) => {
Err(crate::ApiError::query(GRAPH_SOURCE_LEDGER_TIME_UNSUPPORTED))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking (small) — the new user-facing refusals come back as HTTP 500, and the body's "malformed timestamp is now a 400" doesn't hold. ApiError::query(msg) builds ApiError::Internal("Query error: …") (fluree-db-api/src/error.rs:560-562), which is 500 in ApiError::status_code() and in the server's ServerError::status_code() (fluree-db-server/src/error.rs:358). That constructor predates this PR, but this PR routes its new refusals through it.

I probed these through query_from() and read status_code(): @t: / @commit: on a graph source → 500 (this line), @snapshot: on a ledger → 500 (time_resolve.rs:454), and a malformed @iso: on a ledger → 500 (time_resolve::parse_time_travel_iso). The pin-on-a-non-Iceberg-source refusal (view/fluree_ext.rs:756) goes through the same constructor, so it's a 500 too (I didn't probe that one's status separately). Meanwhile the refusals this PR builds as QueryError — SnapshotNotFound, NoSnapshotAtTime, and the two-states InvalidQuery — are 400. So two users who both typed a bad pin get a 400 and a 500 respectively, and a client that retries 5xx (or an operator watching err:system/InternalError) reads a user typo as a server fault.

Minimally, build these four as ApiError::Query(QueryError::InvalidQuery(..)), the same way pin_graph_source_times builds the two-states refusal, and add a status_code() == 400 assertion to the refused-pin loop in the test. Retargeting ApiError::query itself to a 400 variant is the more general fix, but it has a lot of callers, so that one's a judgment call.

@bplatz bplatz Sep 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 901c385

@bplatz bplatz Sep 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dataset-spec parse errors (malformed from / FROM) addressed in 1fd59c5 (#1897). Follow-up: #1908 for auditing the remaining ApiError::query callers.

// aggregated across every graph the dataset can read.
tracker.record_policy_enforcement(dataset.policy_enforcement());

crate::graph_source::pin_graph_source_times(dataset.views(), r2rml.table_provider)?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional — the tracked cores' pin push has no test of its own.

The body is upfront that the tracked and streaming cores have no pinned case of their own, and I think we should just fold that in here, because the dataset tracked core is the production path for any request with tracking headers (fluree-db-server/src/routes/query.rs:708-718 → query_from()…execute_tracked()). I commented out the pin push on both tracked cores (this line and view/query.rs:1887): pinned_query_on_a_graph_source_reads_that_snapshot still passes, and a pinned query_from().jsonld(..).track_all().execute_tracked() silently returns all 5 rows. Since the refusing default only fires when the push happens, forgetting a push anywhere is a silent-current read, which is the failure this PR is about.

A tracked leg in the honored-pins loop (both query_from() and graph_at(), each .track_all().execute_tracked() and assert 3 rows) catches 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.

@bplatz bplatz Sep 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 901c385

continue;
};
match times.insert(gs_id, view.graph_source_time) {
Some(prior) if prior != view.graph_source_time => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question (decision-needed) — the one-state-per-source rule also refuses aliased snapshot-diff queries.

This is more of a question than a suggestion. The "one source, one state per query" rule also refuses two aliased named views of the same table, e.g. fromNamed: [{"@id": "orders@snapshot:A", "alias": "old"}, {"@id": "orders", "alias": "new"}] (probed: 400, "read at two different states"). That's the "what changed in this table between two snapshots" query, and it's the one natively available for ledgers (two fromNamed at different @t:), so graph sources and ledgers now differ in what time travel can express. It's loud rather than wrong, and the body already names the per-view GraphRef pin as deferred, so I don't think it belongs in this PR — but it's a cross-crate refactor that shapes the product story for lakehouse time travel (and Delta inherits the same limitation in #1899), so it seems worth an explicit call on whether and when we want it, rather than letting it stand by default.

@bplatz bplatz Sep 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up: #1906

Comment thread fluree-db-api/src/graph_source/r2rml.rs Outdated
// names resolve to field ids as they were at that snapshot.
let schema = metadata
.current_schema()
.schema_for_snapshot(snapshot)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional (design) — a column renamed since the pin is dropped silently rather than refused.

I may be wrong about the intended semantics here, but it seems the "a column renamed since the pin won't resolve" limitation fails silently rather than loudly. Names resolve against the pinned schema here, and then projection.iter().filter_map(|col_name| schema.field_by_name(col_name)…) (:3674) drops any name that isn't there, erroring only when every projected name is missing. So after a rename, a pinned query returns the rows with that property missing and no error, which runs against the PR's "never silently" contract.

Since Iceberg field ids are stable across renames, resolving the current mapping's column names through the current schema (name → field id) and reading those ids from the pinned snapshot's files would make renames just work; columns added after the pin would read as absent, which is the correct historical answer. The one case that reads differently is a column dropped and re-added under the same name. If you'd rather keep pinned-schema resolution, the cheap alternative is to refuse a pinned read when a mapped column doesn't resolve. I didn't build a renamed-column fixture, so this is traced rather than observed. It's minor — but if you agree it's right, I'd rather see it in this PR than lost in the backlog.

@bplatz bplatz Sep 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 901c385

None => "latest".to_string(),
Some(fluree_db_query::r2rml::SourceTime::SnapshotId(id)) => format!("@snapshot:{id}"),
Some(fluree_db_query::r2rml::SourceTime::AsOfTimestampMs(ms)) => {
format!("@time:{}", crate::time_resolve::epoch_ms_to_iso(ms))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit — @time: appears in user-facing text before #1897 makes it parse.

describe_source_time renders @time:…, and the CLI doc comment on reject_graph_source_unsupported (fluree-db-cli/src/commands/query.rs:1726-1727) names time:, but time: doesn't parse until #1897 (probed: at this commit the two-states error tells the user @time:2999-…, and @time: itself is rejected). This only matters if #1896 ships without #1897 — if the stack lands together, feel free to ignore.

@bplatz bplatz Sep 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving as is: #1897 merges right behind this, so @time: parses before a release sees it.

/// rather than read the live tables. View construction already refuses a
/// pin on a non-Iceberg source, so this only guards the provider itself.
#[cfg(feature = "sql")]
fn refuse_pin_on_sql_source(&self, graph_source_id: &str) -> QueryResult<()> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit — refuse_pin_on_sql_source doesn't cover the SQL lane's pushed-plan path.

refuse_pin_on_sql_source guards scan_table_inner and table_row_count_inner, but not execute_plan / source_schema (:2519), which is the path the SQL lane uses for pushed-down plans. It's unreachable today because resolve_graph_source_at refuses GraphSourceType::Sql before a pin exists, and the comment says this is only the provider guarding itself. But if it's defense-in-depth, it's cheap to make it cover all the SQL entry points. Minor, and fine to fold in or not.

// the latest-committed retained snapshot: a rolled-back or branch
// snapshot is retained but was never (or is no longer) the table's
// state, and `snapshots` alone cannot tell the two apart.
main_lineage(metadata)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Praise — resolving as-of against the snapshot log (with current-ancestry fallback) rather than max-timestamp over retained snapshots is the right rule, and it quietly fixes the old select_snapshot, which would have returned a rolled-back snapshot. The two unit tests pin exactly the rollback and orphaned-branch cases.

/// provider then selects that state in `scan_table` and `table_row_count`
/// alike. The default REFUSES: a provider that cannot honor a pin must not
/// let the query proceed against its current state.
fn pin_source_time(&self, graph_source_id: &str, time: SourceTime) -> Result<()> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Praise — a refusing default for pin_source_time is the right shape for a trait other providers will implement; #1899's Delta provider picks up the contract as-is.

/// and a COUNT is checked against its scan so the manifest shortcut cannot
/// answer from a different snapshot than the rows.
#[tokio::test]
async fn pinned_query_on_a_graph_source_reads_that_snapshot() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Praise — using the 3-then-5-row fixture so a dropped pin can't pass by accident, and running every honored and refused pin through JSON-LD from, SPARQL FROM, and graph_at() (plus the COUNT shortcut), is exactly the parity coverage this needed.

…als are 400s

A time pin on a REST-catalog source could be answered by cross-query
caches that predate it: the disk metadata pointer was consulted without
the as-of rider, and the in-memory loadTable cache without any check. A
pin to a recent instant could read an older snapshot, and a just-committed
@snapshot: id could be refused, for up to the caches' TTLs.

- The disk pointer takes the as-of instant as its min_snapshot_ms rider,
  and its metadata is used only when it can answer the pin (the snapshot
  id is listed, or the current snapshot is at or after the instant).
- A time-pinned query skips the in-memory loadTable cache: it carries only
  a location, so whether it is new enough can't be checked.

The user-error refusals added with graph-source pinning (@t:/@commit: on
a graph source, @snapshot: on a ledger, a pin on a non-Iceberg source, a
malformed timestamp) were built with ApiError::query, which is an
Internal 500. They are now InvalidQuery 400s via ApiError::invalid_query.

A pinned read resolves the current mapping's column names through field
ids: the pinned snapshot's schema is read under current names, so a column
renamed since the pin resolves instead of silently dropping out, and one
added since reads as absent.

Tests: a REST load_table_context test covering both cache layers; tracked
legs (single-view and dataset cores) and a 400 assertion on every refusal
in the pinned graph-source test; a read_schema unit test. Each was checked
to fail with its fix reverted.
@bplatz
bplatz merged commit 0d29a71 into main Sep 22, 2026
16 checks passed
@bplatz
bplatz deleted the feat/iceberg-snapshot-time-travel branch September 22, 2026 20:41
aaj3f added a commit that referenced this pull request Oct 8, 2026
Brings the Glue / S3 Tables catalog modes up to main (2,900 commits since
the 2026-07-06 merge-base) and re-threads them through main's current
Iceberg architecture rather than beside it.

Conflicts:
- Cargo.lock: main's lock, re-resolved with aws-sdk-glue 1.142.1 and
  aws-sdk-s3tables 1.54.0, the newest releases compatible with main's locked
  smithy runtime. The lock only gains those two packages; the PR's
  1.153.0 / 1.59.0 forced the shared AWS runtime (smithy-runtime, sigv4,
  aws-runtime) up under the HTTP/1.1-pinned S3 read path.
- Cargo.toml manifests, cli.rs, docs/graph-sources/iceberg.md: both sides.
- r2rml.rs, iceberg_catalog.rs: resolved by the re-threading below.

Re-threaded onto main's patterns:
- One loadTable ladder. main's REST ladder (per-query pin, cross-query
  cache, disk pointer rung, deferred LazyS3Storage, the #1896 time-pin
  guard, the section 2 fail-closed storage decision) now runs over
  Arc<dyn SendCatalogClient> for REST, Glue and S3 Tables
  (resolve_catalog_load_and_storage, catalog_session_storage). The PR's
  separate sdk_resolve_load_table copy, which predated the time-pin guard,
  is gone.
- One process-wide catalog-client cache (R2rmlCache::catalog_clients,
  shared_catalog_client); Glue/S3 Tables clients are no longer rebuilt on
  every cache miss. A disk-pointer hit on a non-vending catalog builds its
  ambient storage without calling the catalog.
- prepare_iceberg_scan (incremental / materialize) and ledger_info (/info
  catalog object) gained the arms main's new code needs.
- Onboarding: rest_catalog_client becomes async catalog_client for all five
  callers (browse, preview, sample, storage verify, provisional query);
  metadata is read from metadata_location when a catalog returns none
  inline (load_response_metadata).
- IcebergCreateConfig::to_iceberg_gs_config builds one IcebergGsConfig after
  the per-mode match, so delete / order_by / model / default_allow (added on
  main) cannot be dropped for a mode.
- One catalog-mode dispatch for the CLI and both server builders
  (IcebergConnectionConfig::from_mode / IcebergCreateConfig::from_mode,
  CatalogModeError rendered per surface). glue / s3tables take --table only
  when no --r2rml mapping names the tables, as rest does.
- One validation: the API delegates Glue/S3 Tables rules to
  CatalogConfig::validate_aws_sdk_catalog.

Review follow-ups (bplatz, 2026-07-07):
- Glue / S3 Tables listings page through every result.
- One region resolution (catalog call: region, then s3_region, then the SDK
  chain, S3 Tables using the ARN's region; S3 reads: s3_region, then the
  catalog's region), shared by the query and onboarding paths.

Also:
- SDK errors carry their source chain (not "service error"); not-found
  becomes TableNotFound, access-denied becomes the new
  IcebergError::CatalogAccessDenied, lifted to err:catalog/AccessDenied
  (403) on the eager and deferred paths.
- Glue browse lists only Iceberg tables.
- glue / s3tables refuse vended_credentials = true (as Direct does),
  refuse a region that is not an AWS region code (it becomes part of a
  hostname), and parse the S3 Tables ARN (all partitions) and refuse a
  region that contradicts it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:iceberg Iceberg catalogs/credentials, R2RML, virtual datasets, materialize enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants