Fokko commented on code in PR #4920:
URL: https://github.com/apache/iceberg/pull/4920#discussion_r890191844


##########
python/src/iceberg/avro/codec.py:
##########
@@ -0,0 +1,179 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+
+"""
+Contains Codecs for Python Avro.
+
+Note that the word "codecs" means "compression/decompression algorithms" in the
+Avro world 
(https://avro.apache.org/docs/current/spec.html#Object+Container+Files),
+so don't confuse it with the Python's "codecs", which is a package mainly for
+converting character sets (https://docs.python.org/3/library/codecs.html).
+"""
+
+import abc
+import binascii
+import io
+import struct
+import zlib
+from typing import Dict, Tuple, Type
+
+from iceberg.avro.decoder import BinaryDecoder
+from iceberg.io.memory import MemoryInputStream
+
+STRUCT_CRC32 = struct.Struct(">I")  # big-endian unsigned int
+
+
+def _check_crc32(bytes_: bytes, checksum: bytes) -> None:
+    if binascii.crc32(bytes_) & 0xFFFFFFFF != STRUCT_CRC32.unpack(checksum)[0]:
+        raise ValueError("Checksum failure")
+
+
+# bzip2
+try:
+    import bz2
+
+    has_bzip2 = True
+except ImportError:
+    has_bzip2 = False
+
+# snappy
+try:
+    import snappy
+
+    has_snappy = True
+except ImportError:

Review Comment:
   Good call. I've added logging and also another branch in the except when 
something is off when importing the library 👍🏻 



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to