Repository navigation
feat: stable _:fdb blank-node ids addressable in queries and updates - #1432
Merged
Merged
Conversation
…d updates Fluree skolemizes every blank node into the reserved _:fdb-... label space at insert time, and queries already resolved those labels to the stored Sid (canonical_split routes any _: string to the blank-node namespace). Writes, however, re-skolemized them: round-tripping an _:fdb-... id from a query silently minted a fresh node, and a SPARQL DELETE naming one retracted nothing. Blank-node-rooted structures (OWL restrictions, address objects) could only be edited by retracting and re-asserting the whole subtree. Labels with the reserved fdb- prefix now denote the existing stored node everywhere (RDF 1.1 §3.5 skolemization kept in blank-node syntax): - JSON-LD templates: parse_expanded_id_with_ctx and VALUES @id resolve stable ids to constant Sids - SPARQL SELECT WHERE: stable labels lower to constants; other labels stay non-distinguished variables per spec - SPARQL UPDATE: INSERT/DELETE templates, DELETE DATA/INSERT DATA, and DELETE WHERE (both pattern and template sides) resolve stable ids - Turtle: FlakeSink::term_blank passes stable labels through - Edge annotations: delete-by-@id now accepts stable ids (they are addressable), still rejects client-authored blank labels Ordinary labels (_:b0) keep standard semantics: fresh node per transaction on write, existential variable in SPARQL WHERE. Clients cannot collide with the reserved space because transaction skolemization wraps client labels with a txn id before prefixing fdb-. All checks happen at parse/lowering time (once per term, inside the existing _:-prefixed branches), never in per-solution template instantiation, so transactions that don't use stable ids pay nothing. W3C SPARQL eval: 283/327 before and after (no regression).
Named-graph blanks in bulk TriG/N-Quads import were skolemized from the
bare label (fdb-b0) while the same document's default graph used the
ImportSink key (fdb-{ledger}-{t}-{label}). Two consequences, both wrong
under TriG's document-wide label scoping:
- _:b0 in a GRAPH block and _:b0 in the default graph of the SAME
document became two different nodes
- _:b0 in GRAPH blocks of DIFFERENT documents (files, commits, or later
imports into the same ledger) collapsed into one globally shared node
expand_term/expand_object now take the commit's txn_id and mint
{txn_id}-{label}, matching ImportSink::skolemize, so a label unifies
across the default graph and GRAPH blocks of one document and stays
distinct across documents.
Also extends stable _:fdb- id support to the upsert/insert-turtle
named-graph path (convert_named_graphs_to_templates), which was the one
write path still skolemizing stable ids fresh; ordinary labels keep
fresh-mint semantics there.
The regression test uses variable-predicate scans because bound-
predicate patterns return empty on freshly bulk-imported ledgers — a
pre-existing quirk unrelated to blank nodes, reproduced with this fix
fully reverted.
…d allocator The serial import commit functions (import_trig_commit, and import_commit via the no-GRAPH-blocks TriG fallback) allocated namespace codes only in state.ns_registry. SpoolContext resolves code->prefix through the SHARED allocator at record-push time — mid-parse, right after an @Prefix directive allocates the code — and silently falls back to an empty prefix on a miss. The index's predicate dictionary then permanently stored bare suffixes ("name" instead of "http://schema.org/name"), so bound-predicate patterns matched nothing on freshly imported ledgers and results rendered suffix-only predicates. The orchestrator's sync_from_registry after each commit was too late by construction. Serial commit fns now mirror parse_chunk's allocator discipline: ImportSink::new_cached over a WorkerCache backed by the spool's shared allocator, named-graph expansion helpers take the WorkerCache, and each commit's new codes merge back into the registry via lookup_codes + adopt_delta_for_persistence before take_delta() builds the commit's namespace_delta. Without a spool, a throwaway allocator seeded from the registry preserves identical code assignment. Pure-Turtle files were never affected (they go through parse_chunk).
SpoolContext's code->prefix resolution silently fell back to an empty prefix when the shared allocator didn't know a namespace code — the failure mode behind the suffix-only predicate dict entries fixed in the previous commit, which corrupted the index without any signal. A miss for a real (non-OVERFLOW) code now debug_asserts, so any test exercising a misallocated path fails immediately, and warns in release instead of corrupting silently. OVERFLOW Sids keep the empty prefix (they legitimately carry the full IRI in the name). Adds a should_panic unit test pinning the detection, and rewires the three spool unit tests that hand-built the old registry-only allocation pattern onto the production WorkerCache-over-shared-allocator wiring.
aaj3f
approved these changes
Jul 5, 2026
aaj3f
left a comment
Contributor
There was a problem hiding this comment.
Makes sense and looks good! 👍
The trig2 literal has no inner double quotes, so `r#"…"#` tripped clippy::needless_raw_string_hashes under -D warnings on CI. Use a plain `r"…"`. trig1 keeps its hashes — it contains a quoted literal.
This was referenced Jul 29, 2026
aaj3f
added a commit
that referenced
this pull request
Aug 3, 2026
Five GraphSink implementations in fluree-graph-format, so a parser can emit
straight into an output syntax with nothing materialized in between. This is
the bridge the fluree rdf effort was scoped around: everything upstream
produces GraphSink events, and until now nothing consumed them into bytes.
NTriplesWriter / NQuadsWriter — one statement per line, O(1) memory.
TurtleWriter / TrigWriter — the blocks tier: consecutive same-subject runs
fold with ';', same-subject-and-predicate with ',', document order otherwise.
No cross-document regrouping, no [ ] reconstruction, no ( ) re-collapse; all
three need the whole document in memory, which is what a streaming writer
exists not to need. A buffered --pretty tier is the follow-up, and riot draws
the same line.
JsonLdWriter — document mode over the existing format_jsonld, O(document) and
said so in the type docs rather than implied by silence.
TriG writes quads where they arrive, reopening a GRAPH block when the input
returns to a graph it left. That is valid TriG — a graph is the union of its
blocks — and it keeps memory O(1) against interleaved input, where buffering
per graph would be O(dataset). Input already grouped by graph still gets one
block per graph, so the tidy case costs nothing.
Blank-node policy (plan H-6): relabel by default to a fresh b{N} per input
label, with _:fdb- passing through verbatim for #1432's addressability
contract. Disjointness is by construction, not by check: every output label is
either a b{N} mint or begins fdb-, and no mint does. --preserve-bnode-labels
emits labels verbatim and mints anonymous nodes into a reserved fdbw-
namespace; there disjointness cannot be established by construction, so an
input label inside that namespace is refused rather than allowed to merge, as
is one that cannot lex as a BLANK_NODE_LABEL.
Two refusals worth calling out. Named-graph events against a triple-only
writer are refused via the capability probe rather than flattened. Indexed
list items are refused by the text writers — one triple where RDF means three
is data loss — but kept by JsonLdWriter, because JSON-LD has @list to say it
with.
abort_statement is honest about what it can do: unbuffered, bytes already
handed to the writer stay written; WriterConfig::buffer_statements makes it a
true rollback at O(widest statement), which is what --continue-on-error will
need. Turtle's run state rolls back with it, so a rejected statement leaves no
half-open subject.
Round-trip tests parse with the real Turtle parser on both ends and compare
under a blank-node bijection; blank-node identity counts are checked
separately, since isomorphism cannot see a merge. Lexical fidelity is pinned
for +1, 01, 1.0, 1e0 and a bignum, which is why literals are always written
fully quoted and typed rather than in Turtle's numeric shorthand.
aaj3f
added a commit
that referenced
this pull request
Aug 3, 2026
The architecture the G1b measurement called for. Each worker runs its own
writer into a byte buffer and the driver concatenates in chunk order; there is
no shared relabeller and therefore no serial replay, which was ~half the wall
clock of the collect-then-replay design this replaces.
What makes that sound is the label scheme, which is a pure function of (label,
chunk) so workers need no coordination:
- a user's `_:L` becomes `u{L}` — prefixing is injective, so distinct labels
stay distinct, and the same label in two chunks maps to one output label,
which is what document scoping requires;
- an anonymous node in chunk `c` becomes `g{c}_{n}` — disjoint across chunks
by `c`, within a chunk by `n`;
- `_:fdb-…` passes through verbatim, keeping #1432's addressability contract.
The three classes are disjoint by first character rather than by check, and a
user label that imitates a mint is no threat: `_:g0_1` becomes `ug0_1`.
Reassembly is bounded, not "join everything then write". Workers deposit into a
channel whose capacity is at least the worker count — so a worker can never
block holding the chunk the writer is waiting for — and out-of-order arrivals
wait in a reorder buffer. Peak memory is roughly (workers + capacity) × chunk
output, not the whole output.
THE DIFFERENTIAL GATE IS NOW THREE LAYERS, replacing cross-mode byte equality,
which this design deliberately gives up (riot makes no cross-mode byte promise
either):
(a) determinism — same input, same K, byte-identical across runs. Thread
scheduling cannot reach the output, because labels depend on chunk index
and chunks concatenate in order.
(b) equivalence — serial and parallel agree on triple count and on the
number of distinct blank nodes, and a labelled node spanning chunks is
still one node. The byte-identical collect-then-replay implementation is
kept as the oracle side.
(c) adversarial — ten bait labels imitating every pattern the scheme itself
produces (`b1`, `g0_1`, `g7_3`, `u1`, `ug0_1`, `ufdb-x`, `fdbw-1`,
`c0_1`), each keeping its own identity.
The parallel path reports no sink estimate rather than a fabricated one: each
worker has its own writer and no single instrument saw them all.
aaj3f
added a commit
that referenced
this pull request
Aug 5, 2026
Bulk import skolemized labeled blank nodes from the per-chunk commit id
(`{ledger}-{t}`), so `_:x` in chunk 1 and `_:x` in chunk 7 of ONE Turtle
file became two different subjects. RDF scopes blank-node labels to the
document that contains them; one .ttl file is one document.
This is the chunked-Turtle sibling of the TriG bug fixed in #1432, which
established the rule that "a label unifies across one document and stays
distinct across documents". #1432 fixed the named-graph/cross-document
half; the shipping parallel Turtle path still split labels the other way.
The skolemization key is now supplied by the layer that knows how chunks
map onto input files. Producers tag every chunk with the index of the
source document it was cut from; `parse_chunk` turns that into the sink's
`skolem_base` (renamed from `txn_id`, which it no longer is). No
cross-worker coordination is involved: `blank_node_sid` is a pure
function of the key, so two threads parsing chunk 1 and chunk 7 derive
the same Sid independently.
Per arm:
- single-file streaming: every chunk is document 0
- local directory rechunk: the file index, so a sub-split file's chunks
share a scope and two files never do. A coalesced payload reports its
first file, which is sound because `coalesce_unsafe` already refuses to
coalesce any file containing a `_:` label
- Files / remote objects / ndjson: one whole document per chunk, so the
chunk index is already a correct document scope
- serial TriG/N-Quads commits are unchanged — one call is one document
ANONYMOUS nodes need the opposite treatment, and sharing a skolem base
across chunks breaks them unless the mint changes too. Their label came
from a counter that restarts in every sink (one per chunk), so a
document-shared base would make chunk 0's Nth anonymous node and chunk
1's Nth the same subject. Statement-local means nothing can *reference*
such a node from elsewhere; it does not stop two of them from colliding
on an id. The mint now carries `t` (`-b{t}-{N}`), which is unique per
chunk; the leading `-` still keeps the minted space disjoint from user
labels, which cannot begin with `-`.
Tests: `import_ttl_blank_label_scoped_across_chunks`,
`import_ttl_blank_labels_distinct_across_files` and
`import_ttl_anonymous_nodes_distinct_across_chunks` (one 1.5 MB file,
1 MB chunks, 2 parse threads) each fail before the corresponding half of
this change. `import_ttl_blank_labels_distinct_across_small_files` pins
the coalescing guarantee, with the threshold lowered so coalescing
actually engages. `import_directory_blank_nodes_not_coalesced` now
counts distinct subjects rather than names — counting names cannot
detect a merge, since a merged node simply carries both.
aaj3f
added a commit
that referenced
this pull request
Aug 6, 2026
Five GraphSink implementations in fluree-graph-format, so a parser can emit
straight into an output syntax with nothing materialized in between. This is
the bridge the fluree rdf effort was scoped around: everything upstream
produces GraphSink events, and until now nothing consumed them into bytes.
NTriplesWriter / NQuadsWriter — one statement per line, O(1) memory.
TurtleWriter / TrigWriter — the blocks tier: consecutive same-subject runs
fold with ';', same-subject-and-predicate with ',', document order otherwise.
No cross-document regrouping, no [ ] reconstruction, no ( ) re-collapse; all
three need the whole document in memory, which is what a streaming writer
exists not to need. A buffered --pretty tier is the follow-up, and riot draws
the same line.
JsonLdWriter — document mode over the existing format_jsonld, O(document) and
said so in the type docs rather than implied by silence.
TriG writes quads where they arrive, reopening a GRAPH block when the input
returns to a graph it left. That is valid TriG — a graph is the union of its
blocks — and it keeps memory O(1) against interleaved input, where buffering
per graph would be O(dataset). Input already grouped by graph still gets one
block per graph, so the tidy case costs nothing.
Blank-node policy (plan H-6): relabel by default to a fresh b{N} per input
label, with _:fdb- passing through verbatim for #1432's addressability
contract. Disjointness is by construction, not by check: every output label is
either a b{N} mint or begins fdb-, and no mint does. --preserve-bnode-labels
emits labels verbatim and mints anonymous nodes into a reserved fdbw-
namespace; there disjointness cannot be established by construction, so an
input label inside that namespace is refused rather than allowed to merge, as
is one that cannot lex as a BLANK_NODE_LABEL.
Two refusals worth calling out. Named-graph events against a triple-only
writer are refused via the capability probe rather than flattened. Indexed
list items are refused by the text writers — one triple where RDF means three
is data loss — but kept by JsonLdWriter, because JSON-LD has @list to say it
with.
abort_statement is honest about what it can do: unbuffered, bytes already
handed to the writer stay written; WriterConfig::buffer_statements makes it a
true rollback at O(widest statement), which is what --continue-on-error will
need. Turtle's run state rolls back with it, so a rejected statement leaves no
half-open subject.
Round-trip tests parse with the real Turtle parser on both ends and compare
under a blank-node bijection; blank-node identity counts are checked
separately, since isomorphism cannot see a merge. Lexical fidelity is pinned
for +1, 01, 1.0, 1e0 and a bignum, which is why literals are always written
fully quoted and typed rather than in Turtle's numeric shorthand.
aaj3f
added a commit
that referenced
this pull request
Aug 6, 2026
The architecture the G1b measurement called for. Each worker runs its own
writer into a byte buffer and the driver concatenates in chunk order; there is
no shared relabeller and therefore no serial replay, which was ~half the wall
clock of the collect-then-replay design this replaces.
What makes that sound is the label scheme, which is a pure function of (label,
chunk) so workers need no coordination:
- a user's `_:L` becomes `u{L}` — prefixing is injective, so distinct labels
stay distinct, and the same label in two chunks maps to one output label,
which is what document scoping requires;
- an anonymous node in chunk `c` becomes `g{c}_{n}` — disjoint across chunks
by `c`, within a chunk by `n`;
- `_:fdb-…` passes through verbatim, keeping #1432's addressability contract.
The three classes are disjoint by first character rather than by check, and a
user label that imitates a mint is no threat: `_:g0_1` becomes `ug0_1`.
Reassembly is bounded, not "join everything then write". Workers deposit into a
channel whose capacity is at least the worker count — so a worker can never
block holding the chunk the writer is waiting for — and out-of-order arrivals
wait in a reorder buffer. Peak memory is roughly (workers + capacity) × chunk
output, not the whole output.
THE DIFFERENTIAL GATE IS NOW THREE LAYERS, replacing cross-mode byte equality,
which this design deliberately gives up (riot makes no cross-mode byte promise
either):
(a) determinism — same input, same K, byte-identical across runs. Thread
scheduling cannot reach the output, because labels depend on chunk index
and chunks concatenate in order.
(b) equivalence — serial and parallel agree on triple count and on the
number of distinct blank nodes, and a labelled node spanning chunks is
still one node. The byte-identical collect-then-replay implementation is
kept as the oracle side.
(c) adversarial — ten bait labels imitating every pattern the scheme itself
produces (`b1`, `g0_1`, `g7_3`, `u1`, `ug0_1`, `ufdb-x`, `fdbw-1`,
`c0_1`), each keeping its own identity.
The parallel path reports no sink estimate rather than a fabricated one: each
worker has its own writer and no single instrument saw them all.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Labels with the reserved
_:fdb-prefix (the skolem ids Fluree mints for every blank node and returns from queries) now denote the existing stored node in queries and transactions, instead of silently minting a fresh node. This makes blank-node-rooted structures — OWL restrictions, address objects, RDF lists — editable in place: query the node's id, then use it as an ordinary@idto insert/delete individual triples, without retracting and re-asserting the whole subtree.The read side already resolved
_:fdb-...to the stored Sid (canonical_splitroutes any_:string to the blank-node namespace); this closes the write side and SPARQL:@id: "_:fdb-..."in insert/update templates and VALUES addresses the stored node_:fdb-...in WHERE patterns lowers to a constant; ordinary labels stay non-distinguished variables per specDELETE DATA/INSERT DATA, andDELETE WHEREall resolve stable ids (a bnode in a DELETE template was previously skolemized fresh, i.e. a silent no-op)FlakeSink::term_blankand the upsert named-graph path pass stable labels throughOrdinary labels (
_:b0) keep standard RDF semantics: fresh node per transaction on write, existential variable in SPARQL WHERE. Clients cannot collide with the reserved space because skolemization wraps client labels with a txn id before prefixingfdb-. All checks run at parse/lowering time inside existing_:-prefixed branches — zero cost for transactions not using stable ids.Spec framing: this is RDF 1.1 §3.5 skolemization kept in blank-node syntax — the same extension Virtuoso's
nodeID://refs and Jena's<_:label>syntax provide. SPARQL §3.1.3's ban on blanks in DELETE templates exists because such labels could only denote fresh nodes; the reserved prefix removes that premise.Import fixes (found while auditing blank-node scoping)
fdb-b0) — colliding globally across every document imported into a ledger while diverging from the same document's default graph (fdb-{ledger}-{t}-b0). They now share the default graph's skolem key, so a label unifies across the default graph and GRAPH blocks of one document and stays distinct across documents.state.ns_registry, invisible to the spool's mid-parse code→prefix lookups. The silent empty-prefix fallback permanently wrote suffix-only strings (nameinstead ofhttp://schema.org/name) into the index's predicate dict — bound-predicate patterns matched nothing on freshly imported TriG ledgers. Serial commits now mirrorparse_chunk's WorkerCache-over-shared-allocator discipline, and the fallbackdebug_asserts (warns in release) so any recurrence fails tests loudly instead of corrupting silently.Testing
it_stable_blank_nodes.rs— 7 tests: in-place OWL-restriction edits via JSON-LD and SPARQL, node identity stable across edits, fresh-mint semantics preserved for ordinary labels, constant-vs-variable WHERE behaviorit_import.rs—import_trig_blank_label_document_scoped(fails pre-fix) andimport_trig_bound_predicate_queryable(fails pre-fix);should_panicunit test pins the spool prefix-miss detectionDocs
_:fdb-Ids)" section indocs/transactions/update-where-delete-insert.md, with pointers frominsert.mdandconcepts/iri-and-context.md