You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2022/01/21 10:25:00 UTC

[jira] [Work logged] (AVRO-3254) .NET - Automatically scale AvroDecimal values when serializing

     [ https://issues.apache.org/jira/browse/AVRO-3254?focusedWorklogId=712716&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-712716 ]

ASF GitHub Bot logged work on AVRO-3254:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 21/Jan/22 10:24
            Start Date: 21/Jan/22 10:24
    Worklog Time Spent: 10m 
      Work Description: RyanSkraba commented on pull request #1404:
URL: https://github.com/apache/avro/pull/1404#issuecomment-1018375155


   Hello!  I have a quick concern about this PR -- modifying the scale of an AvroDecimal makes it no longer equal to its old value, so the serialize/deserialize would make the datum, or any record containing the datum (for example), no longer equal to its original value.
   
   I would be worried that this would have some unexpected side effects.  Any thoughts?
   
   We should take a look at what the other SDKs are doing.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Issue Time Tracking
-------------------

            Worklog Id:     (was: 712716)
    Remaining Estimate: 0h
            Time Spent: 10m

> .NET - Automatically scale AvroDecimal values when serializing
> --------------------------------------------------------------
>
>                 Key: AVRO-3254
>                 URL: https://issues.apache.org/jira/browse/AVRO-3254
>             Project: Apache Avro
>          Issue Type: Improvement
>          Components: csharp
>            Reporter: Nathan Daniels
>            Priority: Minor
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> *Problem*
> When serializing an {{{}AvroDecimal{}}}, the Decimal class's {{ConvertToBaseValue}} method will throw an exception if the scale of the decimal does not exactly match the scale defined in the schema.
> The exception goes something like
> `{{{}The decimal value has a scale of \{scale} which cannot be encoded against a logical 'decimal' with a scale of \{logicalScale}{{}}}}`
> I feel this is far too restrictive and unintuitive from a usability perspective.  For example, it is not possible to serialize the c# decimal 1.0m into a schema field of precision 20 and scale 2, because 1.0 has a "scale" of 1.  Instead, the user must force the decimal to be {{1.00m}} if they want to serialize despite the fact that 1.0 and 1.00 are the same exact real number.  Now the user needs to be aware of the scale defined in the schema before attempting to serialize.
> *Solution?*
> I propose the {{Decimal}} and {{AvroDecimal}} classes be smart enough to re-scale a value into the scale specified in the schema if doing so would not result in data loss.  It is relatively trivial operation to do so, and would make using {{AvroDecimal}} much easier.
> I will open a PR with my proposed improvement, but essentially the {{Decimal}} class will convert the {{AvroDecimal}} to the desired scale prior to serialization, and continue to throw the exception if doing so would result in data loss.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)