Skip to content

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

Closed

Description

@aaj3f

fluree materialize can't build a twin from a mapping that types a 0/1 numeric column as xsd:boolean: both --verify quick and --verify full fail every time. Queries read "1"^^xsd:boolean as true both over the graph source and in a native ledger, so the twin holds the right values. It's only the parity gate that compares the two sides lexically, and the source's "1" never matches the twin's "true".

Since the gate drops the twin on failure, a mapping like this simply can't be materialized today, and typing a 0/1 flag as a boolean is a pretty ordinary thing to want.

Repro

Setup (a local Iceberg table with 6 synthetic rows, pyiceberg via uv):

mkdir -p /tmp/bool-repro/wh /tmp/bool-repro/proj && cd /tmp/bool-repro

cat > make_table.py <<'PY'
# demo.widget(id long, flag decimal(1,0)), 6 rows, flag = 1,0,1,0,1,0
import sys, decimal, pyarrow as pa
from pyiceberg.catalog.sql import SqlCatalog
wh = sys.argv[1]
cat = SqlCatalog("local", uri=f"sqlite:///{wh}/catalog.db", warehouse=f"file://{wh}")
cat.create_namespace("demo")
t = pa.table({
    "id": pa.array(range(1, 7), type=pa.int64()),
    "flag": pa.array([decimal.Decimal(i % 2) for i in range(1, 7)], type=pa.decimal128(1, 0)),
})
cat.create_table("demo.widget", schema=t.schema, location=f"file://{wh}/demo.db/widget").append(t)
PY
uv run --with 'pyiceberg[sql-sqlite,pyarrow]' python make_table.py /tmp/bool-repro/wh

cat > widget.ttl <<'TTL'
@prefix rr: <http://www.w3.org/ns/r2rml#> .
@prefix ex: <http://example.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://example.org/map/WidgetMap> a rr:TriplesMap ;
  rr:logicalTable [ rr:tableName "demo.widget" ] ;
  rr:subjectMap [ rr:template "http://example.org/widget/{id}" ; rr:class ex:Widget ] ;
  rr:predicateObjectMap [ rr:predicate ex:active ;
    rr:objectMap [ rr:column "flag" ; rr:datatype xsd:boolean ] ] .
TTL

export FLUREE_ICEBERG_LOCAL_ROOTS=/tmp/bool-repro/wh
cd proj && fluree init
fluree iceberg map widget-gs --mode direct --table-location /tmp/bool-repro/wh/demo.db --r2rml ../widget.ttl

The graph source reads the column the way you'd hope:

$ fluree query widget-gs:main 'PREFIX ex: <http://example.org/> SELECT ?s ?a WHERE { ?s ex:active ?a } ORDER BY ?s LIMIT 3'
+-------+-------------+
| a     | s           |
+=====================+
| true  | ex:widget/1 |
|-------+-------------|
| false | ex:widget/2 |
|-------+-------------|
| true  | ex:widget/3 |
+-------+-------------+

Materializing it fails both gates (exit 1):

$ fluree materialize widget-gs:main --output ledger --into widget-quick --verify quick
error: parity gate FAILED — twin 'widget-quick' dropped, not announced.
  - sample:<http://example.org/widget/2>: TripleDiff { missing_in_twin: 1, extra_in_twin: 1 }
  - sample:<http://example.org/widget/3>: TripleDiff { missing_in_twin: 1, extra_in_twin: 1 }
  - sample:<http://example.org/widget/4>: TripleDiff { missing_in_twin: 1, extra_in_twin: 1 }

$ fluree materialize widget-gs:main --output ledger --into widget-full --verify full
error: parity gate FAILED — twin 'widget-full' dropped, not announced.
  - full-triple-diff: TripleDiff { missing_in_twin: 6, extra_in_twin: 6 }

The same mapping with rr:datatype xsd:integer instead passes --verify full (Parity gate passed (3 checks).), so it's the boolean typing alone. A native ledger stores "1"^^xsd:boolean as true, too: fluree insert of ex:w1 ex:active "1"^^xsd:boolean . reads back as {"type": "literal", "value": "true", "datatype": "…#boolean"}.

Reproduced with the 4.2.4 CLI and with a CLI built from main at 7b9164b60.

Cause

The two sides render the same value differently, and the gate's canonicalizer doesn't know booleans:

  • Source side. materialize_object builds the literal from the column's rendered text plus the declared datatype (fluree-db-r2rml/src/materialize/term.rs:417), so a decimal(1,0) cell becomes "1"^^xsd:boolean. That's a legal lexical form (the xsd:boolean lexical space is true, false, 1, 0), so I don't think the enumerator is wrong here as such.
  • Twin side. The twin reads the value back through a query (twin_subject_triples, fluree-db-api/src/materialize.rs:1728), which answers the canonical "true"^^xsd:boolean.
  • The gate. Both sides go through canonicalize_value_nt (fluree-db-api/src/materialize.rs:2174) before they're compared, in the quick and full paths alike. It only rewrites numeric and temporal literals; any other typed literal comes back byte-for-byte (materialize.rs:2192-2198), so "1" vs "true" is a missing/extra pair on every subject.

Expected

The gate should pass when the two sides hold the same value, which they do here. Minimally that's a boolean arm in canonicalize_value_nt beside the numeric and temporal ones: for xsd:boolean, map a trimmed 1 to true and 0 to false, applied to both sides like the rest. The float→double datatype fold just below it (the CRITICAL-3 note from #1529) is the same kind of fix, and a case next to the existing canonicalizer tests (double_enotation_and_plain_canonicalize_equal, materialize.rs:2612) would cover it. We could instead have the enumerator emit the canonical form, but I think the canonicalizer is the right home, since it's already where value-equal lexical forms are meant to collapse.

One more thing I noticed while running this (I haven't dug into it): after a failed gate, the "dropped" twin is still in fluree list (at t=2), and querying it fails on a missing index root (Not found: …/index/roots/….json). So re-running the repro needs a new --into name, or materialize refuses with import requires a fresh ledger. That's likely its own issue, separate from this one.

Activity

  1. added
    bug
    P2
    area:iceberg
    on Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2area:icebergbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions