Repository navigation
(CLI) Route Queries Targeting Iceberg/R2RML Graph Sources - #1404
Merged
Merged
Conversation
`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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
fluree query <name>could only resolve native ledgers:context.rs::resolve_ledger_modehad no notion of a registered Iceberg/R2RMLgraph 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 ofresolve_ledger_modeisrefactored into
resolve_query_targetreturning aQueryTarget { Ledger | GraphSource }.A
lookup_graph_sourceprobe runs after the native-ledger check(ledger-wins), normalizing the bare name to
<name>:main, preferring a localregistration, and skipping retracted sources.
resolve_ledger_modebecomes athin wrapper that maps a graph-source name to a clear
NotFoundfor the ~10other 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:fluree query <graph-source>runs locally viafluree.graph(alias).query()…execute_formatted()(gated on theicebergfeature; a clear "rebuild with
--features iceberg" message otherwise).FROM/fromreferences a foreign graph sourceauto-routes to the connection path —
query_from(local) orquery_connection_sparql/query_connection_jsonld(remote), wiring methodsthat were previously unreachable.
--connectionfederation query does not require an active nativeledger: when no ledger is active/provided, the local connection path falls back
to a bare
Flureehandle (symmetric with the--connection=REMOTEarm), sincethe query's
FROMalready names its sources. A normalfluree querywith noledger still errors
NoActiveLedger(the relaxation is gated on the connectionpath), and a provided ledger still resolves normally.
a clear message.
fluree-db-cli/src/cli.rs— adds--connection[=REMOTE]to the Querycommand only, using
require_equalsso a bare--connectionforces theconnection path while
--connection=REMOTEtargets a named remote (and neitherswallows the following positional query string).
fluree-db-cli/src/lib.rs— threadsconnectionintoquery::run.docs/cli/iceberg.md— fixes the broken example at line 160 (single-targetform + a
--connectionfederation example; andfluree info <gs>→fluree iceberg info <gs>, since bareinfoon a graph-source name now returnsthe clear graph-source error).
Design decisions (intentional deviations from #1398's literal wording)
QueryTargetenum instead of a newLedgerModevariant. ~10 command filesexhaustively match
LedgerMode::{Local,Tracked}; adding a variant/field therewould break all of them. The probe still lives in
context.rs(per the issue'scritical-files list) and query behavior is exactly as specified; other commands
simply get a clearer error for a graph-source name.
--connection[=REMOTE]withrequire_equalsresolves the issue's ambiguous"positional optional" and prevents the flag from eating the query string.
fluree query <gs>executes locally (graph().query()), matchingthe issue's primary "execute locally" design; server-routed forms remain
reachable via
--remote/--connection.--policy/--trackare not plumbed into the graph-source single-targetpath — consistent with the server's graph-source fallback, which doesn't apply
them either. Noted as a minor limitation, not a silent surprise.
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 — nolive catalog):
resolves_registered_graph_source_to_graph_source_targetledger_only_resolution_reports_graph_source_as_clear_errormissing_target_still_reports_not_foundcommands::query::tests:base_ledger_id_strips_branch_time_and_fragmentjsonld_from_targets_handles_string_and_arrayforeign_source_detection_sparql,foreign_source_detection_jsonldgraph_source_guardrails_reject_unsupported_flagsjson_display_format_falls_back_for_jsonldtests/integration.rs:query_connection_remote_routes_to_named_remotequery_bare_connection_keeps_positional_queryquery_bare_connection_without_active_ledger_routes_to_connection_path— bare--connectionwith no active ledger routes onward instead of erroringNoActiveLedger.Results
cargo build -p fluree-db-cli --features iceberg— success.cargo test -p fluree-db-cli --features iceberg— 110 lib + 102 integrationpassed, 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