Repository navigation
Description
Summary
A registered Iceberg/R2RML graph source can be created (fluree iceberg map) and
listed (fluree iceberg list) but cannot be queried via the implicit fluree query path. fluree query <graph-source>[:main] returns "ledger not found", and
GRAPH/FROM references to the source from inside a native-ledger query don't
federate to it. Only the connection-scoped HTTP endpoint (POST /v1/fluree/query
with an inline FROM) or the explicit --remote path reach it.
Root cause
fluree query <target> resolves the target via resolve_ledger_mode
(fluree-db-cli/src/context.rs:56-120), which uses ledger_exists
(fluree-db-api/src/lib.rs:3769-3771 = nameservice().lookup(...)) — native
ledgers only. Graph sources live under a separate key
(lookup_graph_source / resolve_graph_source). So a graph-source name fails the
ledger_exists check and returns NotFound before any server routing.
Federation from the ledger path also can't reach a graph source:
- direct-local +
FROM→validate_sparql_for_viewrejects FROM on a single-ledger GraphDb (view/query.rs:546-566); - server-routed +
FROM→ ledger-scoped/query/<alias>requires every FROM base == endpoint base → "Ledger mismatch" (routes/query.rs:2277-2378), compounded by the CLI sending the un-normalized alias andbase_ledger_idnot stripping:branch; - server-routed +
GRAPH <gs:main>(no FROM) → treated as a named graph within the endpoint ledger → resolves empty (0 rows).
What already works (narrows the fix)
- The connection-scoped endpoint works:
POST /v1/fluree/querywith
Content-Type: application/sparql-query+ inlineFROM <gs:main>executes via
query_from()/query_connection_sparql, which auto-attach the R2RML provider. - The server's ledger-scoped endpoint already resolves a graph-source-named
target itself:POST /query/<graph-source>with a no-FROM body works
(routes/query.rs:2037-2059, 2853-2897→state.fluree.graph(id).query()). - Therefore
fluree query --remote <origin> <graph-source> -e '<no-FROM sparql>'
already works today — the--remotebranch bypassesresolve_ledger_mode. Only
the implicit (non---remote) path is broken. - The CLI remote client already has
query_connection_sparql/
query_connection_jsonld(remote_client.rs:925-952) — currently dead code. - The documented federated example at
docs/cli/iceberg.md:160
(fluree query mydb 'SELECT … FROM <mydb:main> WHERE { GRAPH <gs:main> {…} }') is
broken as written and should be corrected.
Design / fix (almost entirely CLI; ~zero server change)
- (a) Resolve graph-source targets → single-target path. In
resolve_ledger_mode, afterledger_existsfails, probe
nameservice().lookup_graph_source(&id); on hit, mark a graph-source target and
execute locally viaresolve_graph_source(&alias)+ the R2RML-aware
GraphSnapshotQueryBuilder…with_r2rml()(server already supports the routed form).
Normalize the alias to<name>:mainfor routing. - (b) Auto-route federation. When the query body carries
FROM/from(or FROM
NAMED) referencing a source other than the endpoint, route to the connection-scoped
path — wiring the already-presentquery_connection_sparql/jsonld(Tracked) or
query_from()(Local). Gate on "references a target other than the endpoint" so
existing same-ledgerFROM <self:main>is unaffected. - (c)
--connectionflag to force the connection path explicitly (positional
optional). - Docs: fix
docs/cli/iceberg.md:160to the single-target form; keep
docs/graph-sources/iceberg.md(fluree.graph(...).query()/query_from()) as
the API source of truth. - Guardrails: reject
--at/--explain/--format ndjson|csv|tsvfor
graph-source targets up front (mirrors the server's own restrictions), with clear
messages.
Tests
CLI integration (fluree-db-cli/tests/integration.rs, build --features iceberg):
fluree query <gs> resolves (no NotFound); local single-target SPARQL + JSON-LD
return rows; federation auto-route no longer errors with "single-ledger"/"Ledger
mismatch"; --connection forces the path; guardrails error clearly; native-ledger
queries / NDJSON / default-context tests stay green. Add a server route test that
POST /query/<graph-source> (no FROM) returns rows (codifies the dependency).
Risk / compat
Backward compat preserved: the new branch is reached only when ledger_exists is
false and lookup_graph_source succeeds — a path that previously always errored.
Local graph-source query requires the CLI built --features iceberg (give a clear
"rebuild with --features iceberg" message otherwise); --remote/server-routed paths
need no CLI feature. Split-storage server-only sources won't be seen by the local
probe — documented limitation, --remote is the workaround.
Critical files
fluree-db-cli/src/context.rs(graph-source probe inresolve_ledger_mode; alias normalization)fluree-db-cli/src/commands/query.rs(single-target viawith_r2rml; federation auto-route; guardrails)fluree-db-cli/src/cli.rs+lib.rs(--connection, optional positional)fluree-db-cli/src/remote_client.rs(wirequery_connection_sparql/jsonld)docs/cli/iceberg.md(fix the:160example)
Stacking
Part of the fluree/db ↔ Snowflake-managed-Iceberg consumption series (see #1394).
No hard code dependency on the others, but its E2E test wants a creatable +
scannable source → land after the create/scan fixes (PR-6). Size M (CLI
routing + LedgerMode plumbing; server changes none, or one optional hardening to
make base_ledger_id branch-insensitive).
Context: surfaced trying to query a live Snowflake-managed Iceberg star schema
registered as a fluree/db R2RML graph source.
Activity
fix(cli): route queries targeting Iceberg/R2RML graph sources