Skip to content

Numeric lexical forms are canonicalized at ingest, so 01, +1 and 1 become the same term (decision D-11) #1696

Open

Description

@aaj3f

The other half of the ParserOptions default, and the open decision D-11 from the burn-down roadmap ("lexical-form preservation vs documented value-matching divergence" — docs/audit/burn-down/ROADMAP.md §4). Filing it as a tracking issue the way #1442 tracked D-2, because it currently blocks group01 and roughly eight expression-cluster register entries, and because two of the burn-down cluster docs assumed different outcomes for it. Verified at 47e96b7b6.

Repro

@prefix ex: <http://example.org/> .
ex:x1 ex:v 01 .
ex:x2 ex:v +1 .
ex:x3 ex:v 1 .
$ fluree query lex --sparql 'SELECT ?s (STR(?o) AS ?lex) (DATATYPE(?o) AS ?dt) WHERE { ?s ?p ?o }'
ex:x1  1  xsd:integer
ex:x2  1  xsd:integer
ex:x3  1  xsd:integer

In RDF those are three distinct terms with the same value. After ingest they are one term, and nothing downstream can tell them apart.

Mechanism

NumericStyle::Canonicalize is the ParserOptions default (fluree-graph-turtle/src/options.rs:52): Integer and Double tokens are parsed into native LiteralValues and the source spelling is discarded. Ingest takes the default via fluree_graph_turtle::parse (parser.rs:1494), called from fluree-db-transact/src/import.rs:183, :535, :910.

Two lexical forms already survive today, which is worth knowing before designing the fix: Decimal tokens keep their spelling, and integers past i64 keep theirs so downstream can promote to BigInt (parser.rs:961, :1651). So the storage layer is not uniformly value-only — the gap is specifically i64-range integers and doubles.

NumericStyle::PreserveLexical (options.rs:58) already implements the other side and is exercised by the W3C RDF-syntax suites; as with collections, it just isn't reachable from an ingest surface.

Why it matters

Term identity, not value comparison, is what breaks. SPARQL GROUP BY ?x, DISTINCT, sameTerm, and COUNT(DISTINCT ?x) are defined on terms, so a dataset that distinguishes 01 from 1 gets silently merged into one group. That's the group01 failure, and the roadmap's note that it is "unimplementable as scoped because integer lexical forms are canonicalized at ingest" is the same observation from the other end.

For most users storing numbers this is invisible and arguably desirable. It bites the user who is round-tripping someone else's RDF and expects to get back what they put in.

The decision (D-11)

  • Preserve the lexeme — a lexical column alongside the value, so terms keep their identity and the value paths are unchanged. This is an ingest and storage format change, so it wants a real design pass and probably a migration note; it is the option that greens group01 and the expression entries.
  • Documented divergence — state that Fluree stores numeric literals by value, not by lexical form, and that 01 and 1 are the same term here. Zero cost, permanent register entries, and it needs to be said out loud in the docs rather than left implicit.

I don't think this one should be decided inside an implementation PR — it changes what a Fluree literal is. Whichever way it goes, docs/contributing/sparql-compliance.md should carry the answer so the next person doesn't re-derive it.

Related: the same ParserOptions default also flattens RDF collections and drops () statements (D-13) — filed separately. Note that STR() on a double is separately wrong even under the divergence option, since the canonical form is well-defined — also filed separately.

Activity

  1. added
    bug
    P2
    triage:needs-decision
    area:sparql
    on Aug 26, 2026
  2. added this to the 5.0.0 milestone on Nov 14, 2026
  3. removed
    triage:needs-decision
    on Nov 23, 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:sparqlbug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions