Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUST-36 Support of Decimal128 type #53

Closed
zonyitoo opened this issue Feb 4, 2017 · 25 comments
Closed

RUST-36 Support of Decimal128 type #53

zonyitoo opened this issue Feb 4, 2017 · 25 comments
Labels
tracked-in-jira Ticket filed in Mongo's Jira system

Comments

@zonyitoo
Copy link
Contributor

zonyitoo commented Feb 4, 2017

According to BSON 1.1 Spec, it introduced a new type decimal128.

But currently Rust doesn't support d128 type natively.

Related links

  1. d128 crate: https://github.com/alkis/decimal
  2. Official support RFC: Add a BigDecimal type rust-num/num#8
@zonyitoo
Copy link
Contributor Author

zonyitoo commented Feb 4, 2017

Thoughts? @kyeah

@kyeah
Copy link
Contributor

kyeah commented Feb 4, 2017

nice, just one comment; looks great otherwise.

@saghm
Copy link
Contributor

saghm commented Feb 4, 2017

I believe crates.io doesn't let you publish a crate that has both git and crates.io dependencies. Is there any chance that the author of the decimal crate might accept a PR?

EDIT: Oops, that was the "one comment"; never mind!

@zonyitoo
Copy link
Contributor Author

zonyitoo commented Feb 5, 2017

I have already submitted a PR to alkis/decimal#23 . I will remove that git dep after this PR is accepted.

@lrlna
Copy link
Contributor

lrlna commented Jan 5, 2019

I see there is a commit with decimal128 support already. Are you still thinking of merging that commit in? Would love to see that happen!

@zonyitoo
Copy link
Contributor Author

zonyitoo commented Jan 6, 2019

Don't know if it is the best way to support decimal 128 in Rust, yet.

Rust is now supported i128 and u128. Maybe in the future it will support d128?

@lrlna
Copy link
Contributor

lrlna commented Jan 7, 2019

@zonyitoo by the best way do you mean you're not sure if using the decimal crate is a good idea, or is this more about whether the support is up to the spec?

it's possible core will support d128, but I feel like that might be a long way off :(. In the meantime would be cool to have a workaround \o/

@zonyitoo
Copy link
Contributor Author

zonyitoo commented Jan 7, 2019

Yes, I agree. I would take sometime to make this commit works with the master.

@lrlna
Copy link
Contributor

lrlna commented Jan 9, 2019

@zonyitoo if you feel like it's more work than you have capacity for, I can also help out! I just didn't want to step on your toes, since there was already a commit going.

@zonyitoo
Copy link
Contributor Author

@lrlna That would be great! I don't have spear time in the recent future :(

lrlna pushed a commit to lrlna/bson-rs that referenced this issue Feb 27, 2019
lrlna pushed a commit to lrlna/bson-rs that referenced this issue Feb 27, 2019
zonyitoo pushed a commit that referenced this issue Mar 14, 2019
* [#53] supports decimal128 and add necessary documents

* add documentation for decimal128 methods

* add serialize + deserialize for decimal128

* add decimal128 tests + into_i32/_u32 methods
@saghm
Copy link
Contributor

saghm commented Feb 10, 2020

We can use https://jira.mongodb.org/browse/RUST-36 to track the work done for this issue

@nevi-me
Copy link

nevi-me commented Feb 23, 2020

I filed mongodb-rust/mongodb-schema-parser#35 before I saw this conversation. I am trying to parse a collection's schema using the schema parser. However because mongodb doesn't build with the feature = ["decimal128"] from the bson crate, I'm encountering a non-exhaustive pattern as per below.

    Checking mongodb v0.9.1
error[E0004]: non-exhaustive patterns: `&Decimal128(_)` not covered
   --> C:\Users\me\.cargo\registry\src\github.com-1ecc6299db9ec823\mongodb-0.9.1\src\bson_util.rs:128:11
    |
128 |     match val {
    |           ^^^ pattern `&Decimal128(_)` not covered
    |
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms

This is with the below Cargo.toml

[dependencies]
bson = { version = "0.14", features = ["decimal128"] }
mongodb = "0.9.1"
# this contains the patch to use bson 0.14 on the schema parser
mongodb-schema-parser = { git = "https://github.com/nevi-me/mongodb-schema-parser", branch = "update-bson" }

I don't need decimal128 support, so I'll fork the mongodb crate and add the extra pattern for now.

@Alexander-L-G Alexander-L-G added the tracked-in-jira Ticket filed in Mongo's Jira system label Nov 30, 2020
@bugproof
Copy link

bugproof commented Jun 18, 2021

I tried to read data from mongodb collection that uses decimal128 but it panics

thread 'main' panicked at 'Attempted conversion of invalid data type: Decimal128(...)', C:\Users\Konrad.cargo\registry\src\github.aaakk.us.kg-1ecc6299db9ec823\bson-2.0.0-beta.1\src\bson.rs:587:18
stack backtrace:...

Is there any workaround or it's simply not possible with rust's mongodb library?

EDIT:

I had to explicitly add this to [dependencies]:

bson = { version = "2.0.0-beta.1", features = ["decimal128"] }

@patrickfreed
Copy link
Contributor

@bugproof This was a bug actually that has since been fixed in 2.0.0-beta.3 and 1.2.3. Note that the decimal128 feature flag has been removed in 2.0.0-beta.3 (see #282), so you'll need to remove that workaround. Deserialization from documents that contain decimal128 values should work just fine now though.

@patrickfreed patrickfreed changed the title Support of Decimal128 type RUST-36 Support of Decimal128 type Feb 8, 2022
@emreyalvac
Copy link

Any update?

@dotjon0
Copy link

dotjon0 commented Sep 9, 2022

Just checking in to see if there has been any update on this?

@dotjon0
Copy link

dotjon0 commented Nov 2, 2022

Could the MongoDB team provide feedback of where support for Decimal128 is at? This issue was originally raised in 2017 and with no recent updates.

A could of key points:

  1. MongoDB recommends Decimal128 as the best option for 'monetary' high precision values https://www.mongodb.com/docs/manual/tutorial/model-monetary-data/

  2. Rust is becoming a very mainstream language. Lack of Decimal128 support could block development teams from using MongoDB Atlas if they have adopted rust.

@kmahar
Copy link

kmahar commented Nov 2, 2022

Hi @dotjon0, our current plan is to start implementation of this ~1 month from now.

@dotjon0
Copy link

dotjon0 commented Nov 2, 2022

@kmahar thank you so much for the update, its very appreciated. Great to hear Decimal128 implementation is commencing in only a few weeks! Absolute fantastic news! Will look forward and thank you for making the time to update us.

@lrlna
Copy link
Contributor

lrlna commented Nov 8, 2022

@kmahar hello 👋 ! I think there might be some interest in rust's standard library to have rust support decimal 128 implementation natively. If you end up writing this implementation from scratch, would be super cool if you could contribute it back to rust itself :) There is already a u128/i128, so std is close!

@kmahar
Copy link

kmahar commented Nov 9, 2022

hey @lrlna! 🙂 I think to start this type would likely only support converting back and forth between string <-> decimal128 byte representations, and in the future we may try to support conversion to/from other Rust numeric types. If there was a std decimal128 type we’d want to support interop with that, and we could potentially switch to using it in lieu of our type if it supported BID coefficient encoding.
We’d be very happy to contribute our string <-> bytes logic upstream if that helps along an implementation, but at this time I think it’s unlikely we’ll end up writing a full-featured type ourselves that directly supports math like I assume a std type would. However, if that changes we’ll definitely keep this in mind!

@dotjon0
Copy link

dotjon0 commented Nov 18, 2022

I think to start this type would likely only support converting back and forth between string <-> decimal128 byte representations,

amazing, exactly what we need! Thanks so much @kmahar

@abr-egn
Copy link
Contributor

abr-egn commented Feb 2, 2023

Sorry for the long delay here, just wanted to let people know that implementation of conversion to and from human-readable strings for the Decimal128 type has started, and we expect this to go out in the next driver release. If there's other functionality that would be particularly useful, please let us know! It's unlikely to be part of the upcoming feature addition but will definitely inform future priorities.

@abr-egn
Copy link
Contributor

abr-egn commented Mar 14, 2023

We just released version 2.6.0 of the bson crate, which includes support for conversion between Decimal128 values and human-readable strings 🙂

@abr-egn abr-egn closed this as completed Mar 14, 2023
@dotjon0
Copy link

dotjon0 commented Apr 14, 2023

We just released version 2.6.0 of the bson crate, which includes support for conversion between Decimal128 values and human-readable strings 🙂

amazing @abr-egn thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tracked-in-jira Ticket filed in Mongo's Jira system
Projects
None yet
Development

No branches or pull requests