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


##########
tests/integration/test_encryption.py:
##########
@@ -0,0 +1,178 @@
+# 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.
+# pylint:disable=redefined-outer-name
+
+import pyarrow.parquet as pq
+import pytest
+from pyspark.sql import SparkSession
+
+from pyiceberg.catalog import Catalog
+from pyiceberg.encryption.ciphers import SecureKey
+from pyiceberg.encryption.kms import KeyManagementClient
+from pyiceberg.table import Table
+from tests.encryption.memory_kms import MemoryKeyManagementClient
+
+# Master key keyA of UnitestKMS, the in-memory KMS that Spark uses to write 
encrypted tables:
+# 
https://github.com/apache/iceberg/blob/212aa894e919ff9fdf89160da4aadcbe6858ac01/core/src/test/java/org/apache/iceberg/encryption/UnitestKMS.java
+MASTER_KEY_ID = "keyA"
+MASTER_KEY = b"0123456789012345"
+
+# AES-128 and AES-256 data keys
+DATA_KEY_LENGTHS = [16, 32]
+
+ROWS = [
+    {"id": 1, "category": "a", "payload": "alpha"},
+    {"id": 2, "category": "b", "payload": None},
+    {"id": 3, "category": "a", "payload": "gamma"},
+    {"id": 4, "category": "b", "payload": "delta"},
+]
+EXTRA_ROWS = [
+    {"id": 5, "category": "a", "payload": "epsilon"},
+    {"id": 6, "category": "b", "payload": "zeta"},
+]
+
+
+def _create_encrypted_table(spark: SparkSession, identifier: str, 
data_key_length: int) -> None:
+    # As of now, only the hive catalog supports KMS encryption in the 
integration setup.
+    # Spark's hive catalog is configured with UnitestKMS in 
dev/spark/spark-defaults.conf.
+    spark.sql(f"DROP TABLE IF EXISTS hive.{identifier}")
+    spark.sql(
+        f"""
+        CREATE TABLE hive.{identifier} (id bigint, category string, payload 
string)
+        USING iceberg
+        PARTITIONED BY (category)
+        TBLPROPERTIES (
+            'format-version'='3',
+            'encryption.key-id'='{MASTER_KEY_ID}',
+            'encryption.data-key-length'='{data_key_length}',
+            'write.delete.mode'='merge-on-read'
+        )
+        """
+    )
+
+
+def _load_table(catalog: Catalog, identifier: str, kms: KeyManagementClient) 
-> Table:
+    table = catalog.load_table(identifier)
+    return Table(
+        identifier=table.name(),
+        metadata=table.metadata,
+        metadata_location=table.metadata_location,
+        io=table.io,
+        catalog=catalog,
+        kms_client=kms,

Review Comment:
   @xanderbailey ideally i think we can set kms_client in the catalog and let 
it pass to the `Table`, right? what do you think?



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