You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by "kojiromike (via GitHub)" <gi...@apache.org> on 2023/07/16 19:34:53 UTC

[GitHub] [avro] kojiromike commented on a diff in pull request #1181: AVRO-1938: Add fingerprinting support to Python implementation

kojiromike commented on code in PR #1181:
URL: https://github.com/apache/avro/pull/1181#discussion_r1264735918


##########
lang/py/avro/schema.py:
##########
@@ -240,6 +295,30 @@ def __eq__(self, that: object) -> bool:
         Consider the mixins EqualByPropsMixin and EqualByJsonMixin
         """
 
+    def fingerprint(self, algorithm="CRC-64-AVRO") -> bytes:
+        """
+        Generate fingerprint for supplied algorithm.
+
+        'CRC-64-AVRO' will be used as the algorithm by default, but any
+        algorithm supported by hashlib (as can be referenced with
+        `hashlib.algorithms_guaranteed`) can be specified.
+
+        `algorithm` param is used as an algorithm name, and NoSuchAlgorithmException
+        will be thrown if the algorithm is not among supported.
+        """
+        schema = self.canonical_form.encode("utf-8")
+
+        if algorithm not in SUPPORTED_ALGORITHMS:
+            raise avro.errors.UnknownFingerprintAlgorithmException(f"Unknown Fingerprint Algorithm: {algorithm}")
+
+        if algorithm == "CRC-64-AVRO":
+            return _crc_64_fingerprint(schema)

Review Comment:
   Consider swapping these two `if` statements



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