Skip to content

fix(materialize): the parity gate reads "1"^^xsd:boolean as true - #2447

Merged
aaj3f merged 2 commits into
mainfrom
fix/materialize-boolean-parity
Nov 19, 2026
Merged

aaj3f merged 2 commits into
mainfrom
fix/materialize-boolean-parity

Conversation

@aaj3f

@aaj3f aaj3f commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Fixes #2386.

A mapping that types a 0/1 column as xsd:boolean couldn't be materialized: the source side renders the cell as "1"^^xsd:boolean, the twin stores the boolean and answers "true"^^xsd:boolean, and canonicalize_value_nt only rewrote numeric and temporal literals, so every one of those triples was a missing/extra pair and both --verify quick and --verify full dropped a twin that held the right values.

What changes

  • canonicalize_value_nt (fluree-db-api/src/materialize.rs) has an xsd:boolean arm beside the numeric and temporal ones. The new normalize_boolean_lexical maps 1 to true and 0 to false, and both sides go through it, like the rest of the canonicalizer.
  • It only collapses the four forms the write path itself parses as a boolean (coerce_string_value takes true, false, 1 and 0, 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 the xsd:boolean IRI gets the arm, so a "1" of some other datatype, or a plain "1", is untouched.
  • docs/cli/materialize.md says the gate compares booleans by value, next to the numeric/temporal note.

The twin side was already right (the import stores "1"^^xsd:boolean as true), so nothing changes in what gets built; it's only the comparison.

Tests

  • boolean_one_and_zero_canonicalize_to_true_and_false (unit, next to double_enotation_and_plain_canonicalize_equal): 1/true and 0/false canonicalize equal, 1 never equals false (or 0 true), and 2, " 1", "1 ", TRUE, yes, 1.0 and 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 a long and a decimal(1,0) column, both typed xsd:boolean (the issue's repro shape, on the same MultiTableMock fixture the other gate tests use). It checks the twin holds true/false with the boolean datatype, that Quick and Full pass, and that after flipping one subject's flag from true to false both 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 a TripleDiff { 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 -- --check and cargo 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

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]>
@aaj3f
aaj3f requested a review from bplatz November 18, 2026 15:46

@bplatz bplatz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. Please review the inline comments before merging.

Comment on lines +2230 to +2236
fn normalize_boolean_lexical(lex: &str) -> &str {
match lex {
"1" => "true",
"0" => "false",
other => other,
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: 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:

Suggested change
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,
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bplatz bplatz added bug Something isn't working as expected area:iceberg Iceberg catalogs/credentials, R2RML, virtual datasets, materialize labels Nov 19, 2026
…_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]>
@aaj3f
aaj3f merged commit b5aee2c into main Nov 19, 2026
21 checks passed
@aaj3f
aaj3f deleted the fix/materialize-boolean-parity branch November 19, 2026 17:26
bplatz added a commit that referenced this pull request Nov 19, 2026
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.
@aaj3f aaj3f mentioned this pull request Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:iceberg Iceberg catalogs/credentials, R2RML, virtual datasets, materialize bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

materialize: the parity gate rejects every xsd:boolean column that holds 0/1 ("1"^^xsd:boolean vs the twin's true)

2 participants