[ 
https://issues.apache.org/jira/browse/AVRO-4162?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17987153#comment-17987153
 ] 

Kalle Niemitalo commented on AVRO-4162:
---------------------------------------


The bug is [in the AvroDecimal.CompareTo(AvroDecimal) 
method|https://github.com/apache/avro/blob/8c27801dc8d42ccc00997f25c0b8f45f8d4a233e/lang/csharp/src/apache/main/AvroDecimal.cs#L1137-L1144]:

{code:csharp}
            var unscaledValueCompare = 
UnscaledValue.CompareTo(other.UnscaledValue);
            var scaleCompare = Scale.CompareTo(other.Scale);

            // if both are the same value, return the value
            if (unscaledValueCompare == scaleCompare)
            {
                return unscaledValueCompare;
            }
{code}

Because 155 > 25, {{unscaledValueCompare}} is positive; in practice it's 1.
Because 2 > 1, {{scaleCompare}} is positive; in practice it's 1.
But even though 155 > 25 and 2 > 1, it does not mean that 1.55 > 2.5.

Fixing this should be careful not to break the correct behaviour with negative 
{{UnscaledValue}}, where a larger {{Scale}} makes the number less negative and 
thus greater.

> C# AvroDecimal.CompareTo 
> -------------------------
>
>                 Key: AVRO-4162
>                 URL: https://issues.apache.org/jira/browse/AVRO-4162
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: csharp
>    Affects Versions: 1.12.0
>            Reporter: Kalle Niemitalo
>            Priority: Major
>
> {{new AvroDecimal(unscaledValue: 155, scale: 2).CompareTo(new 
> AvroDecimal(unscaledValue: 25, scale: 1))}} returns 1, but it should return a 
> negative number because 1.55 < 2.5.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to