Repository navigation
feat(materialize): fluree materialize — native-twin builder from virtual R2RML/Iceberg datasets - #1529
Conversation
…hunk A) The engine-free core of `fluree materialize`: enumerate every (s,p,o) triple for a compiled R2RML mapping directly off row batches, with no query plan, operator, or fuel tracker. It reuses the exact per-term materialize helpers the query operator uses (materialize_subject/predicate/object_from_batch, get_join_key_from_batch), so term and datatype fidelity match the engine by construction — the only new logic is the whole-graph orchestration. Foreign-key edges are resolved lookup-free and dims-first: parent triples maps are processed before their children (topological order), and a parent key->subject index built during the parent scan resolves each child FK by hash lookup. A dangling or null FK produces no triple (R2RML inner-join semantics). Cyclic and self-referential parents are fully pre-indexed. Emits into a TripleObserver (an N-Triples collector for the parity diff; an ingest-sink adapter lands in chunk B) and collects MaterializeStats incl. per-(child, predicate) FK-edge counts for the parity gate. 9 hermetic golden tests cover multi-class type emission, null-subject and null-object drop, typed/lang/constant/template objects, FK inner-join, dangling and null FK drop, composite keys, self-referential FK pre-indexing, and dims-first ordering determinism.
… chunk B) materialize_graph(provider, gs, observer) streams each logical table through the whole-graph enumerator over the R2rmlProvider/R2rmlTableProvider scan path — the provider-backed counterpart to the in-memory reference driver, with identical dims-first ordering and the same per-batch index/emit calls. The ordering + pre-index logic is now a shared materialize::plan() so both drivers stay in lock step, and ParentIndexSet::needed_parent_columns feeds scan projection. Engine-equivalence checkpoint: materializer_driver_matches_engine_wildcard runs the driver over the same airline mock the engine `?s ?p ?o` wildcard uses and asserts the two decoded triple sets are identical (12 triples) — the deterministic hermetic analog of the live native-sf01 full-triple diff, proving the new enumerator agrees with the proven query engine over an identical scan. Plus materializer_driver_resolves_fk_across_tables: dims-first FK resolution and dangling-drop over streamed per-table scans. Full it_graph_source_r2rml suite green (55 passed).
ImportSinkObserver bridges the whole-graph enumerator to the native bulk ingestion pipeline: each materialized (s,p,o) is interned and encoded through the SAME ImportSink term_iri/term_blank/term_literal + emit_triple the Turtle and JSON-LD parsers use, so term/datatype/language fidelity is preserved by construction (a "9.99"^^xsd:decimal interns to a decimal flake, a "hola"@es to a lang-tagged string). The lang-vs-explicit-datatype-vs-implicit-xsd:string decision — the one spot literal fidelity could silently narrow — is factored into literal_sink_args and unit-tested for all three cases.
…1, chunk B) The materialization side of the end-to-end builder: build_virtual_chunk encodes a buffer of materialized triples into a ParsedChunk by mirroring parse_chunk exactly (WorkerCache + ImportSink::new_cached + SpoolContext + finish), replaying interned triples through ImportSinkObserver instead of parsing Turtle. Zero transact edits — every primitive is public and ParsedChunk fields are pub. drive_virtual_import streams a virtual R2RML source through the enumerator (dims-first, same pre-index pass) into a byte-budgeted ChunkingObserver and hands each completed ParsedChunk to an emit callback in contiguous idx order (t=idx+1). Chunk size is derived from BYTES (the memory budget), never a fixed row count — the machine-safety chunk-size knob. R2rmlBuildProvider is the combined provider trait for the builder, with a compile-time Send+Sync assertion (the ?Send/Send trait-duality guard). Byte-budget chunk cutting is unit-tested.
…03 D1, chunk B COMPLETE) Wires the materializer into the bulk import pipeline as a new ImportSource::Virtual branch that REUSES the battle-tested downstream unchanged. A single materializer thread scans the R2RML source (async, driven via Handle::block_on off a dedicated thread), enumerates triples dims-first, and encodes byte-budgeted ParsedChunks that feed the SAME commit_parsed_chunks_in_order consumer + spool-sort + build_all_indexes + publish_index the text paths use. Provider rides on ImportConfig::virtual_source (Arc<dyn R2rmlBuildProvider>, Send+Sync asserted); the arm is inserted before the remote-parallel arm so every existing Local/Remote/streaming/Files arm body is byte-identical (diff = 138 insertions, 1 deletion — only is_channel_fed gains `|| is_virtual`). Chunk byte-size derives from the memory budget (machine-safety). Entry: CreateBuilder::import_r2rml, doc'd to set explicit --parallelism/--memory-budget-mb. End-to-end test (multi-thread, tight bounds threads=2 + memory_budget_mb=256): builds a real indexed+published twin from a dim+fact+FK mock with lang and xsd:decimal literals, then queries it back — class counts, FK-edge resolution to the parent IRI, xsd:decimal value+datatype round-trip (not narrowed to string), and lang-tag round-trip all confirmed. All 83 bundled import tests + the 56-test R2RML suite green.
…DEC-003 D1) The virtual materializer drives its async scan via Handle::block_on off a dedicated thread, which deadlocks on a single-threaded tokio runtime. Detect the runtime flavor at the arm entry and return a typed ImportError::UnsupportedRuntime instead of hanging; production servers and the CLI run multi-thread. A code comment + this error document the remote-style two-stage producer as the runtime-flavor-agnostic future alternative. Guard test on a current-thread runtime confirms the loud failure.
…DEC-003 D1, chunk C) Adds the per-table build-watermark capture seam: R2rmlProvider::build_watermark returns HashMap<table, TableWatermark> with a DEFAULT of empty, so every existing provider keeps compiling and a real Iceberg-backed provider overrides it to report its catalog session's pins. TableWatermark carries the authoritative metadata_location pin plus best-effort snapshot_id/sequence_number (typed Option, for the Deliverable-3 snapshot diff). The bulk builder will fail loud when this is empty for a non-empty table set, so a provider that forgets to override cannot publish an unstamped twin.
…og session (DEC-003 D1, chunk C2)
Record each table's pinned Iceberg snapshot (metadata_location + snapshot_id +
sequence_number) into a new IcebergCatalogSession.snapshots map at the single
scan_table_inner caller of load_table_context, first-writer-wins. Expose it as
pinned_tables(gs) -> {table -> TableWatermark} and override
FlureeR2rmlProvider::build_watermark to surface it. Harmless for ordinary
queries; the driver reads it only during a materialize build.
…003 D1, chunk C3) Add a metadata-only pin-all pre-pass to drive_virtual_import so every table's snapshot is pinned before emission (cross-table skew bounded to seconds; emit scans reuse the pins, no duplicate loadTable GETs). Assemble the twin's WatermarkStamp — per-table watermark vector + SHA-256 mapping hash + builder version — with a fail-loud guard that errors on an empty watermark for a non-empty table set (§17(a)/(b)). The stamp is logged here; chunk D persists it into the final commit. Mocks override build_watermark with fakes.
…ommit (DEC-003 D1, chunk D) Add ParsedChunk.txn_meta (empty for every text-import chunk → byte-identical commits) and consume it in finalize_parsed_chunk. The materialize driver ns-encodes the WatermarkStamp (builder version + mapping hash + watermark vector as sorted JSON) into ONE chunk's txn_meta via the sink's new intern_meta_predicate (so the stamp predicates' ns codes publish in that commit's namespace_delta). A one-chunk lookahead makes the stamp ride the LAST non-empty commit — completion-marker semantics: a valid twin is one whose head commit carries a parseable stamp. TableWatermark gains serde derives; read_stamp parses it back. Round-trip test: build -> archive_ledger -> restore_ledger -> stamp survives byte-identical and parses.
…e + full diff (DEC-003 D1, chunk E) verify_twin compares the built twin against its virtual source using the Chunk-A enumerator as the oracle and a native wildcard query on the twin, both rendered to identical N-Triples: class counts (always-on), a stratified per-subject sample (Quick, always-on, full node compare of the first N subjects/class), and a full-triple diff (Full). Per-property counts are skipped-with-note (the manifest-sound fast path is a real-Iceberg optimization). Numeric object literals are value-canonicalized on both sides so a value-preserving typed- literal normalization (stored xsd:decimal re-rendering '5.00' as '5') is not misreported — the same treatment the LIVE full-triple diff will need. Gate failure => report FAILED, twin not announced (publish-then-verify-then-drop, the sound ordering; the CLI drops on failure). Hermetic tests: faithful twin passes Quick+Full; a corrupted twin (injected instance) fails on the count + full diff.
…3 D1, chunks F+G) New `fluree materialize <graph-source>` command: build a native twin from a virtual R2RML source, verify it, and write it. Flags: --into (default -twin), --output pack|ledger|s3 (pack default; s3 rejected up front as not-yet-wired in the file-backed CLI), --output-path, --verify quick|full, --max-performance, --home, and (G) --allow-mor-deletes. §14 co-resident posture: conservative fixed defaults (parallelism=2, memory_budget_mb=512) unless the user sets an explicit value or --max-performance (own-the-box auto). Publish-then-verify-then-drop: a failed gate drops the twin so nothing unverified stays announced. One-shot CLI leaks the Fluree for a 'static real provider (single build-scoped session). G: the MoR scan-path guard's refusal is surfaced with the --allow-mor-deletes override (sets FLUREE_ICEBERG_ALLOW_MOR_DELETES). Command self-gates on iceberg (default on); a not(iceberg) build gets a clear error. 5 helper unit tests.
…dget honesty, drop-branch fix (DEC-003 D1) Four review-response items (all nonblocking, one commit): 1. Verify-default honesty: print the Quick gate's shared-oracle epistemics at run time (catches ingest/index corruption, NOT enumerator logic — run --verify full + the native diff before cutover). Make the stratified sample seeded-deterministic (WatermarkStamp.sample_seed, recorded as a sampleSeed Long, derived from the mapping hash) and spread across the class via a seed-mixed hash instead of the lexicographic first-3 — tail-subject bugs are now sampleable, reproducible, and coverage widens as the seed rotates. 2. Quick negative test: a per-subject property corruption (counts unchanged) fails the Quick sample arm. 3. Budget-floor honesty in --help + the gate doc: --memory-budget-mb is advisory sub-2GB (chunk floors at 128MB), peak RAM ~= 2GB + parallelism*128MB*2.5, and the FK parent index sits OUTSIDE the budget (~ largest parent table). 4. Drop-on-fail test (dropped_twin_is_unpublished) — it surfaced a real CLI bug: drop_ledger rejects a :branch suffix (HTTP 400), so the gate-fail drop would have errored and left the unverified twin announced. FIXED: strip the branch (ledger_name_no_branch) and surface a loud manual-drop warning if the drop still errors instead of swallowing it.
…i-table sources (DEC-003 D1) AJ-driven registration-gap fix: the local CLI's Direct mode was single-table, so a multi-table R2RML source over a catalog-less bucket copy (a Snowflake-managed Iceberg database whose table dirs carry random suffixes, e.g. fact_order.UIHGsQex/) could not register. Now, when a Direct table_location is a WAREHOUSE ROOT (auto-detected: its leaf dir does not name the requested table), each rr:tableName resolves to its own dir under the root via ONE session-cached S3 LIST, matching <name>.<suffix>/ or bare <name>/ case-insensitively (namespace-stripped). Ambiguity or a miss fails loud, naming the candidates. - New SendIcebergStorage::list_dir (S3 ListObjectsV2 + delimiter; default-errors for other backends; LazyStorage forces + delegates). - Pure match_warehouse_table_dir in fluree-db-iceberg (5 hermetic tests: suffixed, bare, case, ambiguity, miss). - FlureeR2rmlProvider::resolve_direct_table_location + IcebergCatalogSession warehouse-listing cache (one LIST per build). - Single-table direct behavior byte-unchanged (self-diff: only the info! moved; api it_graph_source_r2rml 62 green, iceberg lib 251 green). - No new flag / no config-schema change (table_identifier already tolerates a root; Direct registration does no probe). Rule documented in iceberg map --help.
… feat/materialize-builder # Conflicts: # fluree-db-transact/src/import.rs
Per-phase tracing spans on the materialize produce side: pin_all_tables, per-table table_scan_emit (scan+render+emit wall + triple delta), and an encode_total accumulator across build_virtual_chunk calls. These are the spans the A2 A/B phase attribution was measured with; they ship with the fix slate so the same numbers are reproducible on any build. The two verify-phase spans in this commit are superseded by the O2 verify redesign that follows in this slate.
…zation
verify_twin double-buffered the ENTIRE graph twice in RAM even in Quick mode
(full source re-enumeration into a BTreeSet + full twin wildcard into another;
~26.8GB footprint at 6.1M triples, certain OOM at 35M). Redesign both modes to
be memory-bounded:
- Quick (default): peak RSS = O(sampled subjects). Class counts come from a
single streamed source pass (SampleAndCountObserver — counts per-class type
triples, retains full triple sets ONLY for the sampled subjects, drops the
rest as it streams) plus bounded twin COUNT queries; the per-subject sample
pulls a seeded window of subjects on each side via bound-subject queries.
- Full (--verify full): spools BOTH sides to on-disk N-Triples (source streamed
through the enumerator, twin paged through bounded wildcard queries), external
merge-sorts each under a bounded working set, then streams a k-way diff. Peak
RSS = O(one sort run). Replaces the whole-graph double-buffer.
- Decimal false-reject fix (A2 receipt): canonicalize_numeric_nt is now value-
canonical for double/float — parse to f64 and re-render the shortest round-trip
form so XSD E-notation (Fluree storage, '-1.5521762E1') and the enumerator's
plain f64::to_string() ('-15.521762') compare equal. decimal/integer keep exact
lexical canonicalization (no lossy float round-trip). Regression tests included.
Drop-on-fail already checks the drop result and warns if the drop errored (CLI).
The two verify-phase spans from the instrumentation commit are superseded here.
…-parallelism) The produce side pinned snapshots and pre-indexed FK-parent tables strictly serially. A2 measured ~30s of serial loadTable round-trips (pin_all_tables) and ~217s of strictly-serial cold-S3 fact-table fetch (Pass-1 pre-index) at 35M. - pin_all_tables: the 8-16 serial loadTable GETs now run concurrently via buffer_unordered, bounded by the --parallelism knob. - Pass-1 pre-index: pre-index tables now scan concurrently (bounded by --parallelism), each into its OWN partial ParentIndexSet, merged back once all scans complete (ParentIndexSet::split_empty + merge_from). Parent IRIs are disjoint across pre-index tables, so the merge is a union. Peak extra memory = parallelism x (one batch + one table's partial index); the partials sum to the final index, resident regardless of ordering. drive_virtual_import takes a parallelism argument (the existing knob, previously only sizing the result channel); the virtual arm passes the effective parse threads. Machine-safety: all new concurrency is capped by the knob (default 2, co-resident). O5(c) - eliminating the fact double-read (Pass-1 index scan + Pass-2 emit scan of the same table) - is DEFERRED: it is naturally subsumed by O1's produce-side pool (topological parent-first emit that indexes during the emit scan), and doing it standalone is more invasive than warranted here. Recorded as a follow-up.
…x accounting
Two bounds-correctness holes the audit flagged (O6):
(a) effective_chunk_size_mb underflowed for sub-2GB budgets: (budget-2048)
saturated to 0 and the clamp then floored the chunk at 128MB REGARDLESS of
budget — so a 512MB-budget import used the same 128MB chunk as a 2GB one, and
a 128MB chunk under a 512MB budget blows the budget once the ~2.5x parse/
inflight expansion is counted. Below 2GB the chunk now scales as
budget*0.6 / working-set, clamped to [16,128] MB (continuous with the
large-budget floor at the 2GB boundary). The >=2GB path is unchanged.
(b) the FK ParentIndexSet is fully resident for the whole build and sat OUTSIDE
any budget. It is now charged against a fraction (~50%) of the import memory
budget and the build FAILS LOUD (MaterializeError::ParentIndexBudgetExceeded,
mirroring the QueryError::MemoryBudgetExceeded pattern) if it would overflow —
checked after Pass-1 and after each lazily-indexed dimension. Estimate via
ParentIndexSet::estimated_bytes (key + term string bytes + per-entry
overhead). drive_virtual_import takes a memory_budget_bytes argument; the
virtual arm passes the effective import budget (0 disables the guard).
The materialize --help BUDGET note is rewritten to describe the new model (it
claimed the budget was advisory below 2GB and the FK index was outside it — both
now fixed). Tests: sub-2GB chunk scaling, large-budget unchanged, budget-fraction
math, empty/disabled guard, estimated_bytes nonzero on a populated index.
…t path Byte-identical allocation reductions on the per-row produce path (verified by the exact-triple-set enumerator tests and the template tests — 121 r2rml tests green): - expand_template_from_batch: replace the per-placeholder `result.replace(...)` loop — each call a full re-scan + re-alloc of the whole growing string, O(placeholders x len) per row, and prone to double-expanding a value containing another placeholder's text — with a single-pass build from the original template's segments into one reserved String. One pass, one allocation, exact R2RML semantics. - emit_batch: hoist per-batch what was rebuilt per row: the rdf:type object terms (was RdfTerm::iri(class.clone()) cloning every class IRI on every row) are built once; each POM's constant predicate is borrowed via Cow (the common case) so the hot data-triple path skips the per-row predicate clone; and this TriplesMap's triple total folds into stats.per_tm ONCE per batch (one tm.iri clone per batch, not one per emitted triple). SCOPE: this is the low-risk, self-contained half of O3/O4. The OwnedTriple double- materialization drop (O3a — intern directly from the enumerator into the chunk sink, cutting on true encoded size) and the per-TriplesMap compiled-template cache are DEFERRED to the O1 produce-parallelism PR: they restructure the same emit->chunk pipeline O1 rearchitects, so landing them together (validated by the 35M re-measure) avoids conflicting rework. Recorded as a follow-up.
…rallelism The entire produce side ran on ONE virtual-materializer thread; --parallelism only sized the result channel, so the create-from path's measured 3.9x (1->2 threads) scaling was fully foregone (A2). This activates the knob as a real produce pool. Design (mirrors the proven text-import N-worker + reordering-consumer pattern): - Pass-1 now pre-indexes EVERY FK parent (not just cyclic/self-referential), so the ParentIndexSet is COMPLETE and READ-ONLY before Pass-2 — a child may emit on any worker in any order, so its parent must already be indexed. Acyclic dim parents that were indexed lazily during their own emit scan are therefore scanned twice (index + emit); the double-read on (usually small) dimensions is the cost O1 accepts (eliminating it is the deferred O5(c)). The pre-index scans stay concurrent (O5), each into a partial index merged back after. - Pass-2: `parallelism` sync worker threads render + intern + encode batches, each with its OWN private chunker + encoding sink. This driver scans each table (async) and dispatches its batches over a bounded channel; a blocking send on the dedicated producer thread is natural backpressure. The r2rml scan futures are !Send, but workers do only SYNC render/encode (the async scans stay on the driver), so no Send bound is needed — sidestepping the non-Send trap. - Chunk idx comes from a shared atomic; commit_parsed_chunks_in_order reorders by idx, so out-of-order arrivals are fine. The completion stamp rides ONE dedicated final chunk (highest idx -> committed last -> the twin's head), produced after the workers join — the already-supported empty-stamp-commit shape. Peak produce memory = parallelism x (one chunk buffer + one encoding sink) — the same N x chunk model the text path lives under; bound = --parallelism (default 2, co-resident), no new knob. drive_virtual_import now takes a Send+Clone SyncSender instead of an FnMut sink so the pool can fan chunks in; the virtual arm keeps a sender clone to surface a build error after the driver drops its copy. Correctness is validated hermetically (no 35M re-measure needed — that stays the separate perf phase): parallel_produce_matches_serial_and_stamps_once drives a fixture mapping at p=1 and p=2 and asserts identical MaterializeStats, identical total op_count (no triple lost/duplicated), unique + contiguous chunk indices, and EXACTLY ONE stamped chunk at the highest idx. SpoolConfig gains #[derive(Clone)] (all-Arc fields) so each worker gets its own handle; fluree-db-tabular becomes a direct api dep to name ColumnBatch on the work channel. DEFERRED (recorded here, in this PR — not a second PR): O3a (drop the OwnedTriple intermediate; intern directly from the enumerator into the chunk sink) does not ride naturally on this worker restructure — it rewrites the same per-worker emit->chunk path — so it lands as a follow-up commit on this branch.
bplatz
left a comment
There was a problem hiding this comment.
Approving. Please walk the inline notes below and decide which belong in this PR versus a follow-up — a few of them (1, 4) I think are worth folding in here; the rest are your call.
Verified locally
cargo clippy --all --all-features --all-targets -- -D warnings— clean.cargo nextest run -p fluree-db-api -p fluree-db-r2rml -p fluree-db-cli -p fluree-db-transact -p fluree-db-iceberg --all-features --no-fail-fast— 4373 passed, 0 failed.
The one finding that is not inline
No docs. This adds a new top-level fluree materialize command with no docs/cli/materialize.md and no docs/SUMMARY.md entry; every one of the other ~43 CLI commands has both. docs/graph-sources/r2rml.md and docs/graph-sources/iceberg.md are the natural home for the twin / watermark / completion-stamp concept and for the new warehouse-root --table-location resolution rule, which the body says is documented only in iceberg map --help. Per the repo's docs mandate this belongs in the same changeset.
Process note
The base audit-program/land-on-main is 45 commits and ~10k lines ahead of main, so this diff is ~6.4k of the ~16.5k that actually reaches main through it. Worth stating explicitly for whoever sequences the landing.
What is strong
The wave-scheduled index-during-emit design is the right shape, and claiming a chunk idx only AFTER securing the first batch — so an empty chunk can never leave a gap that stalls the in-order consumer forever — is exactly the kind of detail that is easy to get wrong and was gotten right. Publish-then-verify-then-drop is sound: I confirmed create ... import rejects a ledger that already has commits, so the hard drop can only ever hit a ledger this build just created, and the :branch strip closes the one way that guard could have been defeated. The verify-default honesty message printed to the operator is the right instinct. And apart from the chunk-sizing note, the shared-path footprint really is as small as the appendix claims.
| // buffers + index build and divide the rest across the working set; | ||
| // floor at 16MB (still worth a commit), cap at 128MB (continuous with | ||
| // the large-budget floor at the 2GB boundary). | ||
| let working = budget_mb as f64 * 0.6 / denominator; |
There was a problem hiding this comment.
Shared-path behavior change that the native-impact appendix does not list.
The appendix says the only shared-path change is ParsedChunk.txn_meta, "self-diff byte-identical for every text import." This rewrite of effective_chunk_size_mb changes chunk sizing for EVERY import whose budget is under 2048 MB — Turtle/TriG/JSON-LD included, not just materialize.
Concretely, at memory_budget_mb = 512 with max_inflight = 2: before, 512.saturating_sub(2048) = 0 → clamp(128, 768) = 128 MB. After: 512 * 0.6 / 6 = 51 MB. That is ~2.5x the commit count and a different ledger shape for the same input.
The default budget is 80% of RAM, so most hosts land above 2048 and are unaffected. What IS affected: containers under roughly 2.5 GB, and anyone who passes --memory-budget-mb explicitly — which the PR's own machine-safety posture actively encourages, and which every finalizer-touching test in this repo already does (memory_budget_mb = 256).
The fix itself reads correct to me — the old floor genuinely ignored the budget below 2 GB and the comment explains exactly why. The ask is just that the appendix name it as a second shared-path change with its blast radius, rather than the byte-identical claim standing unqualified.
There was a problem hiding this comment.
You're right on both counts here — the appendix's "byte-identical" claim was written before the O6 commit landed and I never went back to qualify it. I've reworked that section of the body to name effective_chunk_size_mb as a second shared-path change with your blast-radius numbers (128MB → ~51MB chunks at 512MB budget, ~2.5× commit count, sizing-only — contents/index identical), and 95389a66f adds the same disclosure as a comment at the site so the next reader of import.rs doesn't need the PR body to know text imports under 2GB budgets are affected. Thanks for actually working the arithmetic — the 512MB example is now the canonical one in both places.
| let mut offset = 0usize; | ||
| loop { | ||
| let q = format!( | ||
| "SELECT ?s ?p ?o WHERE {{ ?s ?p ?o }} ORDER BY ?s ?p ?o LIMIT {PAGE} OFFSET {offset}" |
There was a problem hiding this comment.
OFFSET paging over the whole twin is O(n^2), and moves the memory cost onto the query side.
At 35M triples this is ~176 pages, and each page asks the engine for a full ORDER BY ?s ?p ?o over the entire twin and then skips M rows. Each page also materializes 200k bindings as serde_json::Value via to_sparql_json.
So the boundedness O2 won is real on the verify side (external sort, SORT_RUN_LINES runs) but the twin-read side is neither bounded nor linear. The addendum's 35.2M full-triple diff reads like an external same-renderer N-Triples export rather than a run of verify_twin_full, so I do not think this specific path has been exercised at that scale — worth confirming.
An index-ordered scan or the existing export path would give a single linear pass; spool_twin_ntriples is most of the way to re-implementing one already.
There was a problem hiding this comment.
Confirmed — your read was exactly right, and worth stating plainly: the 35.2M full-triple diff in the addendum was the external same-renderer export → sort → comm pipeline, not verify_twin_full; the OFFSET-paged path had never been exercised past test scale. d1a5d0904 replaces it with a single linear index-ordered pass (reusing the export-path scan shape feeding the existing external-sort/k-way machinery, which is more or less the "spool_twin_ntriples is most of the way there" observation implemented), and counts now come from bounded COUNT queries rather than full materialization. There's a hermetic multi-chunk twin test on the new path. The per-class seeded sampling in quick mode still does an ORDER BY ?s LIMIT 3 OFFSET N per class — same shape you flagged in the other note, bounded at 16 classes here — noted in-code rather than rewritten; happy to fold it into a follow-up if it ever grows teeth.
| let mapping = provider.compiled_mapping(graph_source_id, None).await?; | ||
| let classes = mapping_classes(&mapping); | ||
|
|
||
| let dir = std::env::temp_dir().join(format!( |
There was a problem hiding this comment.
std::env::temp_dir() may be tmpfs, which would undo the bounded-memory rewrite.
Full mode writes two complete N-Triples renderings of the graph plus their sorted runs here — tens of GB at the scales this builder targets. On many Linux hosts /tmp is tmpfs and therefore RAM-backed, so the verify that was just rewritten to be memory-bounded would put it all back in memory, on exactly the large datasets where it matters.
There is also no override. Suggest defaulting to the import's spool dir (or somewhere under .fluree) and adding a --tmp-dir. TmpDirGuard cleans up on drop but not on SIGKILL, which is a second reason not to leave GBs in a shared /tmp.
There was a problem hiding this comment.
Good catch — on a tmpfs host that would have quietly un-done the entire bounded-memory story at exactly the scales it was built for. d1a5d0904 defaults the verify spool under the target's .fluree storage area instead of std::env::temp_dir(), and adds --tmp-dir for operators who want it elsewhere. The SIGKILL-residue point is documented alongside (the guard cleans on drop; a hard kill leaves files, and having them under .fluree at least makes them discoverable rather than lost in a shared /tmp).
| /// under `materialize:watermark`. The whole stamp must fit the 64 KiB txn_meta | ||
| /// cap; a schema with a very large table count would need a compacter encoding | ||
| /// (documented residual). | ||
| fn encode_stamp( |
There was a problem hiding this comment.
The 64 KiB cap this doc comment asserts is not enforced on this path.
MAX_TXN_META_BYTES is checked in exactly two places — fluree-db-transact/src/parse/txn_meta.rs:407 and parse/trig_meta.rs:1398 — both of which validate txn-meta arriving from user TriG/JSON-LD. encode_stamp builds TxnMetaEntrys directly and hands them to finalize_parsed_chunk, so neither validator runs.
The watermark JSON grows with table count times metadata_location length; S3 metadata URIs plus JSON framing run roughly 350 bytes per table, so ~190 tables. That is not an unreasonable warehouse.
Every other guard on this path is fail-loud with a typed error (EmptyWatermark, ParentIndexBudgetExceeded). This one should be too, rather than a comment describing a cap and a downstream failure mode that is not stated.
There was a problem hiding this comment.
Agreed, and folded in per your call: d1a5d0904 enforces MAX_TXN_META_BYTES fail-loud before finalize with a typed StampTooLarge naming actual-vs-cap (and the table-count driver, since watermark size scales with tables × metadata-location length), consistent with EmptyWatermark/ParentIndexBudgetExceeded. There's a boundary test that builds a watermark just over the cap. Your ~190-table arithmetic is what convinced me this wasn't theoretical — that's a real warehouse.
| /// `Some` here (all three stamp fields present). Keys on the stable predicate | ||
| /// LOCAL NAMES (the namespace code is per-ledger); the local names are | ||
| /// materialize-specific, so requiring all three together identifies the stamp. | ||
| pub fn read_stamp(txn_meta: &[TxnMetaEntry]) -> Option<WatermarkStamp> { |
There was a problem hiding this comment.
This ignores the namespace that intern_meta_predicate was added to publish.
The reason GraphSink::intern_meta_predicate exists (and the reason encode_stamp routes the stamp predicates through the chunk's own sink) is so their namespace codes land in this commit's namespace_delta and resolve when the commit is read back. Then read_stamp matches on bare local names, so any commit carrying builderVersion + mappingHash + watermark string entries in ANY namespace parses as a valid twin stamp.
Given the stated contract is "a twin is valid iff a head-walk finds the stamp," it seems worth resolving the ns code and requiring it to be MATERIALIZE_NS. The information is already there by construction — the mechanism was built and then not used on the read side.
There was a problem hiding this comment.
This one stung a little because, as you said, the mechanism was built and then not used on the read side. d1a5d0904 fixes it: read_stamp now resolves the stamp predicates' namespace codes via the commit's namespace_delta and requires MATERIALIZE_NS — a commit carrying builderVersion/mappingHash/watermark local names in any other namespace no longer parses as a twin stamp. There's a forged-foreign-ns rejection test plus the round-trip.
| /// sink, so the stamp predicates' namespace codes publish in this commit's | ||
| /// namespace_delta. Every other chunk passes `None`, leaving `txn_meta` empty | ||
| /// (byte-identical to a text-import chunk). | ||
| pub fn build_virtual_chunk( |
There was a problem hiding this comment.
Vestigial after O3a — triples is now always empty.
Since the O3a commit removed the OwnedTriple intermediate, the only remaining call is build_virtual_chunk(&[], ctx, t, idx, Some(&stamp)) at line 1006. So the triples parameter is dead on every path, ImportSinkObserver exists solely to serve it (its only use is the loop at 335-337 that never iterates), and the OwnedTriple alias exists only to name the dead parameter.
All three are pub, so no dead-code warning fires and nothing will surface this later — precisely the rot the repo's dead-code policy is aimed at. Suggest build_stamp_chunk(ctx, t, idx, stamp) and deleting ImportSinkObserver + OwnedTriple, or keeping them with the #[expect(dead_code)]-style why/when comment the policy asks for.
There was a problem hiding this comment.
Cleaned up in d1a5d0904: build_stamp_chunk(ctx, t, idx, stamp) replaces the empty-slice call, and ImportSinkObserver + the OwnedTriple alias are deleted rather than annotated — you're right that pub was going to keep this invisible forever.
|
|
||
| /// Subjects per class fully compared by the stratified sample (deterministic: | ||
| /// the lexicographically first N subjects of each class). | ||
| const SAMPLE_SUBJECTS_PER_CLASS: usize = 3; |
There was a problem hiding this comment.
Worth surfacing in --help: the default gate's sample strength is three subjects per class. Combined with the class-count check that is a reasonable smoke test, but "quick verify" reads stronger than it is, and the CLI already prints an honesty note about the shared oracle — the sample size belongs in the same breath.
Separately, seeded_offset can put the window near the end of a class, so twin_sample_subject_iris issues ORDER BY ?s LIMIT 3 OFFSET N with N close to the class size — a full sort and skip per class. Fine at the sizes tested; the same shape as the full-mode paging note above.
There was a problem hiding this comment.
--verify help now states the quick-mode sample strength (three subjects per class + class counts) in the same breath as the shared-oracle honesty note. On the seeded_offset sort-and-skip shape: acknowledged as the same class as the full-mode paging note — the full-mode side is gone entirely (see the other thread), and the per-class variant is bounded by class count at sizes where it doesn't bite; left in place with a note rather than rewritten.
| entry | ||
| .entry(cols.clone()) | ||
| .or_default() | ||
| .insert(key, subject.clone()); |
There was a problem hiding this comment.
Last-wins on a duplicate parent join key. This MATCHES the generic query operator (R2rmlScanOperator's ParentLookup is also a plain HashMap<Vec<String>, RdfTerm>), so the twin agrees with the virtual path and the parity gate is right to pass — no divergence introduced here.
The reason it is still worth a note: the fused aggregate deliberately DECLINES this shape (insert_dim_gkeys returns false on any duplicate, with a comment explaining that a single-entry-per-key map cannot represent the fan-out), and materializing bakes the last-wins result into a permanent native ledger where fixing the operator no longer fixes the data. If the intent is that the twin is the durable artifact, a loud decline here — matching the fused path's posture — may be worth more than silent agreement with the deviation.
There was a problem hiding this comment.
Your instinct here turned out to be right for a stronger reason than durability. We put this one through a careful adversarial pass before deciding, and Claude's determinism analysis found the decisive fact: the last-wins pick was run-to-run nondeterministic — the parent index consumes scan_table's buffer_unordered stream, so when a duplicate key's colliding rows span data files, I/O completion order chooses the winner. Two runs over the same pinned snapshots could bake different twins, which breaks the mapping-hash/stamp reproducibility contract outright — so "silent agreement with the virtual path" wasn't actually agreement with any one graph.
5602938b4 lands the resolution: materialize now declines duplicate parent join keys by default with a typed error naming table/join-column/count, --allow-duplicate-parent-keys overrides (the MoR-guard pattern), and — the part I'd call the real fix — a deterministic keep-min tie-break (lexicographically smallest parent subject) now shared by BOTH the twin builder and the virtual path's build_parent_lookup, so the two agree and both are reproducible regardless of scan order. An override-built twin records its distinct ambiguous-key count in the stamp (distinct keys deliberately — a raw collision tally is itself order-dependent). The true RefObjectMap fan-out (one edge per matching parent) is now tracked as #1583; since twins are rebuildable, re-materialization heals any override-built twin once that lands.
| /// The env var read by fluree-db-iceberg's fail-closed merge-on-read guard. A | ||
| /// stable public contract (`fluree_db_iceberg::mor_guard::ALLOW_MOR_DELETES_ENV`); | ||
| /// hard-coded here so the CLI need not take a direct dependency on that crate. | ||
| const ALLOW_MOR_DELETES_ENV: &str = "FLUREE_ICEBERG_ALLOW_MOR_DELETES"; |
There was a problem hiding this comment.
The comment calls this a stable public contract, but a hard-copied literal with no compile-time link is the drift hazard the repo handles elsewhere with // SYNC: comments at both ends (the OTEL init pair in telemetry.rs / main.rs, and the Cypher "5.4.0" version string). A // SYNC: here and on mor_guard::ALLOW_MOR_DELETES_ENV would at least make a rename visible to whoever does it.
Note also that this file is #![cfg(feature = "iceberg")], and under that feature fluree-db-iceberg is already in the tree via fluree-db-api — so importing the constant may be cheaper than the comment suggests.
There was a problem hiding this comment.
You were right that the import is cheaper than the comment claimed — under #[cfg(feature = "iceberg")] the crate's already in the tree, so d1a5d0904 just imports ALLOW_MOR_DELETES_ENV through the fluree-db-api re-export and the hand-copied literal is gone.
Review #1529 fold-in #1 (id=3690216219). The O6 sub-2GB chunk-sizing rewrite resizes chunks for EVERY text import (Turtle/TriG/JSON-LD) whose memory budget is below 2048MB, not just materialize: at 512MB it goes 128MB -> ~51MB chunks (~2.5x the commit count, a different ledger shape). Name that shared-path blast radius at the site. Sizing only, never correctness. (The PR-body native-impact appendix is corrected separately.)
Folds in the lead-adjudicated inline items on the materialize verify and completion-stamp paths (single commit: these all live in materialize.rs and its entangled CLI/test files). - Full verify streams the twin in ONE linear pass over the binary index (the export scan_all shape), canonicalized as written, instead of the O(n^2) `ORDER BY ?s ?p ?o LIMIT N OFFSET M` wildcard paging that re-sorted the whole twin per page and moved cost onto the query side. Per-class counts come from bounded COUNT queries. Adds a hermetic multi-chunk full-mode test (ids=3690216222, 3690216241). - verify: `--tmp-dir` override + default the full-mode spool under the twin's `.fluree` storage area (never a tmpfs `/tmp`, which would undo the bounded-memory design); SIGKILL-residue documented (id=3690216229). - encode_stamp enforces the 64KiB txn-meta cap fail-loud with a typed StampTooLarge (actual vs cap + table-count driver) BEFORE finalize, consistent with EmptyWatermark/ParentIndexBudgetExceeded; boundary test (id=3690216231). - read_stamp requires the stamp predicates' ns code to resolve to MATERIALIZE_NS (via the commit's namespace_delta) — the local names alone are not a sufficient signature; a forged foreign-ns stamp is rejected; test (id=3690216235). - Delete dead O3a code: build_virtual_chunk(&[],..) -> build_stamp_chunk; drop ImportSinkObserver + the OwnedTriple alias (id=3690216238). - `--verify` help states the quick sample strength (3 subjects/class + class counts) alongside the shared-oracle honesty note (id=3690216241). - CLI references fluree-db-iceberg's mor_guard::ALLOW_MOR_DELETES_ENV (re-exported through fluree-db-api) instead of a hard-copied literal, so a rename shows up at the use site (id=3690216252).
Review #1529, "No docs" (approval body). Add docs/cli/materialize.md (synopsis, options incl. --verify modes with the shared-oracle honesty note, --tmp-dir, machine-safety posture, examples) and its SUMMARY.md entry. Document the twin / watermark / completion-stamp contract and the two verify modes, and the warehouse-root --table-location resolution rule, in docs/graph-sources/iceberg.md, with a cross-reference from r2rml.md.
…keep-min Adjudicated follow-up to bplatz's inline id=3690216248 (dupkey-adjudication.md, ruling C2). The last-wins pick on a duplicate parent join key was run-to-run NONDETERMINISTIC — the parent index consumes scan_table's buffer_unordered stream, so when a key's colliding rows span data files an I/O-completion race decided the winner, and baking one draw violated the twin's mapping-hash / stamp reproducibility contract. - Deterministic keep-min tie-break shared by BOTH parent-index builders: fluree-db-r2rml `ParentIndexSet::index_batch` (twin) and fluree-db-query `build_parent_lookup` (virtual path), via the shared `parent_key_insert_keep_min` — the lexicographically smallest parent subject wins, so twin and virtual agree AND both are reproducible regardless of scan order. Detection is free (HashMap occupancy); ambiguous keys are counted as DISTINCT keys (order-independent, unlike a raw collision tally). Shared both-feed-orders unit test. - Decline gate (C2): the twin builder refuses a source with duplicate parent keys by default, with a typed `DuplicateParentKeys` error naming the table(s), join column(s), and count; overridable via `--allow-duplicate-parent-keys` (CLI flag -> import builder option -> drive_virtual_import), mirroring the #1520 MoR-guard posture. Checked after the full index build, before the stamp, so a declined source never publishes a stamped twin. - `MaterializeStats.dup_parent_keys` + the completion stamp record the anomaly (a new OPTIONAL `dupParentKeys` stamp predicate, present only for an override-built twin, so a clean twin's stamp stays byte-identical) — the overridden twin self-documents what it baked. - Tests: decline fires; the override builds a deterministic twin (FK -> the keep-min winner in both batch orders) with the stat + stamp field set. Deferred to a tracked follow-up: the true R2RML RefObjectMap fan-out (one edge per matching parent) — a SHARED virtual+materialize bug; once it lands, re-materialization heals existing twins and the decline gate can relax to warn.
|
Thanks for this review, @bplatz — the local-verification legwork (full clippy + the 4,373-test run) on top of the inline notes is much appreciated. Everything is now folded in across The duplicate-parent-key note grew into the most substantive change of the set: an adversarial pass found the last-wins pick was run-to-run nondeterministic (I/O-completion order picks the winner across data files), so beyond your decline suggestion it now ships a deterministic keep-min tie-break shared by the twin builder and the virtual path — detail in that thread, fan-out tracked as #1583. On your process note re: the base branch — stated explicitly for whoever sequences the landing: #1554 (the |
…-fold Brings family-C's widened filter-over-join admission and #1529's keep-min parent-index change under the vectorized fold. merge-tree verified conflict-free; the semantic interaction (family-C shapes now folded through the borrowed-key dense-id path) is re-verified by the P1 differential and the fused_aggregate suite at this merged head.
…ouse single-table fallback MAJOR-2 (#1529 review): on the Direct path the pin is a 2s metadata cache and on REST with the loadTable cache off pinning is a documented no-op, so a source that commits mid-build yields a twin whose stamped watermark does not describe its contents. Cheap-loud fix: - IcebergCatalogSession.record_snapshot now records a table that yields a SECOND DISTINCT metadata_location into snapshot_conflicts (first-writer-wins still picks the pin); - R2rmlProvider gains a defaulted verify_build_snapshot_integrity (mock/test providers stay Ok); FlureeR2rmlProvider refuses when the loadTable cache is disabled and when any table moved snapshots; - drive_virtual_import calls it at build start (cache) and again before the completion stamp (conflicts), so no untrustworthy twin is ever stamped. MAJOR-3 (#1529 review): the warehouse-root detector splits the leaf on the FIRST '.', misrouting legitimate single-table Direct locations whose leaf dir does not name the table (a suffixed table dir, or a dir literally 'DW.FACT_ORDER'). When match_warehouse_table_dir misses AND the listing has a metadata/ child (every Iceberg table dir has one), treat it as a single table and return the location unchanged. Tests: record_snapshot_flags_second_distinct_metadata_location, listing_is_single_table_detects_metadata_child.
…p minors MAJOR-4 (#1529 review): two per-row/per-edge alloc sites O4 missed. - emit_batch: FK-edge counts accumulate in a per-POM Vec (a bare += 1), folded into stats.ref_edges ONCE per batch — the old per-edge entry((tm.iri.clone(), predicate.to_string())) did two heap allocs + a composite-String hash on every edge (and defeated the Cow::Borrowed hoist); templated ref predicates keep the per-edge path. - ParentIndexSet::index_batch: pre-create each col-set map once (get_mut by borrow in the row loop) instead of entry(cols.clone()) per row; pass the join key by value and re-read it only on the rare distinct-subject collision. MAJOR-5 (#1529 review): three verification gaps. - parent_index_budget_guard_trips_on_a_populated_index (the failure arm — the 'fails loud rather than OOM' promise was untested). - build_parent_lookup_keeps_min_subject_on_duplicate_join_key (the live-query keep-min semantics; last-wins would pick the other subject). - verify_twin_full_passes_on_multi_chunk_twin now asserts build.t > 1 so it's genuinely multi-chunk. Cheap minors adjacent to touched files: dupParentKeys read warns on a malformed (present) payload instead of reading back CLEAN (fail-open); verify spool dir gets a per-process atomic suffix (concurrent same-source verifies no longer share/delete each other's runs); the pack drop instruction + docs use the whole-ledger id + --force; the --memory-budget-mb 0=auto doc line corrected to the 512MB co-resident default; ImportConfig marked #[non_exhaustive].
…keys A GROUP BY on a referenced parent IRI (crt_highcard: GROUP BY ?c where ?c is edw:customer) declined the fused fold — scalar_column_for_var admits only a scalar column, so ?c fell to the generic per-row materialize path, which mints an RDF IRI for EVERY fact row (~58% of wall + the 8.7x RSS at SF1). Admit it in the single-table resolve_at_open: resolve the RefObjectMap, build an FK->IRI resolver by scanning the parent dimension ONCE (minting each parent subject via materialize_subject_from_batch exactly as build_parent_lookup does, with deterministic keep-min on a duplicate parent join key), then fold on that IRI through the existing Dim-sourced group-key machinery and emit it as an IRI term at output (new GKind::Iri => Binding::iri). The per-fact-row minting is gone — the mint cost moves to the O(dim) resolver build the generic path already pays — so the fold is byte-identical to the generic ?c binding while collapsing RSS. Design (team-lead approved, deviating from the charter's fold-on-FK/decline sketch where value-identity requires it): fold on the exact minted IRI (dodges the Decimal-lexical stringification-drift class of fold-on-FK), keep-min not decline (the generic query path resolves dup parent keys by keep-min post-#1529, so keep-min IS parity — declining would be slower parity). At most one ref group key (+ any fact-column keys via the mixed W4-2 model); >=2 ref keys decline as follow-on. A null/dangling FK drops the row, matching materialize_pom_object. #1583 (RefObjectMap fan-out) will change group multiplicity — a comment at the admission site flags that it must revisit this fusion IN THE SAME change. Tests (hermetic, end-to-end via open+next_batch over a mock provider): value-identity + dangling-FK drop; keep-min on a duplicate parent key (asserts the lexicographically smaller subject wins, byte-identical to build_parent_lookup); ~100k distinct-IRI cardinality exercising the dense-id dict.
…d-fold Puts the P3 soundness core on the true final tree. #1586 renamed the materialize spool tuple finish()->into_parts() (the #1529 x #1552 merge skew); this branch's pre-#1552 call sites are superseded by main's repaired versions (I never touched those lines, so git takes main's side cleanly). merge-tree verified conflict-free.
…came Rebasing onto main brought in #1552's GraphSink protocol, where finish() is a trait lifecycle method returning a result rather than the collector sink's accessor — the accessor is now into_graph(). Same rename-plus-old- caller seam class as the #1529 x #1552 materialize break: this branch's tests compiled standalone against their old base while the PR's merge result did not, which is why local suites were green while CI was red. All seven call sites move; every sink is an owned local at end of life, so the consuming accessor fits without restructuring.
…tadata arm
Finishes the 24-commit rebase onto `upstream/main` (452 commits of drift). Separate
from the replayed commits because every hunk here is a rebase-resolution artifact,
not a change of intent: nothing in this commit alters behaviour.
THE `parse_manifest_list` CORRECTION.
`send_planner.rs` needed one import added:
-use crate::manifest::{parse_manifest, parse_manifest_list_with_deletes};
+use crate::manifest::{parse_manifest, parse_manifest_list, parse_manifest_list_with_deletes};
That single line is the whole of what we spent three review rounds describing as
"fluree#1520 restructured `parse_manifest_list` away, so the rebase is blocked and there is
no mechanical resolution." @aaj3f refuted it in round 3 and was right:
`parse_manifest_list` is on `main` at `manifest/manifest_list.rs:153`, exported from
`manifest/mod.rs:21`, a one-line wrapper over `parse_manifest_list_with_deletes(data,
false)`. Our conflict resolution had taken main's import line while keeping our body,
and we then reported the resulting `cannot find function` as a fact about upstream's
code rather than about our own resolution. One `git show upstream/main:<path>` would
have settled it.
The rest:
- `auth/mod.rs` — `hydrate` gained a `GoogleMetadata` arm. Written OUT rather than
matched by a wildcard, deliberately: that exhaustiveness is what forced an explicit
redaction decision for this variant in fluree#1567, and a wildcard here would silently
accept the next variant too.
- `graph_source/config.rs`, `graph_source/r2rml.rs`, `ledger_info.rs` — three
functions/initializers left unclosed by a conflict that cut THROUGH a body. Both
sides ended mid-expression and shared the closing `}`, so taking both halves left
one closer for two items. Worth naming as a rebase hazard: a union is only safe
when each side is a whole item.
- `graph_source/r2rml.rs` — upstream's `gs_config_json` auth fixture gained
`delete: None, order_by: None`. Those fields are ours (`439908642`), so this is our
breakage of their test, and it surfaced ONLY under `--all-targets`: `cargo check`
does not build test targets. Same blind spot that took fluree#1567's first CI run down.
- `lib.rs` — export list unioned (`MaterializeResult`, `PersistedMaterializeJob` from
us; `verify_storage_access`, `StorageAccessReport` from upstream).
NOTE — fluree#1529 HAS MERGED. `fluree-db-api/src/materialize.rs` is now on main (3,174
lines: `materialize_graph`, `WatermarkStamp`, `ImportSink`/`ParsedChunk` ingestion,
parity gate), so the bulk-import engine this PR was asked to converge onto is no
longer a draft. Our replay engine now sits beside it, and there are two watermark
concepts in one codebase. That is a design conversation, not a rebase problem, but it
changes what this branch should become.
PER-COMMIT COMPILABILITY IS NOT RESTORED. The 24 replayed commits are individually
bisect-hostile until these hunks are folded into the commits they belong to. Left as
one commit on purpose: this branch is headed for the four-way re-split, so
`rebase -i` to make a soon-to-be-decomposed history bisectable is poor value. Say the
word and it gets folded.
Verified at this SHA, 0 behind `upstream/main`:
fluree-db-iceberg --lib 266 passed
fluree-db-api --lib 1014 passed
fluree-db-server --lib 167 passed
grp_graphsource 157 passed
it_graph_source_r2rml 65 passed
iceberg_track_durability 4 passed
cargo fmt --all -- --check clean
cargo clippy --all-features --all-targets clean (3 crates)
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
feat(materialize): fluree materialize — native-twin builder from virtual R2RML/Iceberg datasets
This is one of five surviving pull requests in the consolidated virtual-dataset review program, which collapses the #1475–#1529 lineage into five reviewable units at the maintainers' request. #1529 implements
fluree materialize: a bulk builder that turns a virtual R2RML-over-Iceberg graph source into a native Fluree ledger ("twin"), verifies it against the source, and writes it as a pack or a local ledger. It is the last member of the reading order. Since the consolidated body below was written, the previously-open live gate has been RUN AND PASSED (an independent full-triple diff against a natively-imported ledger at full 35.2M scale came back identical — see the acceptance section directly below), and a measured performance fix slate has landed on the branch; the sections below the acceptance report are the original consolidated body, kept intact for review continuity. Reading order across the program: #1520 (standalone MoR correctness fix) → #1507 (performance program) → #1514 (serverless Lambda-usability + BYO-IAM) → #1528 (big-Iceberg-audit implementation) → #1529 (this PR). The outward-facing audit record is on thedocs/virtual-dataset-audit-2026-07branch — the fact base for materializing Iceberg into native ledgers is in C3-materialization-facts.md and the strategy framing (with the snapshot-keyed correctness lemma) is in D1-strategy-options.md.2026-07-29 addendum — performance fix slate + full-scale acceptance (commits
74780fd25…476d08192)A stage-by-stage performance audit of this builder against the repo's own bulk-import path (
fluree create --from) found that bounded-by-design had been conflated with slow-by-implementation, and a measured fix slate landed here as eight commits on this branch (per the maintainers' one-PR consolidation rule). The audit's baseline, at equal bounds (--parallelism 2 --memory-budget-mb 1024, the 35,238,778-triple sf01 dataset over a Snowflake-managed REST catalog): build+publish 348.7s, and a verify phase that double-buffered the whole graph in RAM even in quick mode — 16.5GB RSS at 6.1M-triple dims scale, projected 95–155GB at 35M, i.e. certain OOM on the build host.The slate, in commit order on this branch: a merge-up of the consolidated program base (
74780fd25); produce-phase instrumentation spans (5e429a9fd); O2 — memory-bounded verify in both modes plus decimal value-canonicalization in the parity compare (9649c3e4d); O5 — concurrent table pin + Pass-1 FK pre-index bounded by--parallelism(2caec9194); O6 — budget honesty: sub-2GB budgets now scale the chunk size instead of silently flooring at 128MB, and the FK parent index is charged against the budget with a typedParentIndexBudgetExceededinstead of living outside it (03787651a); O4 — per-row allocation cleanup in the enumerator hot path, byte-identical across the r2rml exact-output suite (0e6cf38bb); O1 — a parallel produce side:--parallelismsync worker threads render/intern/encode with private sinks while the non-SendIceberg scans stay on the async driver, with an in-commit differential test asserting p=1 and p=2 produce identical triple sets, contiguous chunk indices, and exactly one stamped final chunk (e77bebc15); O3a — theOwnedTripleintermediate buffer removed, terms interned directly from the enumerator into the chunk sink (06e00004f); and a dateTime value-canonicalization fix in the verify compare (476d08192, receipt below). Review-response commits (bplatz, 2026-07-31):95389a66f+d1a5d0904+82b44631a— full-verify rewritten as a single linear index pass (the O(n²) OFFSET paging is gone), verify spool moved off possibly-tmpfs/tmpto under.flureewith a--tmp-diroverride, the 64KiB stamp cap now enforced fail-loud (StampTooLarge),read_stamprequires theMATERIALIZE_NSnamespace (foreign-ns stamp forgeries rejected), post-O3a dead code removed,--verifyhelp states quick-mode sample strength, the MoR env constant imported rather than hand-copied, anddocs/cli/materialize.md+ SUMMARY + graph-sources docs added per the repo docs mandate. Final review commit5602938b4— duplicate parent join keys:fluree materializenow DECLINES by default a source whose FK parent join key maps to more than one parent (typed error naming table/join-column/count), overridable with--allow-duplicate-parent-keys. Rationale: the prior last-wins pick was run-to-run NONDETERMINISTIC — the parent index consumesscan_table'sbuffer_unorderedstream, so when a key's colliding rows span data files an I/O-completion race chose the winner, and baking one draw violated the twin's mapping-hash / stamp reproducibility contract. The fix ships a deterministic keep-min tie-break (lexicographically smallest parent subject) shared by the twin builder and the virtual query path, so both agree and both are reproducible; an override-built twin records the distinct ambiguous-key count in its stamp (distinct-key counting deliberately, since a raw collision tally would itself be order-dependent). The true RefObjectMap fan-out (one edge per matching parent) is a tracked follow-up.Shared-path changes (correcting an earlier claim in this body that
ParsedChunk.txn_metawas the only one). Two functions on the shared text-import path change: 1.ParsedChunk.txn_meta— self-diff byte-identical for every text import (a data chunk emits empty txn_meta; only the twin's final stamp chunk populates it). 2.ImportConfig::effective_chunk_size_mb(previously unlisted) — the sub-2GB branch now derives chunk size from the budget instead of always applying the 128MB floor, resizing chunks for EVERY text import (Turtle/TriG/JSON-LD) withmemory_budget_mb < 2048. At 512MB / max_inflight=2: 128MB → ~51MB chunks (~2.5× commit count, different ledger shape, same input). Default budget ≈80% RAM, so most hosts land ≥2048MB and are unaffected; what changes is containers under ~2.5GB and any explicit--memory-budget-mbbelow 2GB (which the machine-safety posture encourages, and every finalizer-touching test uses at 256MB). Sizing only — commit contents/index identical, only chunk boundaries and count differ. 3.build_parent_lookupin fluree-db-query (the VIRTUAL query path) changes last-wins → deterministic keep-min on a duplicate parent join key — output-affecting ONLY on the duplicate-key shape that is nondeterministic today (an I/O-order-dependent arbitrary pick becomes a stable one); no effect on unique-key joins, which is the entire corpus. A ninth commit closes the recorded O5(c) residual (fa96388d3): tables are scheduled into topological waves so a non-cyclic FK parent is scanned exactly ONCE — its key→subject index is built during its own emit scan and frozen per-wave for the parallel workers — eliminating the separate pre-index pass that made cold fact tables the dominant wall; only cyclic/self-referential parents keep the pre-index fallback, and the quick gate's independent source re-scan is deliberately kept (its samples are chosen post-publish, so reusing build-pass statistics would let the build self-certify).Measured acceptance at full 35.2M scale (record: the A1/A2/B-REMEASURE documents of the materialize-perf audit series): verify now completes bounded where it previously OOM'd — the entire quick-verified 35M run peaked at 1.41GB RSS (dims scale: 16.46GB → 1.24GB, 13.3× less); a clean-load warm-cache build ran 56.0s wall with encode spread across both workers (the cold-source wall remains dominated by fact tables being scanned for Pass-1 indexing, Pass-2 emission, and the verify oracle — the recorded O5(c) follow-up on this branch, not a separate PR); and the independent oracle gate that kept this PR draft is now closed: a full-triple streaming diff (same-renderer N-Triples export of both sides → external sort → set compare, ~1.2GB RSS) between the materialized twin and the blessed natively-imported
enterprise-sf01ledger returned zero differences in either direction at 35,238,778 triples — the enumerator is proven correct against an oracle that is not itself.Two verify-gate false-reject classes were found by that acceptance run and fixed in the parity compare's value canonicalization: decimals (stored E-notation vs the oracle's plain
f64rendering) and dateTimes (storage pads fractional seconds to six digits,…T00:16:42.000000Z, while the oracle's formatter drops the fraction when zero — the gate now normalizes insignificant fractional-second zeros and zero UTC offsets on both sides). Both were fail-CLOSED failures — the gate refused correct twins and dropped them loudly, never the reverse. Known residuals, recorded here rather than deferred to other PRs: a non-zero-UTC-offset dateTime is deliberately not collapsed to its UTC instant (the schema under test is all-UTC); graph-source resolution is CWD-relative (./.fluree) and does not honorFLUREE_HOMEfor sources — a UX wart worth a look; and whether a first-class skip-verify mode for operators running their own independent diff deserves productizing is an open maintainer question.Original PR body
Base re-pointed by consolidation onto the family-C branch beneath it; no other PR's scope folded in — this survivor remains the standalone materialize builder, original text below.
fluree materialize— a native twin from a virtual (R2RML-over-Iceberg) datasetImplements the materialization design's first deliverable: bulk-build a native Fluree ledger ("twin") from a virtual R2RML-over-Iceberg graph source, verify it against the source, and write it as a
.flpackpack or a local ledger. This is the categorical fix identified by the materialization assessment — it ends the per-query cold-parquet storm and the admission-gate tail-chase for datasets that warrant a native copy, with guaranteed 1:1 native query semantics.First-principles per the AJ directive — zero anchoring to PR #1422; no transact-replay. The build reuses the existing bulk
create --fromfinalize → spool-sort → k-way-merge index → publish pipeline verbatim, pointed at the R2RML scan stream instead of a TTL parser.Design + assessment record: C3-materialization-facts.md (machinery + arithmetic) and D1-strategy-options.md (the strategy space).
What a reviewer should walk
The build is one new producer branch feeding an unchanged downstream. Read it in dependency order:
fluree-db-r2rml/src/materialize/graph.rs— the engine-freeTriplesMap → (s,p,o)whole-graph enumerator. Composes the SAME per-term helpers the query operator uses (term/datatype fidelity by construction), dims-first FK resolution.fluree-db-api/src/materialize.rs— scans each table through the enumerator, encodes byte-budgetedParsedChunks viaImportSinkObserver, ships them into the existing finalizer channel (ImportSource::Virtual).ac21c0711— per-table snapshot capture:IcebergCatalogSession.snapshotsrecorded at the singlescan_table_innercaller ofload_table_context(first-writer-wins),pinned_tables(gs),FlureeR2rmlProvider::build_watermarkoverride.fluree-db-api/src/graph_source/{catalog_session.rs,r2rml.rs}.fdcbc11f7— pin-all pre-pass (all snapshots pinned up front → cross-table skew bounded to seconds) +WatermarkStampassembly (watermark vector + SHA-256 mapping hash + builder version) + fail-loud empty-watermark guard.ee7897e1e— persist the completion stamp in the twin's FINAL commit:ParsedChunk.txn_meta(empty → byte-identical for every text import) +finalize_parsed_chunkconsume; the stamp is ns-encoded through the sink and rides the last non-empty commit via a one-chunk lookahead (completion-marker semantics: a valid twin is one whose head commit carries a parseable stamp).fluree-db-transact/src/{import.rs,import_sink.rs},fluree-db-query/src/r2rml/provider.rs.743f5e4ae— the post-build parity gateverify_twin: class counts + stratified per-subject sample (quick, always-on) and a full-triple diff (full), enumerator-as-oracle vs a native wildcard query, both rendered to identical N-Triples.bf27d545a— thefluree materializeCLI + MoR build-time UX.fluree-db-cli/src/commands/materialize.rs.Correctness proofs (all hermetic; no live runs in this PR)
materializer_driver_matches_engine_wildcard: the driver's triple set is byte-identical to the query engine's?s ?p ?owildcard over the same scan.materialize_builds_queryable_native_twin: a real indexed+published twin round-trips class counts, an FK edge to the parent IRI, anxsd:decimal(value+datatype), and a lang tag (value+@en).materialize_stamp_survives_pack_restore:archive_ledger → restore_ledgerpreserves the head-commit stamp byte-for-byte andread_stampparses it identically.verify_twin_passes_on_faithful_twin(pass,quick+full) andverify_twin_fails_on_corrupted_twin(an injected instance fails on both the class-count check and the full diff).Parity-gate value-semantics (ratified)
A parity gate asks "same graph in value space."
"5.00"^^xsd:decimaland"5"^^xsd:decimalare one value; comparing pre-intern lexical (enumerator) against post-intern canonical (twin) is a diff artifact, not a data defect. The gate strips trailing fractional zeros for xsd numeric datatypes on both sides. Where lexical renderings genuinely differ for the same value, the twin's native rendering is contract-correct by the parity direction (native is the fixed contract) — so any client-observable decimal-lexical drift on cutover is the virtual path shedding a deviation, not the twin introducing one. The lead-run live native-sf01 full-triple diff must carry the same value-level canonicalization.Gate record
fmtclean; scopedclippy0 new warnings;cargo check -p fluree-db-api --no-default-features --features aws,iceberg,shacl(no-native featureset) compiles; CLI compiles with and withouticeberg. Tests: fluree-db-transact lib 303, fluree-db-query lib 116, fluree-db-api materialize lib 6,it_graph_source_r2rml60 (2 ignored ext-infra), fluree-db-cli materialize helpers 5.Machine-safety posture
The CLI default is co-resident-tolerant (fixed
parallelism=2,memory_budget_mb=512, never own-the-box auto-sizing);--memory-budget-mb/--parallelismraise it explicitly,--max-performanceopts into host auto-sizing on a cleared machine. Every finalizer-touching test runs withthreads=2+memory_budget_mb=256. Verification uses publish-then-verify-then-drop: the gate needs a queryable twin, so a failed gate drops the twin — nothing unverified stays announced. (Deliverable-2 rider: solo's alias repoint must sequence strictly AFTER gate-pass.)Residuals (deferred, tracked)
key → parent-subject-term(general); the exists-set + apply-parent-template form saves memory when parent subject-template columns ⊆ the join key. Guarded byMaterializeStats.ref_edgesper-(child,predicate) counts. Not trivial → left as a guarded-threshold note.block_onoff a dedicated thread); a runtime-flavor-agnostic async-task → bridge-thread producer is deferred until a caller needs it.--output s3— not yet wired in the file-backed CLI (rejected up front). The direct-S3 CAS publish path exists (designed and verified CAS-safe); it needs an S3-backed home the CLI does not construct.read_task_sample-bounded sample is the scale follow-up.Package-end gate (lead-run, not in this PR): the live native-sf01 full-triple diff and any live build against Snowflake. No live runs were performed here.
Warehouse-root direct resolution (follow-on, AJ live-gate registration-gap fix)
bf27d545a→6fcf7fc64. The local CLI's Direct mode was single-table, blocking registration of a multi-table R2RML source over a catalog-less bucket copy (a Snowflake-managed Iceberg database whose table dirs carry random suffixes,fact_order.UIHGsQex/). Now a Direct--table-locationmay be a warehouse ROOT: auto-detected when its leaf dir doesn't name the requested table, eachrr:tableNameresolves to its own dir under the root via one session-cached S3 LIST (SendIcebergStorage::list_dir), matched by the purematch_warehouse_table_dir(<name>.<suffix>/or bare<name>/, case-insensitive, namespace-stripped). Ambiguity/miss fails loud naming the candidates. Single-table direct is byte-unchanged (self-diff), no new flag / config change (rule documented iniceberg map --help). Registration shape:fluree iceberg map <name> --mode direct --table-location s3://bucket/warehouse/dw --s3-region <r> --r2rml <ttl>— pure ambient IAM, zero catalog/OAuth. Hermetic: 5 match tests; iceberg lib 251, api it_graph_source_r2rml 62 green. The live S3 LIST is part of the lead-run gate.Consolidated scope
#1529 folds in no other pull requests. It implements the native-twin builder set out in the materialization design record and was built first-principles, reusing the existing bulk-ingestion finalize → spool-sort → k-way-merge → publish pipeline pointed at the R2RML scan stream. Its pre-consolidation tip is preserved at tag
archive/pre-refactor-2026-07-21/feat_materialize-builder; nothing was rewritten. Its base is re-pointed onto the family-C branch beneath it (perf/family-c-filter-join), which is a sibling of the fork point, so the diff renders builder-only while GitHub notes the base is some commits ahead.Verification of record
Every proof in this PR is hermetic; the live gate is deferred and is the basis for the draft status.
The hermetic proofs, all green:
materializer_driver_matches_engine_wildcard(the driver's triple set is byte-identical to the query engine's?s ?p ?owildcard over the same scan);materialize_builds_queryable_native_twin(a real indexed and published twin round-trips class counts, an FK edge, anxsd:decimal, and a lang tag);materialize_stamp_survives_pack_restore(archive→restore preserves the head-commit stamp byte-for-byte); and the parity-gate pairverify_twin_passes_on_faithful_twinandverify_twin_fails_on_corrupted_twin(an injected instance fails on both the class-count check and the full diff). The independent adversarial review is recorded under R-1529 in pr-reviews-impl.md: verdict SHIP (draft) with no blocking finding — the shared text-import path is byte-untouched, the completion stamp rides the structurally-final commit so partial builds are detectable, the CLI'sBox::leakis shell-only and one-per-process, and every fail-loud guard fires. The review's load-bearing observation, which a reader must internalize: the parity gate is an ingestion-integrity gate, not an enumerator-correctness gate — its oracle is the enumerator, so a fault in the enumerator itself is only caught by the deferred live native-sf01 diff.The build/serve/sync arithmetic and the pack substrate anchors are in C3-materialization-facts.md; the native-twin-promotion strategy and its snapshot-keyed correctness lemma are in D1-strategy-options.md.
Native-impact appendix
ParsedChunk.txn_metaplus afinalize_parsed_chunkconsume land on the shared bulk import / transact path (fluree-db-transact/src/import.rsandimport_sink.rs). Every text-importParsedChunksite setstxn_meta = Vec::new()(parse_chunk, the ndjson constructor, andfinalize), andis_virtual = config.virtual_source.is_some()is false for all file and remote imports; the newImportSource::Virtualarm is inserted before the remote-parallel path with no existing body touched. Theimport.rsdiff is 138 insertions / 1 deletion (the only change to an existing line isis_channel_fedgaining|| is_virtual). Thebuild_watermarktrait default is empty, so non-materialize providers are unaffected, andrecord_snapshotis fire-and-forget first-writer-wins with no extra I/O. Verified: transact lib 303 + import 10 green, andmaterialize_stamp_survives_pack_restore.fluree-db-r2rml/src/materialize/graph.rs,fluree-db-api/src/materialize.rs, the CLI, and the warehouse-rootlist_dir) compose the shared per-term helpers the query operator uses without modifying them.Confirmed negatives (git-checked): no
arrow/datafusion/parquetdependency bump, and no.github/workflowsorrust-toolchainedits.Draft status and open gates
This PR is deliberately a draft. Two gates are open and both must be run before any live cutover relies on the twin:
Until both are exercised, the builder invites hermetic review as a draft with the live parity gate stated as pending; it should not be flipped ready on the hermetics alone.