You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "rayokota (via GitHub)" <gi...@apache.org> on 2025/07/01 00:13:17 UTC

[PR] AVRO-4161: [C#] Fix System.Decimal to Avro decimal conversion [avro]

rayokota opened a new pull request, #3423:
URL: https://github.com/apache/avro/pull/3423

   <!--
   
   *Thank you very much for contributing to Apache Avro - we are happy that you want to help us improve Avro. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   *Please understand that we do not do this to make contributions to Avro a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/AVRO/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
     
     - Name the pull request in the form "AVRO-XXXX: [component] Title of the pull request", where *AVRO-XXXX* should be replaced by the actual issue number. 
       The *component* is optional, but can help identify the correct reviewers faster: either the language ("java", "python") or subsystem such as "build" or "doc" are good candidates.  
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Make sure that the change passes the automated tests. You can [build the entire project](https://github.com/apache/avro/blob/main/BUILD.md) or just the [language-specific SDK](https://avro.apache.org/project/how-to-contribute/#unit-tests).
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message (including the JIRA id)
   
     - Every commit message references Jira issues in their subject lines. In addition, commits follow the guidelines from [How to write a good git commit message](https://chris.beams.io/posts/git-commit/)
       1. Subject is separated from body by a blank line
       1. Subject is limited to 50 characters (not including Jira issue reference)
       1. Subject does not end with a period
       1. Subject uses the imperative mood ("add", not "adding")
       1. Body wraps at 72 characters
       1. Body explains "what" and "why", not "how"
   
   -->
   
   ## What is the purpose of the change
   
   The conversion from the C# System.Decimal to an Avro logical type decimal is not correct. The first 12 bytes of the System.Decimal represent a positive unscaled value. This value is passed into a BigInteger constructor. However, the documentation of the [BigInteger constructor](https://learn.microsoft.com/en-us/dotnet/api/system.numerics.biginteger.-ctor?view=net-9.0#system-numerics-biginteger-ctor(system-byte())) states that the most significant bit of the last byte represents the sign of the BigInteger. The docs also explain that a 0 byte can be appended to the byte array passed to the BigInteger constructor to ensure the value is treated as positive.
   
   ## Verifying this change
   
   Added a test that fails without the fix.
   
   *(Please pick one of the following options)*
   
   This change is a trivial rework / code cleanup without any test coverage.
   
   *(or)*
   
   This change is already covered by existing tests, such as *(please describe tests)*.
   
   *(or)*
   
   This change added tests and can be verified as follows:
   
   *(example:)*
   - *Extended interop tests to verify consistent valid schema names between SDKs*
   - *Added test that validates that Java throws an AvroRuntimeException on invalid binary data*
   - *Manually verified the change by building the website and checking the new redirect*
   
   
   ## Documentation
   
   - Does this pull request introduce a new feature? (yes / no)
   
   


-- 
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: dev-unsubscribe@avro.apache.org

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


Re: [PR] AVRO-4161: [C#] Fix System.Decimal to Avro decimal conversion [avro]

Posted by "rayokota (via GitHub)" <gi...@apache.org>.
rayokota commented on PR #3423:
URL: https://github.com/apache/avro/pull/3423#issuecomment-3026560280

   > Filed the AvroDecimal.CompareTo bug as [AVRO-4162](https://issues.apache.org/jira/browse/AVRO-4162).
   
   I can take a look at this after this PR is merged


-- 
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


Re: [PR] AVRO-4161: [C#] Fix System.Decimal to Avro decimal conversion [avro]

Posted by "rayokota (via GitHub)" <gi...@apache.org>.
rayokota commented on PR #3423:
URL: https://github.com/apache/avro/pull/3423#issuecomment-3063882703

   @martin-g , I added a requested test, would it be possible for you to kick off another build?  Thanks!


-- 
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


Re: [PR] AVRO-4161: [C#] Fix System.Decimal to Avro decimal conversion [avro]

Posted by "rayokota (via GitHub)" <gi...@apache.org>.
rayokota commented on PR #3423:
URL: https://github.com/apache/avro/pull/3423#issuecomment-3021242204

   @KalleOlaviNiemitalo @zcsizmadia could I kindly get a review? Thanks in advance!


-- 
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


Re: [PR] AVRO-4161: [C#] Fix System.Decimal to Avro decimal conversion [avro]

Posted by "KalleOlaviNiemitalo (via GitHub)" <gi...@apache.org>.
KalleOlaviNiemitalo commented on code in PR #3423:
URL: https://github.com/apache/avro/pull/3423#discussion_r2188160570


##########
lang/csharp/src/apache/test/AvroDecimalTest.cs:
##########
@@ -38,7 +38,19 @@ public void TestAvroDecimalToString(decimal value)
         {
             var valueString = value.ToString();
 
-            var avroDecimal = new AvroDecimal(value);            
+            var avroDecimal = new AvroDecimal(value);
+            var avroDecimalString = avroDecimal.ToString();
+
+            Assert.AreEqual(valueString, avroDecimalString);
+        }
+
+        [Test]
+        public void TestHighPrecisionAvroDecimalToString()
+        {
+            var value = 4.1748330066797328106875724512m; // High precision decimal value

Review Comment:
   Can you add a test of converting a negative `decimal` to AvroDecimal?  Even though this PR doesn't change how that works.



-- 
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


Re: [PR] AVRO-4161: [C#] Fix System.Decimal to Avro decimal conversion [avro]

Posted by "rayokota (via GitHub)" <gi...@apache.org>.
rayokota commented on code in PR #3423:
URL: https://github.com/apache/avro/pull/3423#discussion_r2188398634


##########
lang/csharp/src/apache/test/AvroDecimalTest.cs:
##########
@@ -38,7 +38,19 @@ public void TestAvroDecimalToString(decimal value)
         {
             var valueString = value.ToString();
 
-            var avroDecimal = new AvroDecimal(value);            
+            var avroDecimal = new AvroDecimal(value);
+            var avroDecimalString = avroDecimal.ToString();
+
+            Assert.AreEqual(valueString, avroDecimalString);
+        }
+
+        [Test]
+        public void TestHighPrecisionAvroDecimalToString()
+        {
+            var value = 4.1748330066797328106875724512m; // High precision decimal value

Review Comment:
   Sure, I added a test for a negative high precision value



-- 
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


Re: [PR] AVRO-4161: [C#] Fix System.Decimal to Avro decimal conversion [avro]

Posted by "KalleOlaviNiemitalo (via GitHub)" <gi...@apache.org>.
KalleOlaviNiemitalo commented on code in PR #3423:
URL: https://github.com/apache/avro/pull/3423#discussion_r2179887055


##########
lang/csharp/src/apache/test/AvroDecimalTest.cs:
##########
@@ -38,7 +38,19 @@ public void TestAvroDecimalToString(decimal value)
         {
             var valueString = value.ToString();
 
-            var avroDecimal = new AvroDecimal(value);            
+            var avroDecimal = new AvroDecimal(value);
+            var avroDecimalString = avroDecimal.ToString();
+
+            Assert.AreEqual(valueString, avroDecimalString);
+        }
+
+        [Test]
+        public void TestHighPrecisionAvroDecimalToString()
+        {
+            var value = 4.1748330066797328106875724512m; // High precision decimal value

Review Comment:
   Specified in [C# 5 section 7.4.5.4 Real literals](https://github.com/dotnet/csharpstandard/blob/V5-standard/standard/lexical-structure.md#7454-real-literals).



-- 
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


Re: [PR] AVRO-4161: [C#] Fix System.Decimal to Avro decimal conversion [avro]

Posted by "martin-g (via GitHub)" <gi...@apache.org>.
martin-g commented on PR #3423:
URL: https://github.com/apache/avro/pull/3423#issuecomment-3039810946

   Just wait ...
   I guess @zcsizmadia will take a look soon.


-- 
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


Re: [PR] AVRO-4161: [C#] Fix System.Decimal to Avro decimal conversion [avro]

Posted by "martin-g (via GitHub)" <gi...@apache.org>.
martin-g commented on code in PR #3423:
URL: https://github.com/apache/avro/pull/3423#discussion_r2179826429


##########
lang/csharp/src/apache/test/AvroDecimalTest.cs:
##########
@@ -38,7 +38,19 @@ public void TestAvroDecimalToString(decimal value)
         {
             var valueString = value.ToString();
 
-            var avroDecimal = new AvroDecimal(value);            
+            var avroDecimal = new AvroDecimal(value);
+            var avroDecimalString = avroDecimal.ToString();
+
+            Assert.AreEqual(valueString, avroDecimalString);
+        }
+
+        [Test]
+        public void TestHighPrecisionAvroDecimalToString()
+        {
+            var value = 4.1748330066797328106875724512m; // High precision decimal value

Review Comment:
   What is `m` at the end of the number ? Magic ? :-)



-- 
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


Re: [PR] AVRO-4161: [C#] Fix System.Decimal to Avro decimal conversion [avro]

Posted by "martin-g (via GitHub)" <gi...@apache.org>.
martin-g merged PR #3423:
URL: https://github.com/apache/avro/pull/3423


-- 
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: dev-unsubscribe@avro.apache.org

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


Re: [PR] AVRO-4161: [C#] Fix System.Decimal to Avro decimal conversion [avro]

Posted by "KalleOlaviNiemitalo (via GitHub)" <gi...@apache.org>.
KalleOlaviNiemitalo commented on code in PR #3423:
URL: https://github.com/apache/avro/pull/3423#discussion_r2179878195


##########
lang/csharp/src/apache/test/AvroDecimalTest.cs:
##########
@@ -38,7 +38,19 @@ public void TestAvroDecimalToString(decimal value)
         {
             var valueString = value.ToString();
 
-            var avroDecimal = new AvroDecimal(value);            
+            var avroDecimal = new AvroDecimal(value);
+            var avroDecimalString = avroDecimal.ToString();
+
+            Assert.AreEqual(valueString, avroDecimalString);
+        }
+
+        [Test]
+        public void TestHighPrecisionAvroDecimalToString()
+        {
+            var value = 4.1748330066797328106875724512m; // High precision decimal value

Review Comment:
   It's C# syntax for a constant of type `decimal`.



-- 
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


Re: [PR] AVRO-4161: [C#] Fix System.Decimal to Avro decimal conversion [avro]

Posted by "rayokota (via GitHub)" <gi...@apache.org>.
rayokota commented on PR #3423:
URL: https://github.com/apache/avro/pull/3423#issuecomment-3036846772

   @martin-g @zcsizmadia , anything else I need to do for this PR?  Thanks!


-- 
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


Re: [PR] AVRO-4161: [C#] Fix System.Decimal to Avro decimal conversion [avro]

Posted by "KalleOlaviNiemitalo (via GitHub)" <gi...@apache.org>.
KalleOlaviNiemitalo commented on PR #3423:
URL: https://github.com/apache/avro/pull/3423#issuecomment-3021555777

   This looks OK but I have doubts about AvroDecimal.CompareTo


-- 
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


Re: [PR] AVRO-4161: [C#] Fix System.Decimal to Avro decimal conversion [avro]

Posted by "KalleOlaviNiemitalo (via GitHub)" <gi...@apache.org>.
KalleOlaviNiemitalo commented on PR #3423:
URL: https://github.com/apache/avro/pull/3423#issuecomment-3022883855

   Filed the AvroDecimal.CompareTo bug as [AVRO-4162](https://issues.apache.org/jira/browse/AVRO-4162).


-- 
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


Re: [PR] AVRO-4161: [C#] Fix System.Decimal to Avro decimal conversion [avro]

Posted by "KalleOlaviNiemitalo (via GitHub)" <gi...@apache.org>.
KalleOlaviNiemitalo commented on PR #3423:
URL: https://github.com/apache/avro/pull/3423#issuecomment-3026611934

   If you're interested in fixing more AvroDecimal conversion bugs, there's also the infinite recursion [AVRO-3569](https://issues.apache.org/jira/browse/AVRO-3569).


-- 
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