Repository navigation
Conversation
…ores A decimal written since the last index build kept the scale it was written with, and a double kept the sign of -0.0, so a query printed 1.50 or -0.0E0 until the ledger was indexed and 1.5 or 0.0E0 after, with no write in between. Matching was already by value; only the printed form changed. FlakeValue::decimal (normalized) and FlakeValue::double (-0.0 as 0.0) build a number as the index keys it, and every place a number is read from text or a JSON number goes through them: write coercion, bare Turtle and JSON-LD numbers, SPARQL, JSON-LD and Cypher constants, import's raw doubles, flake deserialization, and the commit decoder, which reads a commit an earlier release wrote with 1.50 as 1.5. Arithmetic keeps the scale it computes. This settles D-11 as a documented deviation: Fluree stores a number as its value, not its lexical form, so 01, +1 and 1 are one term. compatibility.md, datatypes.md and sparql-compliance.md say so, and the W3C register entries that tell such terms apart say they are decided.
A graph source's cells reached terms through the same coercion a write uses, so they picked up the write's normalization: a decimal(10,2) column's 99.50 read as 99.5, and a double's -0.0 as 0.0. A database's SUM, MIN and MAX return the table's form, so the SQL lane printed 104.50 where the scan lane printed 104.5, and a pinned decimal read back without its reported scale. The literal encoder now parses a decimal or double cell as the table holds it, as it did before. compatibility.md already said a graph source's decimal keeps its column's scale; it now says the same of -0.0. The set-semantics suite compares a graph source with a ledger holding the same triples. A ledger stores 1.00 as 1, so its GROUP BY over a decimal compares the printed values as numbers. The Python round trip expects a ledger's 1.50 back as 1.5.
An xsd:float was stored at double precision, tagged only by its
datatype, and each reader took its spelling from whichever half it
looked at. "0.1234567890123"^^xsd:float serialized as
1.234567890123E-1 while arithmetic and STR() of an expression used the
float, 1.2345679E-1; a GROUP BY key minted a third spelling,
0.12345679; and "3.4e39"^^xsd:float was a finite value that its own
cast made INF.
A float is now stored as its single-precision value, held as the
double nearest the float's shortest decimal form
(float_as_stored_double). A printer of the double prints the float's
canonical form, `as f32` gives the float back, and order is kept. A
float written as the shortest form of a float value, such as 0.5 or
3.14, is stored as before, so a bare numeric constant still matches it.
Every f32 was checked: for +-7.038531e-26 the nearest double converts
to the next float, so they are stored one double step toward it.
canonical_xsd_float is the canonical form of the stored double, so
STR() and the serializers agree for those two as well.
FlakeValue::float builds the value, and write coercion goes through
it for a lexical, a JSON number, an integer or a double under
xsd:float, as do query constants. The commit retag reads a float that
an earlier release committed at double precision as the float, so
novelty, a reload and a ledger's first 5.0 index build, which rebuilds
from commits, all hold it at single precision.
A float an expression computes (a cast, arithmetic, a group key) is
minted as the stored value rather than as text. It joins, groups and
prints as a stored float: xsd:float("0.5") matches a stored 0.5, and
?f + 0 prints 1.0E0, not 1. xsd:string() keeps the XPath cast form.
stored_float_f64 and STR()'s fast path, which read the double off the
binding to agree with the serializer, are gone.
compatibility.md gives the behaviour change and the window before a
ledger's first 5.0 index build, when an earlier index still holds a
float with more digits than single precision keeps.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A decimal now reads back without the trailing zeros it was written with, and a double's
-0.0reads back as0.0, from the moment it is written. The index has always stored them that way. But a value written since the last index build was held as written, so a query printed1.50until the ledger was indexed and1.5after, with no write in between. Matching was already by value; only the printed form changed.This also records decision D-11 (#1696): Fluree stores a number as its value, not its lexical form, so
01,+1and1are one term. Integers and doubles already behaved this way. This PR brings decimals and-0.0into line and documents the rule as a deviation.It also settles #1776: an
xsd:floatis stored at single precision, the value XSD defines, so one float term has one spelling everywhere.What changes
FlakeValue::decimalandFlakeValue::doublebuild a value as it is stored: a normalizedBigDecimal, and-0.0folded to0.0. Every place a number is read from text or a JSON number now goes through them:coerce_value,coerce_string_value, JSON numbers), which every JSON-LD, Turtle, TriG and bulk-import write uses;convert_native_literal), and import's raw doubles;1.50reads as1.5;1.50 + 1.50is3.0), as before.-0.0. A database'sSUM,MINandMAXreturn that form, so the SQL lane and the scan lane build the same terms.xsd:floatis stored at single precision (Float rendering keys on theDoublevariant, not the declaredxsd:floatdatatype — one term, three spellings #1776). It was stored at double precision, and each reader spelled it from whichever half it looked at."0.1234567890123"^^xsd:floatserialized as1.234567890123E-1,STR()of an expression gave1.2345679E-1, and aGROUP BYkey0.12345679."3.4e39"^^xsd:floatwas finite, though its cast isINF.FlakeValue::floatstores a float as the double nearest its shortest decimal form (float_as_stored_double). Every printer of the double prints the float's canonical form, andas f32gives the float back. A float written as the shortest form of a float value, such as0.5or3.14, is stored as before. So a bare numeric constant still matches it, and an index an earlier release built differs only for floats with more digits than single precision keeps.f32was checked once, outside the suite: the stored double converts back, prints the float's shortest form and keeps float order. The exceptions are ±7.038531e-26, whose nearest double converts to the next float. Those two are stored one double step toward the float.canonical_xsd_floatis the canonical form of the stored double, soSTR()and the serializers still agree on them.xsd:float("0.5")matches a stored0.5,?f + 0prints1.0E0(was1), and JSON-LD prints{"@value": 2.5, "@type": "xsd:float"}(was a string@value).xsd:string()keeps the XPath cast form.stored_float_f64andSTR()'s fast path, which read the double off the binding to agree with the serializer, are gone.compatibility.md(RDF 1.1), and behaviour-change entries for decimals and for floats. The float entry covers the window before a ledger's first 5.0 index build, when an earlier index still holds a float with more digits than single precision keeps;datatypes.md;sparql-compliance.md.group01, the D6 expression tests and the numeric-lexical Turtle/TriG tests now say they are a decided deviation. No entry was added or removed.Cost
Write path: one
normalized()per decimal, one comparison per double, and one format and parse per float. Staging and the index encoder already normalize every decimal they hash or key. The commit decoder adds one datatype comparison per double it reads. A float an expression mints takes one format and parse, in place of the text it formatted and allocated before. On the read path, the only other cost is parsing a query constant.Tests
it_numeric_storage_canonical:INSERT DATAandINSERT … WHERE, JSON-LD insert and upsert, Turtle insert and upsert, TriG, graph sync,Transaction, push and bulk import. The values are"1.50","100.00","-0.00", a bare1.50,"-0.0"^^xsd:double, a bare-0.0e0,"0.1234567890123"^^xsd:floatand"3.4e39"^^xsd:float(a JSON number in the JSON-LD lanes);WHEREbinds (VALUES,BIND, JSON-LDvalues);1.50 + 1.50keeping scale 1;a_computed_float_is_the_stored_float: a cast joins the stored float, and arithmetic and a group key print as it does, in SPARQL and in JSON-LD.op_codec::decoding_reads_a_number_as_its_value: a commit holding1.50,100.00,-0.0and a float at double precision, as an earlier release wrote them, decodes to the stored value. A double keeps its precision.raw_reader::a_raw_float_reads_at_single_precision: the same through the raw reader that index builds use.fluree-graph-ir: a strided walk overf32bit patterns, and the two exceptions.STR()float tests,a_float_beyond_its_range_is_stored_as_inf(was…_stored_at_double_precision), and three tests that pinned a computed float's string@valuein JSON-LD.it_decimal_exactness's novelty-vs-indexed differential now compares exactly. Itscanon_decimal_bindingshelper, which hid this difference, is gone.Non-vacuity:
nextwithout the fix, the new tests fail: every lane rendered1.50/-0.0E0as written and1.5/0.0E0once indexed.convert_native_literal, the SPARQL update template decimal, and the SPARQL query double.1.234567890123E-1and3.4E39, andSTR()prints1.2345679E-1andINF;a_computed_float_is_the_stored_floatfails, and the cast joins nothing.fluree-db-query/src/parse/lower.rsgo through the constructor for uniformity, but reverting them changes nothing observable. They lower pattern constants in a SPARQL update'sWHERE, which match by value and are never stored.Fixes #1696
Fixes #2090. This is its last open item, the decimal scale and
-0.0. Its re-upsert and sub-microsecond items were fixed by #2109, and its big-integer items by #2477. Itsxsd:floatprecision item moved to #1776, settled here.Fixes #1776