Repository navigation
fix(materialize): the parity gate reads "1"^^xsd:boolean as true - #2447
Conversation
A 0/1 column typed xsd:boolean renders "1" and "0" on the source side,
while the twin stores the boolean and answers "true" and "false". The
gate's canonicalizer only rewrote numeric and temporal literals, so every
such triple came back as a missing/extra pair and both --verify quick and
--verify full dropped a twin that held the right values.
canonicalize_value_nt now has an xsd:boolean arm that maps "1" to "true"
and "0" to "false" on both sides. Only the four forms
coerce_string_value parses as a boolean collapse; anything else (" 1",
"TRUE", "yes", "2") is kept as text by an import and still has to match
byte for byte, and only the xsd:boolean IRI is touched.
Tests: a unit test beside the other canonicalizer tests, and
verify_twin_passes_on_a_zero_one_column_typed_boolean, which builds a
twin from a long and a decimal(1,0) column typed xsd:boolean, checks it
holds booleans, passes Quick and Full, and fails both once one flag is
flipped. Without the new arm it fails the way the issue describes (each
sampled subject a TripleDiff).
Fixes #2386.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
bplatz
left a comment
There was a problem hiding this comment.
Approving. Please review the inline comments before merging.
| fn normalize_boolean_lexical(lex: &str) -> &str { | ||
| match lex { | ||
| "1" => "true", | ||
| "0" => "false", | ||
| other => other, | ||
| } | ||
| } |
There was a problem hiding this comment.
Optional: this copies coerce_string_value's boolean arm, which is what the import uses. Calling it keeps the gate and the import in step if that arm ever changes:
| fn normalize_boolean_lexical(lex: &str) -> &str { | |
| match lex { | |
| "1" => "true", | |
| "0" => "false", | |
| other => other, | |
| } | |
| } | |
| fn normalize_boolean_lexical(lex: &str) -> &str { | |
| match fluree_db_core::coerce::coerce_string_value(lex, fluree_vocab::xsd::BOOLEAN) { | |
| Ok(fluree_db_core::FlakeValue::Boolean(true)) => "true", | |
| Ok(fluree_db_core::FlakeValue::Boolean(false)) => "false", | |
| _ => lex, | |
| } | |
| } |
There was a problem hiding this comment.
Agreed, this is better. It really was a straight copy of the boolean arm, so if coerce_string_value ever picked up another form, the gate would quietly start disagreeing with the import and we'd be back to missing/extra pairs. Took your suggestion as-is in cd8b7c8, and reworded the doc comment above it so it says the parse is the write path's own, rather than listing the four forms as though the gate owned them.
I did double-check the premise first: an import really does go through coerce_string_value for typed literals (fluree-db-transact/src/value_convert.rs and the raw_reader.rs decode both call it), so this keeps the two in step for real. The boolean_one_and_zero_canonicalize_to_true_and_false unit test and the five verify_twin_* tests in it_graph_source_r2rml still pass.
…_string_value normalize_boolean_lexical copied coerce_string_value's xsd:boolean arm. It now calls it, so the parity gate and the import read a boolean lexical form the same way if that arm ever changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Brings #2418, #2419 and #2447, each of which applies to next. - #2418 (frame lengths checked): every frame encoder returns PackResult and writes nothing on FrameTooLarge, next's own included. The erasure and authorization frames go through the checked JSON encoder with the manifest, the erasure artifact frame checks its length, and the erasure transfer's frames, its archive manifest and the retention journal manifest propagate the error. The stream's error path and next's retention-section error path share main's fallback, an Error frame with a short message, in encode_error_frame_or_short. The CLI's remote splice keeps next's erased-history manifest. main's archive test creates its ledger, as a commit needs on next. - #2419 (the ?var = <const> memo keyed by the constant): applies as is. Its test seeds through next's async genesis_ledger. - #2447 (the parity gate reads "1"^^xsd:boolean as true): applies as is.
Fixes #2386.
A mapping that types a 0/1 column as
xsd:booleancouldn't be materialized: the source side renders the cell as"1"^^xsd:boolean, the twin stores the boolean and answers"true"^^xsd:boolean, andcanonicalize_value_ntonly rewrote numeric and temporal literals, so every one of those triples was a missing/extra pair and both--verify quickand--verify fulldropped a twin that held the right values.What changes
canonicalize_value_nt(fluree-db-api/src/materialize.rs) has anxsd:booleanarm beside the numeric and temporal ones. The newnormalize_boolean_lexicalmaps1totrueand0tofalse, and both sides go through it, like the rest of the canonicalizer.coerce_string_valuetakestrue,false,1and0, untrimmed). The issue suggested trimming first, but I went with the exact forms on purpose: an import keeps anything else (" 1","TRUE","yes","2") as text under the declared datatype, so it isn't the same stored value as a boolean, and leaving it alone means it still has to match byte for byte, as it does today. Only thexsd:booleanIRI gets the arm, so a"1"of some other datatype, or a plain"1", is untouched.docs/cli/materialize.mdsays the gate compares booleans by value, next to the numeric/temporal note.The twin side was already right (the import stores
"1"^^xsd:booleanastrue), so nothing changes in what gets built; it's only the comparison.Tests
boolean_one_and_zero_canonicalize_to_true_and_false(unit, next todouble_enotation_and_plain_canonicalize_equal):1/trueand0/falsecanonicalize equal,1never equalsfalse(or0true), and2," 1","1 ",TRUE,yes,1.0and the empty string pass through unchanged.verify_twin_passes_on_a_zero_one_column_typed_boolean(it_graph_source_r2rml.rs): builds a twin from three rows with alongand adecimal(1,0)column, both typedxsd:boolean(the issue's repro shape, on the sameMultiTableMockfixture the other gate tests use). It checks the twin holdstrue/falsewith the boolean datatype, that Quick and Full pass, and that after flipping one subject's flag fromtruetofalseboth gates fail with exactly one missing and one extra triple. With the new arm disabled it fails at the Quick assertion with every sampled subject aTripleDiff { missing_in_twin: 2, extra_in_twin: 2 }, which is the issue's failure.The issue's other note (a dropped twin still showing in
fluree list) isn't touched here.Verification
On a Mac at
450fa6a7f, for the touched crate only (CI runs the full gate):cargo fmt -p fluree-db-api -- --checkandcargo clippy -p fluree-db-api --features iceberg --lib --test it_graph_source_r2rml -- -D warnings: clean.cargo test -p fluree-db-api --features iceberg --test it_graph_source_r2rml: 71 passed, 2 ignored.cargo test -p fluree-db-api --features iceberg --lib materialize::: 89 passed.🤖 Generated with Claude Code