Skip to content

CLI cannot query a registered Iceberg/R2RML graph source (fluree query <graph-source> → "ledger not found") #1398

Closed

Description

@aaj3f

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_view rejects 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 and base_ledger_id not 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/query with
    Content-Type: application/sparql-query + inline FROM <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 --remote branch bypasses resolve_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, after ledger_exists fails, probe
    nameservice().lookup_graph_source(&id); on hit, mark a graph-source target and
    execute locally via resolve_graph_source(&alias) + the R2RML-aware
    GraphSnapshotQueryBuilder…with_r2rml() (server already supports the routed form).
    Normalize the alias to <name>:main for 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-present query_connection_sparql/jsonld (Tracked) or
    query_from() (Local). Gate on "references a target other than the endpoint" so
    existing same-ledger FROM <self:main> is unaffected.
  • (c) --connection flag to force the connection path explicitly (positional
    optional).
  • Docs: fix docs/cli/iceberg.md:160 to 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|tsv for
    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 in resolve_ledger_mode; alias normalization)
  • fluree-db-cli/src/commands/query.rs (single-target via with_r2rml; federation auto-route; guardrails)
  • fluree-db-cli/src/cli.rs + lib.rs (--connection, optional positional)
  • fluree-db-cli/src/remote_client.rs (wire query_connection_sparql/jsonld)
  • docs/cli/iceberg.md (fix the :160 example)

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions