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 2022/06/17 16:38:14 UTC

[avro] branch branch-1.11 updated (59aa0078e -> 87778e6c5)

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

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


    from 59aa0078e AVRO-3523: Move contributions guidelines to website (#1707)
     new b5bd31232 AVRO-3521: "Scale" property from decimal object (#1689)
     new 87778e6c5 AVRO-3076: Fix incorrect Javadoc regarding custom coder defaults (#1715)

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../main/java/org/apache/avro/reflect/ReflectData.java   |  3 +++
 .../main/java/org/apache/avro/specific/SpecificData.java |  2 +-
 lang/py/avro/io.py                                       | 16 ++++++++--------
 lang/py/avro/schema.py                                   |  2 +-
 lang/py/avro/test/test_io.py                             | 14 ++++++++++++++
 lang/py/avro/test/test_schema.py                         |  2 +-
 6 files changed, 28 insertions(+), 11 deletions(-)


[avro] 01/02: AVRO-3521: "Scale" property from decimal object (#1689)

Posted by rs...@apache.org.
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 b5bd312324d5a47890b3e8a802995f1d0c4346bb
Author: Igor Izvekov <iz...@mail.ru>
AuthorDate: Fri Jun 17 19:31:05 2022 +0300

    AVRO-3521: "Scale" property from decimal object (#1689)
    
    * AVRO-3521
    
    * Fixed style for "AVRO-3521"
    
    * Changed from 'a positive integer' to 'a non-negative integer' (by RyanSkraba's improvement).
    
    * Update error message in test
    
    Co-authored-by: Ryan Skraba <ry...@skraba.com>
---
 lang/py/avro/io.py               | 16 ++++++++--------
 lang/py/avro/schema.py           |  2 +-
 lang/py/avro/test/test_io.py     | 14 ++++++++++++++
 lang/py/avro/test/test_schema.py |  2 +-
 4 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/lang/py/avro/io.py b/lang/py/avro/io.py
index be81d9b6d..998dcd863 100644
--- a/lang/py/avro/io.py
+++ b/lang/py/avro/io.py
@@ -699,8 +699,8 @@ class DatumReader:
                     warnings.warn(avro.errors.IgnoredLogicalType(f"Invalid decimal precision {precision}. Must be a positive integer."))
                     return decoder.read_bytes()
                 scale = writers_schema.get_prop("scale")
-                if not (isinstance(scale, int) and scale > 0):
-                    warnings.warn(avro.errors.IgnoredLogicalType(f"Invalid decimal scale {scale}. Must be a positive integer."))
+                if not (isinstance(scale, int) and scale >= 0):
+                    warnings.warn(avro.errors.IgnoredLogicalType(f"Invalid decimal scale {scale}. Must be a non-negative integer."))
                     return decoder.read_bytes()
                 return decoder.read_decimal_from_bytes(precision, scale)
             return decoder.read_bytes()
@@ -711,8 +711,8 @@ class DatumReader:
                     warnings.warn(avro.errors.IgnoredLogicalType(f"Invalid decimal precision {precision}. Must be a positive integer."))
                     return self.read_fixed(writers_schema, readers_schema, decoder)
                 scale = writers_schema.get_prop("scale")
-                if not (isinstance(scale, int) and scale > 0):
-                    warnings.warn(avro.errors.IgnoredLogicalType(f"Invalid decimal scale {scale}. Must be a positive integer."))
+                if not (isinstance(scale, int) and scale >= 0):
+                    warnings.warn(avro.errors.IgnoredLogicalType(f"Invalid decimal scale {scale}. Must be a non-negative integer."))
                     return self.read_fixed(writers_schema, readers_schema, decoder)
                 return decoder.read_decimal_from_fixed(precision, scale, writers_schema.size)
             return self.read_fixed(writers_schema, readers_schema, decoder)
@@ -1067,8 +1067,8 @@ class DatumWriter:
         if writers_schema.type == "bytes":
             if logical_type == "decimal":
                 scale = writers_schema.get_prop("scale")
-                if not (isinstance(scale, int) and scale > 0):
-                    warnings.warn(avro.errors.IgnoredLogicalType(f"Invalid decimal scale {scale}. Must be a positive integer."))
+                if not (isinstance(scale, int) and scale >= 0):
+                    warnings.warn(avro.errors.IgnoredLogicalType(f"Invalid decimal scale {scale}. Must be a non-negative integer."))
                 elif not isinstance(datum, decimal.Decimal):
                     warnings.warn(avro.errors.IgnoredLogicalType(f"{datum} is not a decimal type"))
                 else:
@@ -1080,8 +1080,8 @@ class DatumWriter:
             if logical_type == "decimal":
                 scale = writers_schema.get_prop("scale")
                 size = writers_schema.size
-                if not (isinstance(scale, int) and scale > 0):
-                    warnings.warn(avro.errors.IgnoredLogicalType(f"Invalid decimal scale {scale}. Must be a positive integer."))
+                if not (isinstance(scale, int) and scale >= 0):
+                    warnings.warn(avro.errors.IgnoredLogicalType(f"Invalid decimal scale {scale}. Must be a non-negative integer."))
                 elif not isinstance(datum, decimal.Decimal):
                     warnings.warn(avro.errors.IgnoredLogicalType(f"{datum} is not a decimal type"))
                 else:
diff --git a/lang/py/avro/schema.py b/lang/py/avro/schema.py
index 064c9d134..4885e333f 100644
--- a/lang/py/avro/schema.py
+++ b/lang/py/avro/schema.py
@@ -303,7 +303,7 @@ class DecimalLogicalSchema(LogicalSchema):
             raise avro.errors.IgnoredLogicalType(f"Invalid decimal precision {precision}. Max is {max_precision}.")
 
         if not isinstance(scale, int) or scale < 0:
-            raise avro.errors.IgnoredLogicalType(f"Invalid decimal scale {scale}. Must be a positive integer.")
+            raise avro.errors.IgnoredLogicalType(f"Invalid decimal scale {scale}. Must be a non-negative integer.")
 
         if scale > precision:
             raise avro.errors.IgnoredLogicalType(f"Invalid decimal scale {scale}. Cannot be greater than precision {precision}.")
diff --git a/lang/py/avro/test/test_io.py b/lang/py/avro/test/test_io.py
index 6ca3a61b8..29dd82130 100644
--- a/lang/py/avro/test/test_io.py
+++ b/lang/py/avro/test/test_io.py
@@ -71,6 +71,16 @@ SCHEMAS_TO_VALIDATE = tuple(
             },
             decimal.Decimal("-3.1415"),
         ),
+        (
+            {
+                "type": "fixed",
+                "logicalType": "decimal",
+                "name": "Test",
+                "size": 8,
+                "precision": 1,
+            },
+            decimal.Decimal("3"),
+        ),
         (
             {"type": "bytes", "logicalType": "decimal", "precision": 5, "scale": 4},
             decimal.Decimal("3.1415"),
@@ -79,6 +89,10 @@ SCHEMAS_TO_VALIDATE = tuple(
             {"type": "bytes", "logicalType": "decimal", "precision": 5, "scale": 4},
             decimal.Decimal("-3.1415"),
         ),
+        (
+            {"type": "bytes", "logicalType": "decimal", "precision": 1},
+            decimal.Decimal("3"),
+        ),
         ({"type": "enum", "name": "Test", "symbols": ["A", "B"]}, "B"),
         ({"type": "array", "items": "long"}, [1, 3, 2]),
         ({"type": "map", "values": "long"}, {"a": 1, "b": 3, "c": 2}),
diff --git a/lang/py/avro/test/test_schema.py b/lang/py/avro/test/test_schema.py
index ed101632e..5a4949301 100644
--- a/lang/py/avro/test/test_schema.py
+++ b/lang/py/avro/test/test_schema.py
@@ -421,7 +421,7 @@ IGNORED_LOGICAL_TYPE = [
     ),
     ValidTestSchema(
         {"type": "bytes", "logicalType": "decimal", "precision": 2, "scale": -2},
-        warnings=[avro.errors.IgnoredLogicalType("Invalid decimal scale -2. Must be a positive integer.")],
+        warnings=[avro.errors.IgnoredLogicalType("Invalid decimal scale -2. Must be a non-negative integer.")],
     ),
     ValidTestSchema(
         {"type": "bytes", "logicalType": "decimal", "precision": -2, "scale": 2},


[avro] 02/02: AVRO-3076: Fix incorrect Javadoc regarding custom coder defaults (#1715)

Posted by rs...@apache.org.
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 87778e6c56ed0d01a8fdcf0b670e327d5dad814f
Author: Rens Groothuijsen <l....@alumni.maastrichtuniversity.nl>
AuthorDate: Fri Jun 17 18:33:32 2022 +0200

    AVRO-3076: Fix incorrect Javadoc regarding custom coder defaults (#1715)
---
 lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java  | 3 +++
 .../java/avro/src/main/java/org/apache/avro/specific/SpecificData.java | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java b/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
index b4545b228..ec4909794 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
@@ -71,6 +71,9 @@ public class ReflectData extends SpecificData {
 
   private static final String STRING_OUTER_PARENT_REFERENCE = "this$0";
 
+  /**
+   * Always false since custom coders are not available for {@link ReflectData}.
+   */
   @Override
   public boolean useCustomCoders() {
     return false;
diff --git a/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java b/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java
index 46731b992..d03e7af63 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java
@@ -191,7 +191,7 @@ public class SpecificData extends GenericData {
 
   /**
    * Retrieve the current value of the custom-coders feature flag. Defaults to
-   * <code>true</code>, but this default can be overriden using the system
+   * <code>false</code>, but this default can be overridden using the system
    * property <code>org.apache.avro.specific.use_custom_coders</code>, and can be
    * set dynamically by {@link SpecificData#useCustomCoders()}. See <a
    * href="https://avro.apache.org/docs/current/gettingstartedjava.html#Beta+feature:+Generating+faster+code"Getting