Skip to content

fix: keep typed literal values through the index (reindex affected ledgers) - #1988

Merged
bplatz merged 4 commits into
mainfrom
fix/sparql-update-typed-literal-coercion
Sep 30, 2026
Merged

bplatz merged 4 commits into
mainfrom
fix/sparql-update-typed-literal-coercion

Conversation

@bplatz

@bplatz bplatz commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1987

Summary

SPARQL UPDATE committed most typed literals as strings, and the index decoded those strings' dictionary ids as the declared type: "2026-09-08"^^xsd:date read back as 1970-01-01 and "20705"^^xsd:long as -9223372036854775804 once indexed. Values now commit as their typed value on every surface, and ledgers that already hold the string form are repaired by a reindex.

Upgrade notes

  • Reindex every ledger that was indexed before the upgrade: fluree reindex <ledger>, POST /v1/fluree/reindex, or Fluree::reindex in an application that embeds fluree-db-api. Incremental builds do not rewrite an index that already misreads the values.
  • Until the reindex, deletes of affected values that are already indexed do not take effect. The commit succeeds and the reindex applies it.
  • Deletes that removed nothing before the upgrade can take effect. A DELETE DATA sent through one surface for a value written through the other used to commit without removing it. It now names the same value, so after a reload or reindex that value is gone with no new write.

docs/troubleshooting/typed-values-wrong-after-indexing.md covers all three.

Root cause

Two defects compounded:

  1. coerce_typed_flake_value in lower_sparql_update.rs coerced only xsd:integer, xsd:decimal, xsd:double, xsd:boolean and f:embeddingVector. Every other datatype fell back to FlakeValue::String with the datatype attached. JSON-LD and Turtle parse the same literals into typed values, so the same RDF term was two different flakes: a date constant missed SPARQL-written dates, and a DELETE DATA sent through the other surface committed without removing anything (the issue's part 2).
  2. The index had no guard for that shape. The resolver stores a string as LEX_ID + dict id, and OTypeRegistry::resolve mapped LEX_ID through the datatype to XSD_DATE / XSD_LONG / …, whose readers decode o_key as the value. value_to_otype_okey in the overlay made the same pairing, so the misread also happened before any index build whenever an index already existed.

The second defect was also reachable without SPARQL: Turtle keeps a literal that is not a value of its datatype ("1990-00-00"^^xsd:date, "abc"^^xsd:integer) as a string, and those were misread the same way, both through transactions and bulk import.

Changes

  • SPARQL UPDATE (fluree-db-transact): template literals coerce through fluree_db_core::coerce::coerce_string_value, the same function JSON-LD uses. A lexical form that is not a value of its datatype is now a lowering error (400) instead of a string that corrupts on index. The WHERE side already coerced via lower_triple_pattern and is unchanged.
  • Commit decode (fluree-db-core, retype_string_literal): both decoders (decode_raw_op for the indexer, decode_op for novelty) read a well-formed string under a typed XSD datatype as the typed value, and a geo:wktLiteral POINT string as a geo point (SPARQL committed those as strings too; coerce_string_value now makes them points). This is what makes existing ledgers recoverable: after upgrading, novelty loaded from commits is typed, and fluree reindex rebuilds a correct index. Ill-typed lexicals and non-POINT WKT stay strings.
  • Index and overlay guard: new OType::is_string_keyed(). OTypeRegistry::resolve gives a LEX_ID under a non-string-keyed datatype OType::customer_datatype(dt) (dict-backed; resolve_datatype_sid maps the payload back through dt_sids, which includes the reserved slots), and value_to_otype_okey keys an overlay string the same way via find_dt_id. Ill-typed literals now read back with their text and datatype. A dt past the payload width still resolves to OType::RESERVED, as Increase custom datatype limit and make it explicit #1966 made it.
  • Docs: troubleshooting/typed-values-wrong-after-indexing.md (affected data, symptoms, reindex including embedded hosts, what changes on upgrade) and a paragraph in concepts/datatypes.md on literals that are not values of their datatype.

Behavior changes

  • SPARQL UPDATE rejects ill-typed literals for built-in XSD datatypes, matching JSON-LD. Before, they committed and then corrupted on index. This includes DELETE DATA, as for query constants: a Turtle-stored ill-typed literal is removed through a bound variable.
  • "1990-00-00"^^xsd:date from Turtle is a distinct term from any valid date, stored under a customer o_type. Before, it was misread as a date.
  • An existing misread index stays wrong until it is rebuilt: incremental builds do not rewrite it. See the upgrade notes above.

Tests

fluree-db-api/tests/it_typed_literal_index.rs (in grp_index):

Test Covers
sparql_typed_literals_read_back_on_every_lane SPARQL + JSON-LD twin; novelty, full rebuild, novelty over an index, incremental build
bound_typed_literal_matches_values_from_both_surfaces SPARQL and JSON-LD constants match values from both surfaces, novelty and indexed
typed_literal_deletes_across_surfaces JSON-LD insert → SPARQL DELETE DATA, SPARQL insert → JSON-LD delete
ill_typed_literals_keep_their_lexical_form Turtle ill-typed literals over an index and after reindex; deleting one through a bound variable
sparql_update_rejects_ill_typed_literal the new 400 path, for INSERT DATA and DELETE DATA
commits_holding_string_typed_literals_read_as_typed_values commits in the pre-fix shape, reloaded from disk: typed in novelty, typed after reindex, matched by constants
commits_holding_string_wkt_points_retract_through_sparql a pre-fix string wkt POINT, reloaded from disk, retracted by SPARQL DELETE DATA in novelty and after reindex

Each fix was reverted on its own to confirm its test fails: the SPARQL coercion fails the reject, delete and bound-constant tests; the decode retag fails the legacy-commit test; the wkt retag fails the legacy-wkt test and its codec unit test; the registry guard fails the ill-typed test at full rebuild; the overlay guard fails it at novelty over an index. Unit tests cover the registry mapping, is_string_keyed, and the codec retag. On the merge with main, #1966's dt_past_payload_width_resolves_to_reserved panicked until the registry guard kept RESERVED; it and decode_value_from_kind_dt_past_payload_width_is_null now pass.

Runs: fluree-db-core, fluree-db-binary-index, fluree-db-indexer, fluree-db-transact lib tests; fluree-db-api grp_index and the geo tests in grp_query; clippy on the touched crates.

Also checked by hand against a ledger written and indexed by 4.2.1: the fixed binary misreads it until fluree reindex, then every value is correct, the legacy date matches a bound constant, and DELETE DATA retracts it.

Notes for review

@bplatz bplatz added the bug Something isn't working as expected label Sep 29, 2026
@bplatz
bplatz requested review from aaj3f and zonotope September 29, 2026 16:51
SPARQL UPDATE coerced only integer, decimal, double, boolean and vector
literals; every other datatype was committed as a string carrying its
datatype. The index stored such a string under the datatype's inline
o_type and decoded the string-dictionary id as the value, so xsd:date read
back as 1970-01-01 and xsd:long as i64::MIN + n. The same string shape made
SPARQL-written values miss typed query constants and deletes sent through
JSON-LD.

- SPARQL UPDATE templates coerce through core's coerce_string_value, as
  JSON-LD does. A lexical form that is not a value of its datatype is
  rejected with a 400.
- Both commit decoders read a well-formed string under a typed XSD
  datatype as the typed value, so ledgers holding such commits are
  repaired by a reindex.
- OTypeRegistry::resolve and the novelty overlay give a string under a
  non-string datatype a string-keyed customer o_type, so ill-typed Turtle
  literals ("1990-00-00"^^xsd:date) keep their lexical form instead of
  being misread; this applied to Turtle insert and bulk import as well.

Docs: a troubleshooting page for affected ledgers and a datatypes section
on literals that are not values of their datatype.

@aaj3f aaj3f 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.

@bplatz routing SPARQL UPDATE through coerce_string_value is exactly the right bottleneck, and the legacy-commit test proves the repair path rather than just the new writes. Two things I'd want in before merging: this has a semantic conflict with #1966, which is now on main (merged together, #1966's out-of-range decode panics again, read path included, even though the textual merge is clean), and geo:wktLiteral points SPARQL wrote before this change can no longer be deleted. Claude-assisted review below:


✅ Approving to unblock you — with 2 things that need to be addressed before this merges.

Routing SPARQL UPDATE through coerce_string_value, and keying the index guard on one predicate (OType::is_string_keyed) that the registry and the overlay both use, is the right altitude for this: the SPARQL list can't drift from JSON-LD again, and the two index writers can't drift from each other. The legacy-commit test proves the repair path, not just the new writes. Two things need to land first:

  1. fluree-db-core/src/o_type_registry.rs:115-118, composition with #1966 (now on main). Not a mistake on this branch's own base (the hunks don't overlap, as the body says) but a semantic conflict: since #1966, resolve_by_dt returns OType::RESERVED past the payload width, and this arm hands that dt to OType::customer_datatype, which #1966 made a hard assert. dt_past_payload_width_resolves_to_reserved and decode_value_from_kind_dt_past_payload_width_is_null pass on main and panic once this PR is merged in, and the second one is the read path. || by_dt == OType::RESERVED fixes both, with it_typed_literal_index and it_custom_datatype_limit still green. This branch's CI ran before #1966 landed and nothing requires a re-run, so please rebase and let CI run before merging.
  2. fluree-db-core/src/commit/codec/raw_reader.rs:470, SPARQL-written geo:wktLiteral points. SPARQL now commits a wkt point as a GeoPoint, but retype_string_literal only retypes XSD, so points SPARQL committed before this change stay strings: a SPARQL DELETE DATA naming one commits and removes nothing, before and after reindex (reproduced). A wkt arm in the retype fixes it.

Also worth doing in this PR:

  • Upgrade note (docs/troubleshooting/typed-values-wrong-after-indexing.md:61): every pre-upgrade index has to be rebuilt, and until then SPARQL deletes of already-indexed SPARQL values don't take; and pre-fix deletes that did nothing take effect on upgrade (reproduced: the value disappears on reload). Embedders have no fluree reindex, so a line for them there and an upgrade note in the PR title or body would help. On the solo side we'll bump EXPECTED_INDEX_FORMAT_VERSION when we repin.
  • DELETE DATA with an ill-typed literal (docs/concepts/datatypes.md:349): now a 400, which leaves Turtle's ill-typed literals removable only through a bound variable. Question inline.
  • The skip at fluree-db-api/tests/it_typed_literal_index.rs:273-278 goes with whichever of this and #1990 merges second (with both merged, the test passes without it). I'd land this one first.
  • #1974 (the mirror image the body lists as not fixed here): I agree it's separable. It lives in the incremental resolver, which builds its OTypeRegistry from the base root's datatypes (incremental_resolve.rs:255-257), a path this PR doesn't touch, and the issue's own reading doesn't explain why it depends on timing, so a fix folded in here would be a guess before there's a deterministic repro.

Adherence to repo commitments:

  • Patterns/abstractions: ✔ SPARQL UPDATE uses core's coerce_string_value, the same bottleneck as JSON-LD and TriG, instead of its own partial list, and the string-keyed guard is one OType predicate shared by both index writers. ⚠️ retype_string_literal gates on the XSD namespace while the coercion it mirrors also rewrites geo:wktLiteral.
  • Performance (speed first, memory second): ✔ No performance-degradation risk. For any object that isn't a string, retype_string_literal is one discriminant check; a string under a non-XSD datatype costs one u16 compare, and one under an XSD string type a five-way &str match, with no allocation. The parse and its allocations run only for a string under a non-string XSD datatype, which means pre-fix SPARQL commits and ill-typed Turtle literals. The overlay's extra find_dt_id scan and the registry's extra check sit on that same rare shape.
  • Deployment targets: ⚠️ The decode path is shared by every host, and the evidence (these tests, and the 4.2.1 check in the body) is CLI and in-process. The Lambda host can't run fluree reindex, so it needs the upgrade note above, and fluree/solo needs an EXPECTED_INDEX_FORMAT_VERSION bump when it repins.
  • Testing: ✔ Six integration tests in grp_index plus unit tests; I ran them by name, and disabling the retype turned commits_holding_string_typed_literals_read_as_typed_values red. ⚠️ Nothing covers a non-XSD datatype on the legacy path (the wkt gap), and the branch predates #1966, so the combination was never run.
  • Conventions: ✔ Self-describing title, a thorough commit body, and a troubleshooting page for affected ledgers.

