kevinjqliu commented on code in PR #4159:
URL: https://github.com/apache/iceberg-python/pull/4159#discussion_r4498790917


##########
pyiceberg/table/__init__.py:
##########
@@ -1345,13 +1354,34 @@ def __init__(
         io: FileIO,
         catalog: Catalog,
         config: dict[str, str] = EMPTY_DICT,
+        kms_client: KeyManagementClient | None = None,
     ) -> None:
         self._identifier = identifier
         self.metadata = metadata
         self.metadata_location = metadata_location
         self.io = io
         self.catalog = catalog
         self.config = config
+        self._kms_client = kms_client
+        self._encryption_manager: _CachedEncryptionManager | None = None
+
+    @property
+    def encryption_manager(self) -> EncryptionManager | None:
+        """The table's encryption manager, or None if the table is not 
encrypted.
+
+        The manager is built from the current metadata, and rebuilt when the 
metadata changes.
+
+        Raises:
+            ValueError: If the table is encrypted but no key management client 
was provided.
+        """
+        from pyiceberg.encryption.manager import EncryptionManager
+
+        cached = self._encryption_manager
+        if cached is None or cached.metadata is not self.metadata:
+            cached = self._encryption_manager = _CachedEncryptionManager(
+                self.metadata, 
EncryptionManager.from_table_metadata(self._kms_client, self.metadata)
+            )
+        return cached.manager

Review Comment:
   this logic looks a bit weird for the non-encrypted case. 
`EncryptionManager.from_table_metadata` returns `None` when the table is not 
encrypted, and the whole function returns `None`



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