This is an automated email from the ASF dual-hosted git repository.
honahx pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git
The following commit(s) were added to refs/heads/main by this push:
new ad405734 Set table properties with dictionary (#503)
ad405734 is described below
commit ad405734c5e187baadb8cad91f176733cf526b7a
Author: Kevin Liu <[email protected]>
AuthorDate: Fri Mar 8 01:00:33 2024 -0800
Set table properties with dictionary (#503)
---
pyiceberg/table/__init__.py | 8 ++++++--
tests/integration/test_reads.py | 34 +++++++++++++++++++++++++++++++---
2 files changed, 37 insertions(+), 5 deletions(-)
diff --git a/pyiceberg/table/__init__.py b/pyiceberg/table/__init__.py
index 1a4183c9..13e1ac1d 100644
--- a/pyiceberg/table/__init__.py
+++ b/pyiceberg/table/__init__.py
@@ -294,17 +294,21 @@ class Transaction:
return self
- def set_properties(self, **updates: str) -> Transaction:
+ def set_properties(self, properties: Properties = EMPTY_DICT, **kwargs:
str) -> Transaction:
"""Set properties.
When a property is already set, it will be overwritten.
Args:
- updates: The properties set on the table.
+ properties: The properties set on the table.
+ kwargs: properties can also be pass as kwargs.
Returns:
The alter table builder.
"""
+ if properties and kwargs:
+ raise ValueError("Cannot pass both properties and kwargs")
+ updates = properties or kwargs
return self._apply((SetPropertiesUpdate(updates=updates),))
def update_schema(self, allow_incompatible_changes: bool = False,
case_sensitive: bool = True) -> UpdateSchema:
diff --git a/tests/integration/test_reads.py b/tests/integration/test_reads.py
index 072fd7db..da43e782 100644
--- a/tests/integration/test_reads.py
+++ b/tests/integration/test_reads.py
@@ -107,22 +107,50 @@ def test_table_properties(catalog: Catalog) -> None:
with table.transaction() as transaction:
transaction.set_properties(abc="🤪")
-
assert table.properties == dict(abc="🤪", **DEFAULT_PROPERTIES)
with table.transaction() as transaction:
transaction.remove_properties("abc")
-
assert table.properties == DEFAULT_PROPERTIES
table = table.transaction().set_properties(abc="def").commit_transaction()
-
assert table.properties == dict(abc="def", **DEFAULT_PROPERTIES)
table = table.transaction().remove_properties("abc").commit_transaction()
+ assert table.properties == DEFAULT_PROPERTIES
+
+
[email protected]
[email protected]('catalog', [pytest.lazy_fixture('catalog_hive'),
pytest.lazy_fixture('catalog_rest')])
+def test_table_properties_dict(catalog: Catalog) -> None:
+ table = create_table(catalog)
assert table.properties == DEFAULT_PROPERTIES
+ with table.transaction() as transaction:
+ transaction.set_properties({"abc": "🤪"})
+ assert table.properties == dict({"abc": "🤪"}, **DEFAULT_PROPERTIES)
+
+ with table.transaction() as transaction:
+ transaction.remove_properties("abc")
+ assert table.properties == DEFAULT_PROPERTIES
+
+ table = table.transaction().set_properties({"abc":
"def"}).commit_transaction()
+ assert table.properties == dict({"abc": "def"}, **DEFAULT_PROPERTIES)
+
+ table = table.transaction().remove_properties("abc").commit_transaction()
+ assert table.properties == DEFAULT_PROPERTIES
+
+
[email protected]
[email protected]('catalog', [pytest.lazy_fixture('catalog_hive'),
pytest.lazy_fixture('catalog_rest')])
+def test_table_properties_error(catalog: Catalog) -> None:
+ table = create_table(catalog)
+ properties = {"abc": "def"}
+ with pytest.raises(ValueError) as e:
+ table.transaction().set_properties(properties,
abc="def").commit_transaction()
+ assert "Cannot pass both properties and kwargs" in str(e.value)
+
@pytest.mark.integration
@pytest.mark.parametrize('catalog', [pytest.lazy_fixture('catalog_hive'),
pytest.lazy_fixture('catalog_rest')])