Skip to content

VALUES bare integer lowered as xsd:long, big integer as xsd:integer — inconsistent, risks silent join misses #1343

Closed

Description

@bplatz

Summary

A bare integer in a SPARQL VALUES clause is lowered with datatype xsd:long, while a large-magnitude bare integer (one that overflows i64) is lowered as xsd:integer. This is inconsistent, non-conformant with the SPARQL spec, and can cause silent join misses against stored xsd:integer data.

Details

In fluree-db-sparql/src/lower/term.rs (lower_value_literal):

  • LiteralValue::Integer → Sid::new(XSD, xsd_names::LONG) (line ~351)
  • LiteralValue::BigInteger → Sid::new(XSD, xsd_names::INTEGER) (line ~363)

Per SPARQL 1.1, an unsuffixed integer literal has datatype xsd:integer. The typed-literal and triple-pattern lowering paths already use xsd:integer; the VALUES bare-integer arm tagging xsd:long is the outlier.

Impact

Hash joins normalize literals through binding_to_group_key_normalized → encoded_equivalent, where an xsd:long-tagged integer encodes to (NUM_INT, encode_i64(v), dt_id = LONG) and an xsd:integer-tagged integer encodes to (..., dt_id = INTEGER). GroupKeyOwned::Lit includes dt_id, so although o_kind/o_key are identical, the differing dt_id places the two values in different hash buckets.

Result: on the normalized-key hash-join path, VALUES ?o { 42 } (tagged xsd:long) does not match stored xsd:integer data, whereas VALUES ?o { 99999999999999999999 } (tagged xsd:integer) does. Same-shaped query, opposite results depending on the magnitude of the constant.

Note: the inline VALUES operator path (values.rs) matches value-based via FlakeValue::eq (datatype-agnostic), so this only manifests when VALUES is executed as a hash join.

Suggested fix

  • Change the LiteralValue::Integer arm in lower_value_literal to tag xsd_names::INTEGER, matching the spec and the BigInteger/pattern paths.
  • Add a regression test that joins a bare VALUES ?x { 42 } against stored xsd:integer data and asserts a match.

Related

Surfaced during review of #1332 (decimal/integer exactness). The current test suite covers typed VALUES ("…"^^xsd:integer) but not the bare-integer case.

Activity

  1. aaj3f commented on Jun 29, 2026

    @aaj3f
    Contributor

    Closing as a duplicate of #1319, which tracks the same root cause — a bare integer literal lowering to xsd:long while stored integers materialize as xsd:integer, so the same number becomes two distinct RDF terms — and the same fix locus, the VALUES Integer arm in fluree-db-sparql/src/lower/term.rs. #1319 is the broader umbrella (VALUES + expressions, plus the integer-family canonicalization option), so let's consolidate there. I'll comment there to also see this issue for more information.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions