Skip to content

(CLI) Route Queries Targeting Iceberg/R2RML Graph Sources - #1404

Merged
aaj3f merged 1 commit into
mainfrom
fix/cli-graph-source-query
Jun 30, 2026
Merged

aaj3f merged 1 commit into
mainfrom
fix/cli-graph-source-query

Conversation

@aaj3f

@aaj3f aaj3f commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Summary

fluree query <name> could only resolve native ledgers:
context.rs::resolve_ledger_mode had no notion of a registered Iceberg/R2RML
graph source, so querying one from the CLI failed even though the source was
registered and the server could serve it. This PR teaches the CLI to resolve a
graph-source name and route the query to the graph-source-aware execution path
(local single-target, or the connection path for FROM-federation).

What changed

  • fluree-db-cli/src/context.rs — the body of resolve_ledger_mode is
    refactored into resolve_query_target returning a QueryTarget { Ledger | GraphSource }.
    A lookup_graph_source probe runs after the native-ledger check
    (ledger-wins), normalizing the bare name to <name>:main, preferring a local
    registration, and skipping retracted sources. resolve_ledger_mode becomes a
    thin wrapper that maps a graph-source name to a clear NotFound for the ~10
    other commands that still only handle ledgers (no behavior change for real
    ledger names). The graph-source probe is error-tolerant: a graph-source-store
    read error is debug-logged and treated as "not a graph source" (fall through),
    so it cannot break native-ledger resolution for the commands that call
    resolve_ledger_mode.
  • fluree-db-cli/src/commands/query.rs — graph-source execution:
    • Implicit fluree query <graph-source> runs locally via
      fluree.graph(alias).query()…execute_formatted() (gated on the iceberg
      feature; a clear "rebuild with --features iceberg" message otherwise).
    • A query whose FROM / from references a foreign graph source
      auto-routes to the connection path — query_from (local) or
      query_connection_sparql / query_connection_jsonld (remote), wiring methods
      that were previously unreachable.
    • A bare --connection federation query does not require an active native
      ledger: when no ledger is active/provided, the local connection path falls back
      to a bare Fluree handle (symmetric with the --connection=REMOTE arm), since
      the query's FROM already names its sources. A normal fluree query with no
      ledger still errors NoActiveLedger (the relaxation is gated on the connection
      path), and a provided ledger still resolves normally.
    • Guardrails reject flags unsupported on the graph-source single-target path with
      a clear message.
  • fluree-db-cli/src/cli.rs — adds --connection[=REMOTE] to the Query
    command only, using require_equals so a bare --connection forces the
    connection path while --connection=REMOTE targets a named remote (and neither
    swallows the following positional query string).
  • fluree-db-cli/src/lib.rs — threads connection into query::run.
  • docs/cli/iceberg.md — fixes the broken example at line 160 (single-target
    form + a --connection federation example; and fluree info <gs> →
    fluree iceberg info <gs>, since bare info on a graph-source name now returns
    the clear graph-source error).

Design decisions (intentional deviations from #1398's literal wording)

  1. QueryTarget enum instead of a new LedgerMode variant. ~10 command files
    exhaustively match LedgerMode::{Local,Tracked}; adding a variant/field there
    would break all of them. The probe still lives in context.rs (per the issue's
    critical-files list) and query behavior is exactly as specified; other commands
    simply get a clearer error for a graph-source name.
  2. --connection[=REMOTE] with require_equals resolves the issue's ambiguous
    "positional optional" and prevents the flag from eating the query string.
  3. Implicit fluree query <gs> executes locally (graph().query()), matching
    the issue's primary "execute locally" design; server-routed forms remain
    reachable via --remote / --connection.
  4. --policy / --track are not plumbed into the graph-source single-target
    path — consistent with the server's graph-source fallback, which doesn't apply
    them either. Noted as a minor limitation, not a silent surprise.
  5. No live-rows E2E test — a queryable Iceberg/R2RML source needs a live
    catalog (the issue itself defers that). Covered instead by a real
    graph-source resolution test plus deterministic unit tests of every routing
    decision.

Tests

context::tests (register a real graph source via the nameservice publisher — no
live catalog):

  • resolves_registered_graph_source_to_graph_source_target
  • ledger_only_resolution_reports_graph_source_as_clear_error
  • missing_target_still_reports_not_found

commands::query::tests:

  • base_ledger_id_strips_branch_time_and_fragment
  • jsonld_from_targets_handles_string_and_array
  • foreign_source_detection_sparql, foreign_source_detection_jsonld
  • graph_source_guardrails_reject_unsupported_flags
  • json_display_format_falls_back_for_jsonld

tests/integration.rs:

  • query_connection_remote_routes_to_named_remote
  • query_bare_connection_keeps_positional_query
  • query_bare_connection_without_active_ledger_routes_to_connection_path — bare
    --connection with no active ledger routes onward instead of erroring
    NoActiveLedger.

Results

  • cargo build -p fluree-db-cli --features iceberg — success.
  • cargo test -p fluree-db-cli --features iceberg — 110 lib + 102 integration
    passed, 0 failed.
  • cargo clippy -p fluree-db-cli --all-targets --features iceberg — zero warnings.
  • cargo fmt -p fluree-db-cli -- --check — clean.
  • cargo build -p fluree-db-cli --no-default-features --features "server,shacl,aws"
    (non-iceberg path) — success (exercises the cfg(not(feature="iceberg"))
    rebuild-message branch).

Fixes #1398

`fluree query <graph-source>` previously failed with "ledger not found":
resolve_ledger_mode only probed native ledgers (a nameservice `lookup`), so a
registered Iceberg/R2RML graph source — keyed separately in the nameservice —
was never found and erred before any routing.

Refactor the resolver into `resolve_query_target`, returning a new `QueryTarget`
enum (Ledger | GraphSource). After the native-ledger check it probes
`lookup_graph_source`; a non-retracted hit resolves to a graph-source target
(alias normalized to `<name>:main`), winning over a tracked remote of the same
name. A probe read error is treated as "not a graph source" so it can't break
ledger resolution for the other commands. `resolve_ledger_mode` stays a thin
wrapper for every other command, now reporting a graph-source name with a clear
"use fluree query" error instead of the generic not-found — so `LedgerMode` is
unchanged and no other command files are touched.

In the query command:
- A graph-source single target executes locally through the R2RML-aware
  `graph().query()` builder (mirrors the server's `POST /query/<graph-source>`),
  gated on the `iceberg` feature with a clear rebuild message otherwise.
- A query whose FROM/from references a source other than the endpoint
  auto-routes to the connection-scoped path (`query_from()` locally,
  `query_connection_sparql/jsonld` remotely — previously dead code); a plain
  same-endpoint query is unaffected.
- New `--connection[=REMOTE]` flag forces the connection path explicitly. Bare
  `--connection` (a pure-federation query naming its sources in FROM) needs no
  active ledger.
- Graph-source targets reject `--at`, `--explain`, and ndjson/csv/tsv up front,
  mirroring the server's restrictions.

Fix the broken federated example in docs/cli/iceberg.md to the single-target
form, alongside a `--connection` federation example.

Refs #1398
@aaj3f
aaj3f requested a review from bplatz June 30, 2026 20:13

@bplatz bplatz 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.

🖱️

@aaj3f
aaj3f merged commit ae24a9e into main Jun 30, 2026
13 checks passed
@aaj3f
aaj3f deleted the fix/cli-graph-source-query branch June 30, 2026 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants