Repository navigation
Description
Found while verifying the burn-down backlog at 47e96b7b6. This is the same defect class #1445 closed for the six RDF output sites, but the STR() builtin was not one of them — so today two paths in the same engine render the same term two different ways.
Repro
@prefix ex: <http://example.org/> .
ex:y1 ex:d 1E0 .$ fluree query lex --sparql 'SELECT ?o WHERE { ex:y1 ex:d ?o }' --format json
"value": "1.0E0", "datatype": "http://www.w3.org/2001/XMLSchema#double" ← correct
$ fluree query lex --sparql 'SELECT (STR(?o) AS ?lex) WHERE { ex:y1 ex:d ?o }' --format json
"value": "1" ← wrong
STR is defined to return the literal's lexical form, and the canonical lexical form of that value is 1.0E0 — which our serializer already knows, two lines above in the same result set.
Mechanism
eval_str (fluree-db-query/src/eval/string.rs:93-109) routes everything that isn't a Sid through ComparableValue::into_string_value, and that function formats doubles with Rust's Display:
// fluree-db-query/src/eval/value.rs:500
ComparableValue::Double(d) => Some(ComparableValue::String(Arc::from(d.to_string()))),f64::to_string() gives "1" for 1.0f64 — no mantissa dot, no exponent. The neighbouring Float arm at :501-503 already routes through a helper (super::cast::format_f32), so the shape of the fix is established right there.
#1445's fix added canonical_xsd_double in fluree-graph-ir/src/xsd_double.rs:92 and wired it into export.rs:1256, :1475, format/sparql.rs:431, :567, format/sparql_xml.rs:370 and format/delimited.rs:614. Expression evaluation was simply never on that list — I don't think it was an oversight so much as that the audit that produced #1445 was scoped to output formats.
Why it matters
STR() feeds FILTER(STR(?o) = "1.0E0"), CONCAT, IRI(CONCAT(...)), REGEX over stringified numerics, and BIND(STR(?o) AS ?k) group keys. All of those silently get the wrong string — no error, just a filter that never matches or a key that collides with a different value's rendering. And a user comparing STR(?o) against the very value we handed them in the result set will find they don't match.
TypedLiteral's inner Double arm (value.rs:519+) looks like it has the same shape and should be checked in the same pass.
Suggested direction
Route the Double arm (and the TypedLiteral { val: FlakeValue::Double, .. } arm) through canonical_xsd_double, exactly as the six output sites do. One wrinkle: fluree-db-query doesn't currently depend on fluree-graph-ir (fluree-db-query/Cargo.toml:10-18), so this either adds that dependency or moves the helper somewhere both crates already see — fluree-db-core would be the natural home, and moving it also stops the next site from re-deriving it.
Worth a regression test on both surfaces per the parity rule, alongside the existing sparql_double_canonical_lexical_form_across_formats (fluree-db-api/tests/it_query_sparql.rs:4645) — that test pins the serializer and would not have caught this.
Activity