Verified locally at b2dbc4ab7: grp_index it_typed_literal_index (6 passed), the four new core unit tests and the transact coercion tests; the retype mutation (red, then restored); a throwaway merge with origin/main (two #1966 tests red where they pass on main alone, green with the one-line fix, and 17 grp_index tests green); throwaway probes for the wkt delete and for the pre-fix no-op delete.

Approving now so you can merge without waiting on another pass from me — just be sure the rebase with the #1966 fix (and a CI run on it) and the wkt retype are in before you do.

Comment thread fluree-db-core/src/o_type_registry.rs Outdated
// and its datatype; decoding the string id as that datatype's
// value would read a dictionary position as a date or number.
let by_dt = self.resolve_by_dt(dt);
if by_dt.is_string_keyed() {

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.

🔴 Must address before merge: once this is merged with today's main (#1966), this arm panics for a datatype id past the OType payload width, and two of #1966's tests go red.

This isn't a mistake on this branch's own base. The body's trial-merge note is right that the hunks don't overlap; the conflict is semantic. #1966 landed at 23:34Z, after this branch's CI finished at 17:02Z. It made resolve_by_dt return OType::RESERVED for a dt above OType::MAX_PAYLOAD (its "decode an out of range datatype as unknown rather than panicking" commit) and turned the debug_assert! in OType::customer_datatype into an assert!. RESERVED decodes as DecodeKind::Sentinel, so is_string_keyed() is false here, and the else hands a dt of 0x4000 or more to OType::customer_datatype (line 118), which now panics in release builds too.

o_type_registry::tests::dt_past_payload_width_resolves_to_reserved passes on origin/main (e4793617f) and on main with #1990 and #1995 merged, and fails as soon as this PR is merged in (panic at o_type.rs:267, "customer payload exceeds 14-bit range"). read::binary_index_store::tests::decode_value_from_kind_dt_past_payload_width_is_null does the same. The second test is the read path: o_type_from_kind and decode_value_from_kind both go through this resolve, so a damaged or future-format LEX_ID row goes back to aborting the process (fluree/solo builds with panic = "abort") instead of decoding as unknown, which is the case #1966 closed. db's ruleset doesn't require passing checks, and GitHub shows this PR as mergeable, so merging it as-is lands a red main.

Keeping RESERVED fixes it. With this line on a merge of main, both tests pass, and so do it_typed_literal_index and it_custom_datatype_limit in grp_index (17 passed). Could you rebase onto main and let CI run again before merging?

Suggested change
if by_dt.is_string_keyed() {
if by_dt.is_string_keyed() || by_dt == OType::RESERVED {

The other customer_datatype call this PR adds, the overlay's store.find_dt_id(dt_sid).map(OType::customer_datatype) in binary_scan.rs, doesn't have this problem. It takes a position in the index root's datatype list, which #1966 bounds on every write path, and the existing otype_from_dt_sid already feeds find_dt_id to customer_datatype the same way. This arm is different because its dt comes straight off a decoded row.

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.

Fixed in c9f91b6 with your guard (|| by_dt == OType::RESERVED). I merged main in rather than rebasing. On the merge before the fix, dt_past_payload_width_resolves_to_reserved panicked with customer payload exceeds 14-bit range; with it, that test and decode_value_from_kind_dt_past_payload_width_is_null pass, as do it_typed_literal_index and it_custom_datatype_limit (all 112 grp_index tests). CI is running on the merged head.

let RawObject::Str(lexical) = raw else {
return raw;
};
if dt_ns_code != namespaces::XSD || xsd_names::is_string_like_name(dt_name) {

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.

🔴 Must address before merge: geo:wktLiteral points that SPARQL committed before this change can no longer be deleted through SPARQL, and a reindex doesn't repair them.

coerce_typed_flake_value now sends every datatype through coerce_string_value, which turns "POINT(2.35 48.85)"^^geo:wktLiteral into a FlakeValue::GeoPoint (fluree-db-core/src/coerce.rs:551-562). The old SPARQL match had no wkt arm, so SPARQL used to commit a point as a String carrying the datatype. retype_string_literal only looks at the XSD namespace (this line), so those older commits stay String for good, in novelty and after any rebuild, while a SPARQL DELETE DATA naming the same literal now lowers to a GeoPoint, and the two never cancel.

I checked it with a throwaway test next to commits_holding_string_typed_literals_read_as_typed_values: commit the pre-fix shape (a String under geo:wktLiteral), reload from disk, and send DELETE DATA { <a> <loc> "POINT(2.35 48.85)"^^geo:wktLiteral }. The delete template is GeoPoint(48.85, 2.35), the commit succeeds, and the row is still there, both in novelty and after reindex. On main both sides were the same string, so the same delete removed it. That's #1987's part 2 again (a delete that reports success and removes nothing) for a datatype that used to delete fine, and a SPARQL re-insert of the point now writes a second, distinct term next to the old string.

A wkt arm here that mirrors coerce_string_value fixes it without borrowing anything, since RawObject::GeoPoint already exists. Illustratively, ahead of the XSD check:

if dt_ns_code == namespaces::OGC_GEO && dt_name == geo_names::WKT_LITERAL {
    return match crate::geo::try_extract_point(lexical) {
        Some((lat, lng)) if crate::GeoPointBits::new(lat, lng).is_some() => RawObject::GeoPoint { lat, lng },
        _ => raw,
    };
}

A wkt point in the legacy-commit test would pin it. (I looked at rdf:JSON too: validate_value_dt_pair already refuses a String under it at stage time, so current releases can't have committed that shape.)

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.

Fixed in ed3c4d6. retype_string_literal now reads a POINT string under geo:wktLiteral as RawObject::GeoPoint, using try_extract_point + GeoPointBits::new as you sketched rather than coerce_string_value, which would allocate a String for every non-POINT geometry on decode. Other WKT stays a string, and the spatial hook already skipped POINT strings, so nothing drops out of the sidecar.

commits_holding_string_wkt_points_retract_through_sparql commits the pre-fix string, reloads from disk, and retracts it with SPARQL DELETE DATA, checked in novelty and after reindex. wkt_point_string_reads_as_geo_point covers the codec, including POLYGON, an out-of-range point and POINT EMPTY staying strings. Both fail with the new branch disabled.

-d '{"ledger": "mydb:main"}'
```

An index that already misreads the values keeps misreading them until it is

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.

🟠 Should address: every index built before the upgrade has to be rebuilt, embedders have no fluree reindex, and two effects of the upgrade aren't on this page yet.

The repair is decode-side, so an index built before the upgrade keeps its string-keyed rows until a full rebuild, and that window is more than cosmetic. By the code (I didn't replay a 4.2.1 index for this one), a SPARQL DELETE DATA of a SPARQL-written value that's already in the index used to lower to the same string and cancel its (XSD_DATE, string id) row; it now lowers to the typed value, whose key doesn't match, so it reports success and the value stays until the rebuild applies it. In the other direction, a pre-fix SPARQL delete that silently did nothing against a JSON-LD- or Turtle-written value is retyped on read as well, so after the upgrade it takes effect. I committed that shape against a JSON-LD date: the date is still there in the process that wrote it, and gone once the ledger is reloaded from its commits and after reindex. That second one is arguably what the user asked for, but it means values that were visible before the upgrade disappear with no new write, which is worth a sentence here.

For hosts: fluree reindex covers the CLI and the server, but an application that embeds fluree-db-api has no CLI. fluree/solo's Lambdas are the case I care about, and the only lever there is bumping EXPECTED_INDEX_FORMAT_VERSION, which invalidates and re-indexes every ledger at cold start. db's CURRENT_INDEX_VERSION (fluree-db-indexer/src/lib.rs:119) isn't bumped here and nothing reads it, so embedders get no machine signal either.

Could we add a line here for embedded deployments (call Fluree::reindex for each ledger after upgrading), plus an upgrade note in the PR title or body, since the release notes are generated from PR titles? On the solo side, we'll bump EXPECTED_INDEX_FORMAT_VERSION in the repin that picks this up.

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.

Done in ed3c4d6. The page now gives the Fluree::reindex call for embedded hosts and has a "What changes on upgrade" section with both effects: deletes of already-indexed values don't take until the reindex, and pre-fix deletes that did nothing take effect once the ledger is reloaded or reindexed. The title now ends "(reindex affected ledgers)" so it reaches the release notes, and the body has an Upgrade notes section.

Not done: CURRENT_INDEX_VERSION stays as is. Nothing reads it, so bumping it wouldn't give embedders a signal. Making it one would be its own change.


A literal such as `"2024-02-30"^^xsd:date` or `"300"^^xsd:byte` names a
built-in datatype but is not one of its values. JSON-LD transactions and
SPARQL UPDATE reject it, naming the datatype in the error. Turtle

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: DELETE DATA now rejects ill-typed literals too, so a literal that Turtle kept can't be deleted by naming it anymore.

literal_to_template builds the delete templates as well as the insert ones, so DELETE DATA { ex:a ex:date "1990-00-00"^^xsd:date } is now a 400. This section says Turtle and bulk import keep such literals "as RDF allows", and on main, naming one in DELETE DATA lowered to the same string-with-datatype flake Turtle stored and removed it. DELETE WHERE already errored on it (the query-side coerce_value), so after this the only way left to remove one is through a bound variable, e.g. DELETE { ?s ex:date ?o } WHERE { ?s ex:date ?o FILTER(STR(?o) = "1990-00-00") }.

This is more of a question than a suggestion, and it's from reading the code rather than a run: rejecting on insert is clearly right, but I wonder if the delete side should lower an ill-typed literal to the string form Turtle stored, so the cleanup path stays open. If you'd rather keep it strict, a sentence here pointing at the variable-binding delete would do. Minor and non-blocking, but if you agree, I'd rather see it settled in this PR than lost in the backlog.

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.

Keeping it strict, and not documenting it in datatypes.md either. DELETE WHERE and query constants already reject these literals, so a lenient DELETE DATA would be a third behavior for one edge case. Deleting through a bound variable works, and it's now covered by tests instead of the docs: ill_typed_literals_keep_their_lexical_form removes one that way over an index and after a rebuild, and sparql_update_rejects_ill_typed_literal checks DELETE DATA as well as INSERT DATA. I also dropped the section's closing sentence, which only described the fix.

// Separate gap, not this issue's: once indexed, a JSON-LD constant
// typed with a non-default numeric subtype matches nothing, even for
// JSON-LD-written data.
if lane == "indexed" && matches!(literal.2, "long" | "float") {

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.

🟡 Merge-order note: this skip comes out with whichever of this PR and #1990 lands second.

With #1990 in, the indexed JSON-LD xsd:long/xsd:float constants match: on a merge of both with main, this test passes with these three lines and the comment above them removed. I'd land this PR first, since it's the P1 and what's left on it is small, and have #1990 drop the skip when it rebases; I've left the same note there.

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 lands first, and #1990 drops the skip when it rebases. The skip stays here for now.

expected_rows(),
"novelty loaded from commits"
);
assert_eq!(

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.

👍 This is the assertion that makes the legacy-commit test real.

The rows render the same whether the object is a string or a date, so the objects_of check above passes either way. I turned retype_string_literal into a no-op locally, and this is exactly where it went red (left: []). Writing it against a file ledger reloaded from its commits, rather than in-memory state, is what lets it see the decode path at all.

Since #1966, resolve_by_dt returns OType::RESERVED for a datatype id past
the o_type payload width, and OType::customer_datatype asserts on such an
id. The LEX_ID arm passed every non-string-keyed result, RESERVED
included, to customer_datatype, so a damaged or future-format row panicked
on read instead of decoding as unknown.
SPARQL UPDATE now commits a geo:wktLiteral POINT as a geo point, as
JSON-LD and Turtle do, but before this change it committed the point as a
string. retype_string_literal retyped only XSD datatypes, so those older
points stayed strings, and a SPARQL DELETE DATA naming one committed
without removing it, in novelty and after a reindex. Both commit decoders
now read a POINT string under geo:wktLiteral as a geo point; other WKT
stays a string.

Tests: a legacy string point is retracted through SPARQL; SPARQL
DELETE DATA rejects an ill-typed literal as INSERT DATA does; a Turtle
ill-typed literal is removed through a bound variable over an index and
after a rebuild.

Docs: the troubleshooting page covers reindexing from an embedded
fluree-db-api, what changes on upgrade before the reindex, and
SPARQL-written wkt points. The datatypes section drops a sentence that
only described the fix.
@bplatz bplatz changed the title fix: keep typed literal values through the index fix: keep typed literal values through the index (reindex affected ledgers) Sep 30, 2026
@bplatz

bplatz commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

@aaj3f thanks. Both blockers are fixed (c9f91b6, ed3c4d6), with main merged in, and I've replied on each thread. Things left as they are: DELETE DATA stays strict for ill-typed literals, CURRENT_INDEX_VERSION isn't bumped, the xsd:long/xsd:float skip waits for #1990, and #1974 stays separate as you suggested.

@bplatz
bplatz merged commit 86cb046 into main Sep 30, 2026
16 checks passed
@bplatz
bplatz deleted the fix/sparql-update-typed-literal-coercion branch September 30, 2026 10:21
bplatz added a commit that referenced this pull request Sep 30, 2026
#1988 skipped these constants on its indexed lane because a JSON-LD
constant typed with a numeric subtype matched nothing once indexed. The
typed-constant fix on this branch closes that gap, so the checks run on
every lane.
aaj3f added a commit that referenced this pull request Oct 19, 2026
Brings in 57bf7a9 (#2120, #2009). Two conflicts:

- fluree-db-api/src/commit_transfer.rs: #2009 routes a push's graphs to
  the ids the ledger's graph registry gives them. The push's retraction
  check reads its slots through that routing as it is; only the routing
  struct's doc comment conflicted, and main's is kept.
- fluree-db-transact/src/parse/jsonld.rs: #2009 reworks JSON-LD graph
  scoping, and carries the delete templates' `ill_typed_as_stored` that
  this branch reverts (call 2, aa1b3e6). Main's file is kept and the
  revert applied to it again: a delete template refuses an ill-typed
  literal, as #1988 had it.
q-qp-p pushed a commit to q-qp-p/fluree-db that referenced this pull request Oct 19, 2026
With fluree#1988, SPARQL UPDATE lowers `"1"^^xsd:int`, `xsd:long` and
`xsd:dateTime` literals as JSON-LD does, so a DELETE DATA intent names the
stored term exactly and the retraction resolver deletes it, over novelty
and over an index. Before fluree#1988 the intent named a string, and the delete
removed nothing.
q-qp-p pushed a commit to q-qp-p/fluree-db that referenced this pull request Oct 19, 2026
…pace

`parse_xsd_double` and `parse_xsd_float` accept exactly the XSD 1.1
lexical forms: numerals, `INF`, `+INF`, `-INF` and `NaN`. A numeral too
large in magnitude for the datatype maps to `INF` or `-INF`, as XSD 1.1
specifies. Rust's spellings (`inf`, `Infinity`, `nan`) are not lexical
forms of either datatype.

Every place that turns a double or float literal into a value uses it:
JSON-LD coercion, SPARQL query literals and casts, SPARQL UPDATE, Turtle,
and string-backed aggregate inputs. JSON-LD and SPARQL UPDATE refuse the
other spellings as ill-typed literals, the rule other built-in datatypes
follow (fluree#1988), and Turtle keeps them as ill-typed literals. SPARQL
UPDATE words the refusal as JSON-LD does (`Parse error: ...`). R2RML
renders non-finite float cells with the XSD spellings.

Cypher's `toFloat` is not an XSD cast. It gets its own function and
reads strings as Cypher does, `Infinity`, `-Infinity` and `NaN`
included.
q-qp-p pushed a commit to q-qp-p/fluree-db that referenced this pull request Nov 8, 2026
This reverts 987a937, "fix(transact): a DELETE can name a stored ill-typed
literal", as pushed for review round 1.

DELETE DATA and DELETE templates refuse an ill-typed literal
("abc"^^xsd:integer) again, as fluree#1988 left them, so a DELETE template
agrees with DELETE WHERE, with a WHERE constant and with a query
constant. fluree#1987's test is back as it was.

The reverted message overstated what it changed. It said DELETE WHERE
templates could name such a literal, but the WHERE half of a DELETE
WHERE still lowered strictly and refused it, so a DELETE WHERE naming
one failed before that commit and after it. Only DELETE DATA and a
DELETE template over an empty WHERE had become lenient.

A stored ill-typed literal is removed through a bound variable
(FILTER(STR(?o) = "abc")), or replaced by an upsert or a graph sync.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Index build silently destroys temporal and xsd:long literals (xsd:date → 1970-01-01), and the resulting triples cannot be retracted by literal match

2 participants