Repository navigation
json-ld: a native number or boolean @value with no @type keeps its RDF datatype - #2212
Conversation
…F datatype
`process_literal` labelled every value object without `@type` as
xsd:string, including `{"@value": 0}` and `{"@value": true}`, while keeping
the native value. The database sinks infer the datatype from the value, so
nothing stored changed, but a sink that keeps it (GraphCollectorSink) built
`Literal { Integer(0), xsd:string }`, which format_ntriples wrote as "0".
Now an untyped native value takes the datatype JSON-LD's RDF conversion
gives it: xsd:boolean, xsd:integer for an integral number, xsd:double
otherwise; a string stays xsd:string. Same rule as the direct-scalar path.
Fixes #2211
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016CjYmSGfnxzJgMSzBESNee
jdorety
left a comment
There was a problem hiding this comment.
LGTM. Production sinks (FlakeSink, ImportSink) infer the datatype from the value, so stored data doesn't change. The regression test fails when the old datatype block is put back.
Nit, not blocking: the comment at adapter.rs:622 says integral numbers get xsd:integer, but the check is as_i64(). So 1.0, 1e3, and integers above i64::MAX get xsd:double. That's consistent with the stored Double value and with the bare-number path in list_item, but it differs from the JSON-LD spec. Maybe reword it to "a number that fits an i64".
The comment said an integral number gets xsd:integer, but the check is as_i64(), so 1.0, 1e3 and an integer past i64::MAX get xsd:double, as their stored value and a bare number in a list do. It now says so, and that JSON-LD's own conversion would call the first two integers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thank you, @jdorety, you're right, and the comment was promising more than the code does. 8d95f49 rewords it as you suggested: |
Fixes #2211
process_literal(fluree-graph-json-ld/src/adapter.rs) labelled every value object without@typeasxsd:string, including what expansion makes of a bare0,1.5ortrue, while keeping the native value. Now an untyped native value takes the datatype JSON-LD's RDF conversion gives it:xsd:booleanfor a boolean;xsd:integerfor an integral number;xsd:doublefor any other number;xsd:stringonly for a string.That's the same rule the direct-scalar path in the same file already uses, so the two now agree. A declared
@typestill wins.On blast radius, which was the thing I most wanted to be sure of. The two database sinks (
flake_sink::term_literal_value,import_sink::term_literal_value) never read the declared datatype for a native value; theyinfer_datatypefrom it. So what transactions and bulk import store shouldn't change.template_sinkdoes hash by the declared datatype, but it's only built inparse/rdf_text, which the Turtle/TriG parser feeds, not this adapter. The ones that do see a difference areGraphCollectorSinkusers (inline_shapes,inline_ontology, and anything that formats a collected graph): they now get"0"^^xsd:integerinstead of"0".Tests:
native_values_without_a_type_keep_their_rdf_datatypecovers integer, double, boolean, string, and a declaredxsd:longthat still wins. It fails without the fix (xsd:stringwherexsd:integeris expected).cargo test -p fluree-graph-json-ld(all suites),-p fluree-db-transact(452 passed),-p fluree-db-api inline(48) andimport(177),-p fluree-graph-turtle -p fluree-graph-format, andcargo clippy -p fluree-graph-json-ld --all-targets --no-deps, all clean.Once this lands, #2207 can drop its local workaround for the same thing (
reader::request::parse_jsonldretypes these literals itself). The workaround is harmless alongside the fix, so there's no merge-order constraint between the two.🤖 Generated with Claude Code
https://claude.ai/code/session_016CjYmSGfnxzJgMSzBESNee