Skip to content

Indexed reads flatten non-xsd:string string-dictionary datatypes, so distinct literals compare equal and lose identity in joins #1729

Closed

Description

@aaj3f

On an indexed ledger, every string-dictionary datatype that isn't xsd:string or rdf:langString is flattened onto xsd:string when an object is decoded into a binding — so two literals with distinct datatypes compare equal, and a literal loses its own identity in a self-join.

No FILTER fold is involved. This is the decode lane itself.

Where

fluree-db-query/src/object_binding.rs:105-112 collapses the datatype for anything landing in the string dictionary. The mirror-image gap is in is_string_term_constraint (fluree-db-query/src/binding.rs:264-272), which recognises the flattened form and so can't distinguish the cases either.

What it looks like

With ex:p carrying both "abc"^^xsd:string and "abc"^^ex:custom, on a ledger with a published index:

  • FILTER(?x = ?y) reports the two equal, though they are distinct RDF terms and = is value equality, which for non-numeric literals requires matching datatypes.
  • A self-join on ex:p loses the custom-typed literal's own identity row.

This is not limited to custom datatypes. xsd:anyURI, xsd:token, and xsd:normalizedString all decode through the string dictionary, so they flatten the same way — any two of them sharing a lexical form become indistinguishable.

Relationship to #1676 and #1723

#1676 (aaaa7d429) fixed exactly this class for plain and lang-tagged strings, making the join key term-exact for those. This is the un-migrated remainder of the same shape: the other string-dictionary datatypes still flatten.

It's also the reason #1723 was fixed by gating the sameTerm fold rather than by making the join term-exact. Two independent reasons that route is closed: this flattening is still live, and — more fundamentally — the join is deliberately lenient across numeric subtypes (1 ≡ "1"^^xsd:long ≡ 1.0), pinned as a product decision by it_literal_identity.rs:189 bare_numeric_literals_stay_lenient_across_subtypes and rooted in the index's normalized numeric key. So "the join implements term equality" is a premise the engine doesn't want to hold, and fixing this issue would not make it true. It would, though, remove a live wrong-results path.

Notes for whoever takes it

  • Verified by reading both sites; the practical consequence was observed while building fix: make the equijoin-filter fold sound about term equality #1728's regression fixtures — its published-index test deliberately compares two measurements within one read lane rather than across the lane switch, precisely because of this.
  • The lane matters: the divergence appears on the indexed read path. Check the novelty path separately rather than assuming it behaves the same.
  • Whatever lands should pin at least one standard datatype (xsd:anyURI or xsd:token) alongside a custom one, so the fix isn't quietly scoped to user-defined datatypes.
  • Per the surface-parity rule, check the JSON-LD surface for the same flattening.
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

    P1area:querybug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions