diff --git a/pyiceberg/table/__init__.py b/pyiceberg/table/__init__.py index 1a4183c914..13e1ac1da5 100644 --- a/pyiceberg/table/__init__.py +++ b/pyiceberg/table/__init__.py @@ -294,17 +294,21 @@ def upgrade_table_version(self, format_version: Literal[1, 2]) -> 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 072fd7db25..da43e7825e 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 + + +@pytest.mark.integration +@pytest.mark.parametrize('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 + + +@pytest.mark.integration +@pytest.mark.parametrize('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')])