Skip to content

feat(cli): iceberg map can name a catalog connection and mapping the remote stores - #2257

Merged
aaj3f merged 4 commits into
mainfrom
feat/cli-iceberg-map-stored-refs
Nov 11, 2026
Merged

aaj3f merged 4 commits into
mainfrom
feat/cli-iceberg-map-stored-refs

Conversation

@aaj3f

@aaj3f aaj3f commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Builds on #2190 (merged), which makes a mapping required for every Iceberg graph source: a map now names one either as a file (--r2rml) or as a mapping the remote stores (--stored-mapping).

Some remotes keep connected catalogs and saved R2RML mappings server-side under their own ids. fluree iceberg map --remote <R> can now name them instead of restating them:

fluree iceberg map orders --remote origin --stored-mapping <MAPPING-ID>
fluree iceberg map orders --remote origin --stored-catalog <CATALOG-ID> --r2rml mappings/orders.ttl --table sales.orders

The request carries stored_catalog_id / stored_mapping_id, the source's own options (table, branch, model, default_allow), and the mapping text when only the connection is stored. It never carries a connection, so no credential is sent again. Direct servers keep today's behavior.

Behavior

  • Every connection, credential and storage option conflicts with either reference, as do --r2rml / --r2rml-type with a stored mapping (which implies its connection). These are refused at parse time, before any request.
  • Every map still needs a mapping, as fix(query): a graph source that can't serve a query says why, and registration refuses one that never could #2190 requires: --r2rml or --stored-mapping, exactly one. Parsing names both when neither is given. A stored connection does not stand in for a mapping, and with --r2rml it needs --table (a stored connection is mapped one named table at a time). Both references may be given together; the remote checks that they agree. With a stored mapping, --table is optional and defaults to the mapping's first table.
  • A blank id is refused, and an id is sent trimmed. A reference without --remote is refused before anything else: neither a local map nor one routed through a running local server has a store for it.
  • There is no capability check. A server that doesn't support references refuses the request: current db servers refuse a body without r2rml for want of a mapping and one with it for the unknown field, and released ones (checked by reading the map route at each release tag) default to rest mode and reject the missing catalog URI before reading any mapping. Nothing gets registered by mistake. On a 400, 404 or 422, the CLI shows the server's message plus a hint that covers both causes: a remote that doesn't store catalog connections or mappings refuses references to them, and otherwise the id may name nothing it has.
  • A failed remote iceberg map, sql map or delta map now prints one error: prefix instead of two, and keeps the error's own kind and exit code (a usage error while building the request used to come back as a remote error).

Design

  • --r2rml and --stored-mapping form one required clap group, so --r2rml is optional only in favor of a stored mapping. An inline map still refuses args without a mapping file, for callers that build args without parsing.
  • StoredRefs holds only the valid combinations, and no variant carries a connection. The by-reference body is built only from keys the remote accepts beside a reference; what keeps a connection out is clap's conflicts (enforced by the sweep test below) and the StoredRefs variants, and the unit tests assert every body's keys against that list.
  • A test sweeps the clap tree, so a connection option added later must conflict with both references.
  • CliError::context prefixes a message and keeps the error's kind; the three map commands use it.

Tests

  • Unit tests cover the body for each combination, every refusal, and the hint. They also assert that a by-reference body never contains mode, catalog_uri, catalog or io.
  • tests/iceberg_stored_refs_seam.rs runs the real binary against:
    • a mock remote that records bodies;
    • a mock that returns 400 and gets the hint;
    • a real db server, which refuses all three reference shapes (stored mapping, both references, stored connection with --r2rml), registers nothing, and prints exactly one error:;
    • local mode, which refuses.
  • Parsing refuses a map with neither mapping and names both --r2rml and --stored-mapping; args built without parsing are refused too. fix(query): a graph source that can't serve a query says why, and registration refuses one that never could #2190's CLI tests pass unchanged.
  • Each new guard was checked by mutating the code it guards; every mutation made a test fail.

Docs

  • docs/cli/iceberg.md: new options and a "Stored connections and mappings" section.
  • docs/cli/server-integration.md: the by-reference body, for server implementers.

Fixes #2250

aaj3f added 2 commits November 3, 2026 14:48
…remote stores

Some remotes keep connected catalogs and saved R2RML mappings under ids of
their own. `fluree iceberg map --remote <R>` now takes `--stored-catalog <ID>`
and `--stored-mapping <ID>` and sends `stored_catalog_id` /
`stored_mapping_id` in place of the connection and the mapping, so a user
does not restate a connection, its credentials, or a local copy of the
mapping that the remote already holds.

Parsing refuses every inline connection option beside either reference (the
flattened auth and storage groups included), and `--r2rml` / `--r2rml-type`
beside a stored mapping, which implies its connection. A sweep test over the
clap tree fails if a connection option added later does not conflict. The
references become a `StoredRefs` value whose variants are the combinations
left: a stored connection always comes with a mapping (inline or stored), and
neither variant holds a connection, so a by-reference body cannot carry a
credential. The body is built from one allowlist of keys; a key outside it
is refused naming its option.

A map still needs a mapping, as for any Iceberg graph source: `--r2rml`
and `--stored-mapping` form one required group, so `--r2rml` is optional
only in favor of a stored mapping, and parsing names both when neither is
given. A stored connection does not stand in for a mapping, and with
`--r2rml` it needs `--table`, which the remote requires there.

The CLI does not ask whether a remote supports references. No db server
registers anything from a by-reference body: current servers refuse one
without `r2rml` for want of a mapping and one with it for the unknown key,
and every released server defaults to rest mode and refuses the missing
catalog URI before it reads a mapping. A 400, 404 or 422 to a
by-reference request keeps the server's message and adds a hint that the
remote may not support stored connections or mappings. A local map, which
has no such store, refuses references outright.
`iceberg map`, `sql map` and `delta map` against a remote formatted the
inner `CliError` into a new `Remote` one, so the message read
"error: failed to map ... on 'origin': error: bad request: ...", and an
error of another kind (a usage error from building the request) lost its
exit code. `CliError::context` prefixes the message and keeps the kind, and
the three map commands use it.
@aaj3f aaj3f added enhancement New feature or request area:cli fluree CLI UX, rdf toolkit, publish/export/insert flows labels Nov 3, 2026

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

Approving. I left a few small comments inline; none of them block, so take what's useful and skip the rest. If you only look at one, make it the local-server route sending a by-reference request.

Comment thread fluree-db-cli/src/commands/iceberg.rs Outdated
}

// Local execution
if StoredRefs::from_args(&args)?.is_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.

With a local fluree server running, a map with --stored-mapping or --stored-catalog and no --remote never reaches this refusal. The server route just above sends the by-reference body to the local server, which always refuses it. The user then gets bad request: an R2RML mapping is required and the hint that this remote may not support stored references, for a remote they never named. Without a server running, the same command gets the clear message here instead.

That route always leads to a Fluree server, which never stores references, so I'd refuse references whenever --remote is absent, before trying the route. The docs would then agree with themselves: the options table says --remote only, while the refusal list says "no --remote, and no local server to route through".

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.

Good catch, thank you — you're right, that route always lands on a Fluree server, which never stores references, so the user got a refusal (and a hint about a remote they never named) depending only on whether a local server happened to be running. Fixed in aa5ce6d: a --stored-catalog / --stored-mapping without --remote is now refused up front, before we try the server route, and the message says they need --remote <NAME> (and that neither a local map nor one routed through a local server has a store for them). The refusal list in docs/cli/iceberg.md now just says "no --remote is given", so it agrees with the options table.

