Repository navigation
feat(cli): iceberg map can name a catalog connection and mapping the remote stores - #2257
Conversation
…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.
bplatz
left a comment
There was a problem hiding this comment.
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.
| } | ||
|
|
||
| // Local execution | ||
| if StoredRefs::from_args(&args)?.is_some() { |
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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(_)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
| 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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)? { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
…stored-refs-on-2190
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: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
--r2rml/--r2rml-typewith a stored mapping (which implies its connection). These are refused at parse time, before any request.--r2rmlor--stored-mapping, exactly one. Parsing names both when neither is given. A stored connection does not stand in for a mapping, and with--r2rmlit 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,--tableis optional and defaults to the mapping's first table.--remoteis refused before anything else: neither a local map nor one routed through a running local server has a store for it.r2rmlfor 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 a400,404or422, 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.iceberg map,sql mapordelta mapnow prints oneerror: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
--r2rmland--stored-mappingform one required clap group, so--r2rmlis 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.StoredRefsholds 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 theStoredRefsvariants, and the unit tests assert every body's keys against that list.CliError::contextprefixes a message and keeps the error's kind; the three map commands use it.Tests
mode,catalog_uri,catalogorio.tests/iceberg_stored_refs_seam.rsruns the real binary against:--r2rml), registers nothing, and prints exactly oneerror:;--r2rmland--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.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