You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by rs...@apache.org on 2021/12/20 17:54:36 UTC

[avro] 03/04: AVRO-3218 Fix parsing of logicalType = decimal (#1350)

This is an automated email from the ASF dual-hosted git repository.

rskraba pushed a commit to branch branch-1.11
in repository https://gitbox.apache.org/repos/asf/avro.git

commit 9b2de4ac2febea6f18c4f7877164027350224f91
Author: Vegard Solberg <39...@users.noreply.github.com>
AuthorDate: Sat Dec 18 02:59:46 2021 +0100

    AVRO-3218 Fix parsing of logicalType = decimal (#1350)
    
    Co-authored-by: Vegard Solberg <ve...@statnett.no>
---
 lang/py/avro/schema.py           | 2 +-
 lang/py/avro/test/test_schema.py | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lang/py/avro/schema.py b/lang/py/avro/schema.py
index 1d3b369..73371d5 100644
--- a/lang/py/avro/schema.py
+++ b/lang/py/avro/schema.py
@@ -1067,7 +1067,7 @@ def get_other_props(all_props: Mapping[str, object], reserved_props: Sequence[st
 
 def make_bytes_decimal_schema(other_props):
     """Make a BytesDecimalSchema from just other_props."""
-    return BytesDecimalSchema(other_props.get("precision"), other_props.get("scale", 0))
+    return BytesDecimalSchema(other_props.get("precision"), other_props.get("scale", 0), other_props)
 
 
 def make_logical_schema(logical_type, type_, other_props):
diff --git a/lang/py/avro/test/test_schema.py b/lang/py/avro/test/test_schema.py
index 2015727..2542617 100644
--- a/lang/py/avro/test/test_schema.py
+++ b/lang/py/avro/test/test_schema.py
@@ -642,16 +642,16 @@ class TestMisc(unittest.TestCase):
             }
         )
 
-        bytes_decimal_schema = ValidTestSchema({"type": "bytes", "logicalType": "decimal", "precision": 4})
-
         fixed_decimal = fixed_decimal_schema.parse()
         self.assertEqual(4, fixed_decimal.get_prop("precision"))
         self.assertEqual(2, fixed_decimal.get_prop("scale"))
         self.assertEqual(2, fixed_decimal.get_prop("size"))
 
+        bytes_decimal_schema = ValidTestSchema({"type": "bytes", "logicalType": "decimal", "precision": 4})
         bytes_decimal = bytes_decimal_schema.parse()
         self.assertEqual(4, bytes_decimal.get_prop("precision"))
         self.assertEqual(0, bytes_decimal.get_prop("scale"))
+        self.assertEqual("decimal", bytes_decimal.get_prop("logicalType"))
 
     def test_fixed_decimal_valid_max_precision(self):
         # An 8 byte number can represent any 18 digit number.