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
DO NOT MERGE: Public version of FixedDecimal proposal #7039
Conversation
The
|
this is discussed in the proposal: I understand you're leaning more towards using sint64. How much would of an overhead is the zigzag encoding itself in your opinion?
You're right but this probably won't lead to any confusion (intuitively integer 0 has "no sign" and it's fair to use it for -123.0) |
My understanding without checking the spec is that initially this costs at most one bit, which will in 1/7th of the cases be enough to cost us an extra byte (with small magnitude numbers still being cheaper than large magnitude). Compared to negative without zig-zag, which costs a hard 10 bytes regardless of size. Is that the question you were asking? |
I meant the computation overhead of performing the zigzag transformation. |
oh, indeed: computationally it is very CPU-friendly - no branching, so it should just pipeline beautifully |
Since there is no particular need to pessimize negative numbers, and negative numbers are not rare in financial applications - can the proposal be updated to have type (sint64, sfixed32)? I'm not sure how much consistence with money.proto matters here. This is generic decimal number support, not specific to money, and money type may not have much need for negative numbers. Also @jtattermusch are there any updates where the discussion is going within Google? |
100% compatibility with message AccountBalance {
string currency = 1;
google.protobuf.FixedDecimal available = 2;
google.protobuf.FixedDecimal usable = 3;
} Here available represents the money in the account and usable how much the owner is actually able to use (which can be more than is available in case the owner has overdraft). Using money in this case makes little sense but being able to switch between the decimal and money is very important for writing abstractions and what not. It‘s unfortunate that |
@Fleshgrinder this makes sense. I forgot that someone may want to read Money wire protocol to FixedDecimal |
Whatever is the outcome of this, it should be supported in |
Interested to hear the likely timeline on acceptance and publication for this PR. |
This is still under internal review and we're considering alternative representations of the type. |
Thanks @jtattermusch ! |
Montly "ping" for the status :) |
Dumb question perhaps, but the following claim is made:
How much support is there for a "negative zero" value in the units or the nanos (depending upon the number)? Or is zero considered to have "no sign" so to speak? Or should the proposal be updated to reflect the wording in money.proto? For example,
|
After a lot of internal discussions, there are some new type defintions that we want to evaluate.
@JamesNK would you be interested in trying to prototype the ToDecimal/FromDecimal C# language bindings and benchmarking their performance / memory efficiency using BenchmarkDotNet? |
Sure. I'll try to do it sometime this week. |
I am sorry if I miss something in the discussion, but currently we are using following format and functions to encode/decode decimals in our software. I didn't invented them - just copied somewhere over the net and they are working till now. converters: public static Protobuf.WellKnownTypes.Decimal ToProtoDecimal(this decimal value)
|
@TrayanZapryanov that is from protobuf-net, and as the person who wrote that, I say officially "oh gawd, burn it with fire, it hurts, it hurts". Or rather: "that is a decision that I regret, and it is horrible". More recently, protobuf-net uses a "compatibility level" concept that allows me to change conventions over time (without breaking existing code), and at the more recent compatibility levels: it does not use that layout. |
@mgravell Thank you for pointing me this. Yes I can remember now and will check how things developed in protobuf-net repo. |
Impatiently waiting on this in C# 👍 |
Hello from 2021. Did you give up on this? |
Any updates on this? I'd love to have support for python's decimals. If you're not planning to add it soon I'll go for a workaround, probably casting to strings. If at all possible I'd like to avoid many backwards incompatible changes to my API. |
@St333p in the meantime we have opted to approach this with a units + nanos approach. It's not perfect but it's reasonable. |
Is this discarded? There will be no standardized decimal number support? |
I was cleaning up old branches and this one hasn't seen any motion for over a year. We definitely don't have short term plans to build this and are already stretched a bit thin on other large efforts. |
Thanks for the insight. Handling "money" values is just not possible with existing protobuf well-known types, it's a little sad. #4406 is important and the lack of this causes many people either to (wrongly) use float types for this kind of magnitude, or use custom non-interoperable messages to properly represent decimal values. |
I am sympathetic to where you are coming from here having worked on fintech in the past. The best advice I can give here is to have strong internal style guidelines. You should either create opaque types to handle money and have dedicated message for them with custom adaptors or store everything as an integral number of pips. The closing of this is not a statement that the suggestion is a bad idea. It is a simple statement of scare resources and trying to set expectations for what we are/are not planning to pursue right now. |
Thank you for your answer. It feels a little underwhelming and I was just expressing some frustration with how the protobuf well-known types are (not) evolving. I understand this is just because of lack of resources. This PR by @jtattermusch seemed a very good direction to me. The problem here is everyone will be defining their own "opaque", non-interoperable message types. Handling numbers is not easy and the lack of this leaves open the door for bad implementations and/or bad decisions. This also leaks to the entire ecosystem built around protobuf... for example, automated grpc-gateway translation of those types for JSON exposure won't happen as there's no standard type to support... so there will be no straightforward "money" support for any grpc-defined API exposed as HTTP in a way that is easy to understand by developers consuming that HTTP api. |
Hmmm… we have Money, what's wrong with it? This PR was about a fixed decimal without currency. As I stated above, a fixed decimal definition ideally is simply compatible with Money. The easiest workaround for the things you mentioned really is a string. JSON can handle it, every language can handle it. That said, I'm also sad that this gets closed. 😿 |
I didn't know this type existed 🤦 my use-case doesn't involve actual money but other type of fixed-decimal magnitudes, I was arguing for the "money" case because it seems easiest to understand. My bad. |
I think that there are plenty of use cases for it, and nobody questions that, but especially the one you mentioned wouldn't be covered by this. JS(ON) has no support for 64 bit numbers, so anyone trying to do that there will end up with strings or funny surprises. The safest route really is a string here. |
Sorry for the offtopic. I understand it's JS that doesn't support 64-bit integer, but not JSON itself, both JSON document format and JSON schema are fine with arbitrary precision numbers. |
Absolutely, but when you mention gateway I think of JS. If JS isn't involved, why the gateway and not gRPC? But yeah, getting too off topic. 😉 |
Sadly three decimal places is insufficient. Working in electricity sector, with normalised pricing in the 6-7 decimal places space. Further, floating point issues for values that need decimal support is sorely needed. :sadpanda: (I missed the closure of this issue). |
I think it would be useful to get these few more common data types into For the decimal floating types, I referenced [this protobuf discussion](protocolbuffers/protobuf#7039 (comment)) and [this](https://github.com/googleapis/googleapis/blob/master/google/type/decimal.proto) I'm not sure what to call out for the currency format, I can't find a standard for that yet. There's a [protobuf money type](https://github.com/googleapis/googleapis/blob/master/google/type/money.proto) that's basically a ISO 4217 currency code plus a decimal number, but I don't really want to invent a suggested money format if there's a real one out there somewhere. For this PR, can we just leave it TBD in order to reserve the type keyword?
I think it would be useful to get these few more common data types into For the decimal floating types, I referenced [this protobuf discussion](protocolbuffers/protobuf#7039 (comment)) and [this](https://github.com/googleapis/googleapis/blob/master/google/type/decimal.proto) I'm not sure what to call out for the currency format, I can't find a standard for that yet. There's a [protobuf money type](https://github.com/googleapis/googleapis/blob/master/google/type/money.proto) that's basically a ISO 4217 currency code plus a decimal number, but I don't really want to invent a suggested money format if there's a real one out there somewhere. For this PR, can we just leave it TBD in order to reserve the type keyword?
Need support for Decimal128, so new fixed width wire type. Workaround is to use with additional validation, but would prefer native scalar Decimal128. Big Decimal can also be represented with bytes, or else string. |
This is basically a copy of the internal proposal (as we currently don't have a open source proposal process in place for protobuf).
See #4406