/// auth failure or a conflict says what it says.
fn map_refusal(e: crate::remote_client::RemoteLedgerError, by_reference: bool) -> CliError {
use crate::remote_client::RemoteLedgerError as E;
let refused = matches!(e, E::BadRequest(_) | E::NotFound(_) | E::ValidationError(_));

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.

A 404 also gets this hint when the remote does support references but has nothing under that id, which points at the wrong cause. The server's message comes first, so it's still readable, but a conditional wording would fit both cases ("if this remote doesn't store connections or mappings, it refuses these references").

Related: cli.rs:4127 (stored_id) checks for a blank id but sends it untrimmed, so a pasted " map-1 " comes back as a 404 with this hint. Trimming it there would avoid that.

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.

Agreed on both. In aa5ce6d the hint is now conditional — "if this remote does not store catalog connections or mappings, it refuses references to them; otherwise check that the id names one it has" — so a 404 from a remote that does store references points at the id instead of the wrong cause. And stored_id now trims what it sends, so a pasted " map-1 " goes out as map-1 (pinned by a_stored_id_is_sent_trimmed).

Comment thread fluree-db-cli/src/commands/iceberg.rs Outdated
let mut body = serde_json::Map::new();
for (key, option, value) in fields {
let Some(value) = value else { continue };
if !BY_REFERENCE_KEYS.contains(&key) {

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.

Every key pushed above is a literal that's already in BY_REFERENCE_KEYS, so this check can't fire. What actually keeps connections out of the body is clap's conflicts, which the sweep test enforces, plus assert_by_reference in the unit tests. The check could go, and the PR body's "any other key is refused, naming its option" claims more than it does.

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.

Yep, you're right — every key pushed there is a literal already on the list, so it couldn't fire. I dropped the check in aa5ce6d; BY_REFERENCE_KEYS is now #[cfg(test)] and only assert_by_reference uses it, to assert every body's keys in the unit tests. I also corrected the PR body: what actually keeps a connection out is clap's conflicts (the sweep test) and the StoredRefs variants, which hold none.

/// name a stored catalog connection or mapping ([`StoredRefs`]), otherwise the
/// connection and mapping given inline.
pub fn args_to_json(args: &IcebergMapArgs) -> CliResult<serde_json::Value> {
match StoredRefs::from_args(args)? {

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.

args_to_json is now called only from tests, and iceberg.rs:263-271 repeats this match so it can pass refs.is_some() to map_refusal. The remote path could call this and work out by_reference from args.stored_catalog / args.stored_mapping.

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.

Done in aa5ce6d: run_iceberg_map_remote now builds its body through args_to_json and works out by_reference from args.stored_catalog / args.stored_mapping, so the match lives in one place.

…causes

Review follow-ups on iceberg map's stored references:

- A map with --stored-catalog or --stored-mapping and no --remote is now
  refused before anything else. It used to be routed to a running local
  server, which never stores references, so the user saw a refusal and a
  hint about a remote they never named. The local refusal now also covers
  the routed case, and the docs say references need --remote.
- The hint on a 400, 404 or 422 is conditional: a remote without stored
  connections or mappings refuses references, otherwise the id may name
  nothing it has. A 404 from a remote that does store references no longer
  points at the wrong cause. Ids are trimmed before they are sent, so a
  pasted " map-1 " is looked up as "map-1".
- The by-reference body no longer re-checks its keys against the allowed
  list: every key it builds is a literal on that list, so the check could
  not fire. What keeps a connection out is clap's conflicts (the sweep test)
  and the StoredRefs variants; the key list stays for the tests.
- The remote path builds its body through args_to_json and derives
  by_reference from the flags, instead of repeating its match.
@aaj3f

aaj3f commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @bplatz! All four folded in with aa5ce6d (replies inline), and I merged main in 0d929f2. fmt, clippy -D warnings, every fluree-db-cli test target and the --no-default-features check are green on a clean box.

@aaj3f
aaj3f merged commit 190529c into main Nov 11, 2026
19 checks passed
@aaj3f
aaj3f deleted the feat/cli-iceberg-map-stored-refs branch November 11, 2026 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:cli fluree CLI UX, rdf toolkit, publish/export/insert flows enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fluree iceberg map: reference a catalog connection and a mapping the remote already stores

2 participants