feat(core): add decimal type#1719
Open
benjamin-awd wants to merge 2 commits intovectordotdev:mainfrom
Open
Conversation
9 tasks
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.
Summary
This PR adds support for a new
decimaltype backed by therust_decimalcrate, providing 96-bit precision decimal arithmetic to solve long-standing floating-point precision loss issues (#1503, #755). Sibling Vector PR: vectordotdev/vector#25048.Added a
d'...'literal syntax for decimal values in VRL programs (e.g.,d'0.12379999458789825'), consistent with VRL's existing quoted-literal conventions (r'...'for regex). Decimal literals are parsed at compile time intorust_decimal::Decimalvalues with no f64 intermediate.parse_json(parse_float: "decimal")enables precision-preserving JSON ingress. Instead of deserializing through f64, this path usesserde_json::RawValueto capture each number's original string representation, then parses directly intoDecimal. This avoids the two-step precision loss that causes issues like0.12379999458789825→0.12379999458789824.This is fully opt-in -- existing behavior is unchanged.
Note: moved away from the
arbitrary_precisionsyntax since that's quite specific to serde_json and an implementation detail that some users may not understand, instead drew inspiration from Python's parse_float(decimal) syntax.Change Type
Is this a breaking change?
We'll keep this opt-in. Within the VRL crate, unless the arbitrary_precision argument is passed in
parse_jsonthe default behavior will occur.On the Vector side, it'll similarly be opt-in e.g.
How did you test this PR?
Tests within this PR and a sibling PR in Vector
Does this PR include user facing changes?
our guidelines.
Checklist
run
dd-rust-license-tool writeand commit the changes. More details here.Note: rust-decimal is already included in the LICENSE-3rdparty.csv file.
References
Closes #1692