Skip to content

fix(iceberg): resolve warehouse-root tables by namespace directory - #2378

Merged
bplatz merged 7 commits into
mainfrom
fix/iceberg-warehouse-namespace-dir
Nov 13, 2026
Merged

bplatz merged 7 commits into
mainfrom
fix/iceberg-warehouse-namespace-dir

Conversation

@bplatz

@bplatz bplatz commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A Direct-mode table_location may name a warehouse root rather than one table's directory. Resolving a table beneath that root matched on the table name alone, against the root's immediate child directories; the namespace in rr:tableName was never consulted.

So a root laid out <root>/<namespace>/<table> could not be read: north.people under a root holding north/ and south/ failed with no directory under the warehouse root matches table 'people' … Found 2 directories: [north, south]. Nothing distinguished the same table name in two namespaces, which a mapping spanning several namespaces in one graph needs.

Change

resolve_direct_table_location now looks in the namespace's directory first:

  • When the root holds a directory for the table's namespace, spelled <ns>/ or the Hive/Glue/Spark <ns>.db/, the table is matched there and only there: a table missing from its namespace directory is an error naming the directory searched, never a match on a stray <root>/<table>. A directory that is itself a table (a flat root's sales/ for a mapping naming sales.orders) is not a namespace. A multi-level namespace (db.schema) descends one directory per level.
  • When the root has no directory for the namespace, matching is flat, exactly as before. A Snowflake-style copy (DW.FACT_ORDER → fact_order.UIHGsQex/) resolves unchanged and issues no additional LIST.
  • A namespace directory matches on its whole name: exact case preferred, otherwise a unique case-insensitive match. Two directories differing only in case with neither exact is an error, as is an ambiguous table inside a namespace directory.
  • Listings stay session-cached, one LIST per directory per build.

The query path and the scan/pin path (prepare_iceberg_scan) share the resolver, so both resolve by namespace.

Cost

Each namespace level is one more LIST per query, session-cached within the query. A cross-query cache of resolved directories is a follow-up. Follow-up: #2388

Tests

  • same_table_name_in_two_namespaces_resolves_by_namespace (it_iceberg_warehouse_root) stages north/people (5 rows), south/people and a two-level eu/west/people (3000 rows each, different tables), a Hive-spelled glue.db/people, and a stray <root>/people under one root and reads the four namespaced tables through one mapping, through the query path and current_snapshot_id. A namespace directory without the table is an error naming that directory (it resolved to the stray table with the fallback in place), and a namespace with no directory at all is matched flat, to the stray table. It fails with the resolver change reverted.
  • Unit test for namespace-directory matching in fluree-db-iceberg.
  • The existing flat warehouse-root test is unchanged and passes.

Checked by hand against S3 (not in CI): pyiceberg-written tables at <root>/north/people, <root>/south/people and <root>/eu/west/people each returned their own rows and snapshot pin through one mapping (one rr:tableName written SOUTH.PEOPLE), a namespace with no directory was a miss, and a flat people.<suffix>/ root still resolved DW.PEOPLE. GCS listings have no namespaced-layout run.

Docs: the warehouse-root paragraph in docs/graph-sources/iceberg.md and the --table-location help text.

A Direct-mode warehouse root matched a table on its name alone, against the
root's immediate children. A root laid out <root>/<namespace>/<table> could
not be read at all, and nothing distinguished the same table name in two
namespaces.

Look in the namespace's directory first (one directory per namespace level);
a root with no directory for the namespace is matched flat, as before.
@bplatz bplatz added the bug Something isn't working as expected label Nov 13, 2026
@bplatz
bplatz requested a review from a team November 13, 2026 12:20

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

@bplatz this is nice. Resolving by namespace directory while keeping the flat Snowflake path byte-identical (and LIST-free) is the right shape. Two headline notes: (1) Hive/Glue write namespace directories as <ns>.db/ (our own Glue fixture is warehouse/glue_it.db/customers), and the whole-name match deliberately excludes suffixed directories, so a Glue-written root still misses. Accepting <level>.db is a few lines. (2) On your reviewer note, I'd make the namespace directory authoritative, with a directory that has its own metadata/ not counting as a namespace (listing_is_single_table already exists for exactly that). Claude reproduced the stray <root>/people pick below, and the current test doesn't pin either behavior. Neither is blocking. This and #2379 merge cleanly in either order, and my #2316/#2317 only conflict with this textually (new methods inserted at the same spot in r2rml.rs), so no need to hold this on mine:

Full review below:


✅ Approve.

This is a clean extension of the warehouse-root resolver. The namespace descent only selects listed children, the flat path costs exactly what it did before, and both Direct entry points (query and current_snapshot_id) go through the one resolver, which your test checks on both. Claude ran the integration test and mutation-checked it: with resolve_namespace_dir short-circuited to None, same_table_name_in_two_namespaces_resolves_by_namespace goes red on north.people. The three notes inline are fold-ins: <ns>.db/ directories; the fallback (answering your note, with a test that pins whichever way you go); and a cross-query cache for the listings.

Adherence to repo commitments:

  • Patterns/abstractions: ✔ extends the existing resolver and the session listing cache; the new matcher sits next to match_warehouse_table_dir and reuses its candidate rule.
  • Performance (speed first, memory second): ✔ no regression: flat roots issue no new LIST. A namespaced root adds one LIST per namespace level per query (session-scoped cache); see the inline note on a cross-query cache.
  • Deployment targets: ✔ host-neutral: no background work or process-lifetime state, and listing goes through each backend's list_dir. Evidence is local (file://) in CI plus the body's manual S3 run. GCS has no namespaced run, but nothing in the path is GCS-specific.
  • Testing: ✔ the new integration test runs in CI (its own [[test]], iceberg + native) and fails with the resolver removed. ⚠️ The fallback behavior isn't pinned (inline).
  • Conventions: ✔ multi-line fix commit; iceberg.md and the --table-location help updated; fmt and clippy green on the head.

Verified at branch HEAD ff8eb962f: Claude ran it_iceberg_warehouse_root (2 passed) and the fluree-db-iceberg warehouse unit tests (7 passed) with --all-features on a clean box. Mutation checks: the namespace descent removed fails the new test; the fallback made authoritative still passes. Both repros above were reproduced, and the merge with #2379 passes both suites. CI is green on this head.

Approving so you can merge when ready, but maybe worth considering the .db and fallback notes first.

Comment thread fluree-db-iceberg/src/catalog/direct.rs Outdated
pub fn match_warehouse_namespace_dir(level: &str, dir_names: &[String]) -> Result<Option<String>> {
let want = level.trim();
let name = |d: &'_ String| d.trim_end_matches('/').to_string();
if let Some(exact) = dir_names.iter().map(name).find(|d| d == want) {

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.

Optional: Hive/Glue-style <namespace>.db/ directories still miss. match_warehouse_namespace_dir matches the whole directory name, and the unit test pins that a suffixed directory is not a namespace (:475). That's the right call for Snowflake's <table>.<random>/, but Hive, Glue and Spark-on-Hive all write namespace directories as <ns>.db/, and the repo already holds one: fluree-db-api/tests/fixtures/iceberg/glue/objects/warehouse/glue_it.db/customers.

Claude reproduced it on this head. A root holding north.db/people and south.db/people, with rr:tableName "north.people", fails on the flat path: no directory under the warehouse root matches table 'people' … Found 2 directories: [north.db, south.db]. The same tables staged as north/people resolve, per your test.

Minimally, after the bare-name checks find nothing, we could try <level>.db with the same exact-then-unique-case-insensitive rule:

// after the exact / case-folded bare-name checks come up empty:
let with_db = format!("{want}.db");
if let Some(exact) = dir_names.iter().map(name).find(|d| *d == with_db) {
    return Ok(Some(exact));
}
// …and the same unique case-insensitive pass over `with_db`

…plus a .db row in namespace_dir_matches_whole_name_preferring_exact_case and one staged <ns>.db/<table> in the integration test. I recognize it's a bit beyond what the body promises, but if you agree it's right, I'd rather see it folded in now than wait for the first Glue-written root someone points at this.

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.

Addressed in b635e75

Comment thread fluree-db-api/src/graph_source/r2rml.rs Outdated
fluree_db_iceberg::catalog::warehouse_table_dir_candidates(requested, &ns_listing);
match candidates.as_slice() {
[one] => return Ok(format!("{ns_dir}/{}", one.trim_end_matches('/'))),
[] => searched_namespace_dir = Some(ns_dir),

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.

Optional, answering your reviewer note: I'd make the namespace directory authoritative. When south/ exists but lacks people, this arm records the directory and the flat match at the root runs anyway. Claude staged north/people, an empty south/, and an unrelated table at <root>/people (the 3,000-row people_window fixture). south.people then returned 3,000 rows, all from <root>/people, with no error. That's a silent wrong-table read, although only in a root that mixes both layouts.

The case the fallback protects is a "namespace directory" that is really a bare table directory: a flat root with sales/ and orders/ tables and a mapping naming sales.orders. listing_is_single_table already answers that, and the namespace listing is fetched anyway. So a directory with its own metadata/ child shouldn't count as a namespace. Once that holds, a miss inside a real namespace directory can be an error like the one you already build at :3864-3870:

let ns_listing = self.warehouse_listing(&ns_dir, lt_key, plan).await?;
if !listing_is_single_table(&ns_listing) {
    let candidates =
        fluree_db_iceberg::catalog::warehouse_table_dir_candidates(requested, &ns_listing);
    match candidates.as_slice() {
        [one] => return Ok(format!("{ns_dir}/{}", one.trim_end_matches('/'))),
        [] => {
            return Err(QueryError::InvalidQuery(format!(
                "warehouse-root resolution for table '{table_id}': no directory under \
                 namespace directory {ns_dir} matches '{requested}'"
            )))
        }
        many => { /* AMBIGUOUS, as now */ }
    }
}

Whichever way you go, the test should pin it. Claude mutated this arm into an authoritative error, and both tests in it_iceberg_warehouse_root still passed: the staged root at it_iceberg_warehouse_root.rs:212 has no root-level people for the fallback to find, so the east.people assertion can't tell the two behaviors apart. Staging one there makes it bite. Minor and non-blocking, but if you agree, I'd rather see it settled in this PR than left as the reviewer note.

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.

Addressed in d86fe1d (authoritative; the test stages a stray root-level table so the fallback would bite).


/// The child-directory listing of a warehouse directory: one LIST per
/// directory per build, session-cached.
async fn warehouse_listing(

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.

Optional: each namespace level is one more LIST on every query. warehouse_listing caches in IcebergCatalogSession::warehouse_listings, which is query-scoped (catalog_session.rs:128-132). So a table under eu.west costs the root LIST that main already pays per query, plus two new sequential LISTs, on every query. It's not a regression (these layouts didn't resolve before), and the flat path adds nothing, which I like. But the resolved directory seems about as stable as anything we cache. A cross-query entry in R2rmlCache, keyed by scope, root and table id, with misses not cached so a newly created table still shows up, would take the root LIST and these off the read path together. This is more of a suggestion than a must, but if you agree it's right, I'd rather fold it in while the helper is fresh.

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.

Follow-up: #2388

Hive, Glue and Spark-on-Hive write a warehouse's namespace directories as
<ns>.db/. The bare name is tried first, then the .db spelling, each
exact-case then unique case-insensitive.
A table missing from its namespace directory fell back to the flat match
at the root, so a stray <root>/<table> answered for it with no error. The
namespace directory is now the only place its tables are looked up; a
directory that is itself a table is no namespace. The miss names the
directory searched.
…-namespace-dir

# Conflicts:
#	fluree-db-api/src/graph_source/r2rml.rs
… authoritative

Both still described the namespace directory as searched first, with a
fallback to the root, and did not name the <ns>.db spelling.
@bplatz
bplatz merged commit cee2517 into main Nov 13, 2026
19 checks passed
@bplatz
bplatz deleted the fix/iceberg-warehouse-namespace-dir branch November 13, 2026 20:13
bplatz added a commit that referenced this pull request Nov 13, 2026
Brings #2296, #2309, #2313, #2315, #2316, #2317, #2367, #2368, #2369,
#2373, #2374, #2378 and #2379.

Ports onto next:

- #2374 (bound-object probe reads POST): main's POST walk and per-type
  flush replace next's OPST walk. The lane keys (o_type, o_key), so next's
  triple-term handles are one more covered type (object_probe_covers takes
  TripleTermDict) rather than a flush per type; a term's matches are read
  whole, as a ref's are. The wildcard cursor still keys refs only. Pooled
  graphs decline through dedicated_branch(Post); o_i is 64-bit. Next's
  pair join keys its subject through the shared LaneKey.
- #2373 (leaflet type constant under replay): replays_history and
  o_type_const_for beside next's may_hold_keys; the row-labelling lanes
  take main's const-unless-replaying form over next's always-read-column.
- #2368: the cyclic join decodes for eager callers with next's list index
  sentinel; both reasoning tests kept (cyclic operator and pair lane).
- #2317 (GRAPH streams): main's work queue and InnerStream with next's
  pooled-graph pruning before each enumerated graph.
- #2315: list predicates are an ordered set in next's multi-ledger view;
  the annotation edge probe stays deleted (no bundle lane on next).
- #2296 (rebase reads its new line): ported onto next's fenced resets,
  erasure checks and peer sync (follow_record keeps next's unchanged-head
  arm); a non-fast-forward rebase moves head and index in one fenced
  reset.
- Main's new tests: async genesis_ledger, graph_source_store for mapping
  writes, leaf_rows for leaflets-per-leaf, storage lock off for two file
  instances. New pattern/function matches cover TermComponents and the
  triple-term functions; AnnotationTarget arms dropped.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants