Skip to content

Commit 045dd10

Browse files
authored
feat: add support for setting and removing table properties on console (#2153)
<!-- Thanks for opening a pull request! --> <!-- In the case this PR will resolve an issue, please replace ${GITHUB_ISSUE_ID} below with the actual Github issue id. --> <!-- Closes #${GITHUB_ISSUE_ID} --> # Rationale for this change Hello! Setting or removing table properties on console currently raise a `Writing is WIP` error. This PR adds the code to set and remove table properties. # Are these changes tested? Yes # Are there any user-facing changes? Yes, setting and removing table properties on console now works. <!-- In the case of user-facing changes, please add the changelog label. -->
1 parent 9abec7e commit 045dd10

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

mkdocs/docs/cli.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,19 @@ Or output in JSON for automation:
219219
}
220220
}
221221
```
222+
223+
You can also add, update or remove properties on tables or namespaces:
224+
225+
```sh
226+
➜ pyiceberg properties set table nyc.taxis write.metadata.delete-after-commit.enabled true
227+
Set write.metadata.delete-after-commit.enabled=true on nyc.taxis
228+
229+
➜ pyiceberg properties get table nyc.taxis
230+
write.metadata.delete-after-commit.enabled true
231+
232+
➜ pyiceberg properties remove table nyc.taxis write.metadata.delete-after-commit.enabled
233+
Property write.metadata.delete-after-commit.enabled removed from nyc.taxis
234+
235+
➜ pyiceberg properties get table nyc.taxis write.metadata.delete-after-commit.enabled
236+
Could not find property write.metadata.delete-after-commit.enabled on nyc.taxis
237+
```

pyiceberg/cli/console.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,10 @@ def table(ctx: Context, identifier: str, property_name: str, property_value: str
361361
catalog, output = _catalog_and_output(ctx)
362362
identifier_tuple = Catalog.identifier_to_tuple(identifier)
363363

364-
_ = catalog.load_table(identifier_tuple)
365-
output.text(f"Setting {property_name}={property_value} on {identifier}")
366-
raise NotImplementedError("Writing is WIP")
364+
table = catalog.load_table(identifier_tuple)
365+
with table.transaction() as tx:
366+
tx.set_properties({property_name: property_value})
367+
output.text(f"Set {property_name}={property_value} on {identifier}")
367368

368369

369370
@properties.group()
@@ -398,8 +399,9 @@ def table(ctx: Context, identifier: str, property_name: str) -> None: # noqa: F
398399
catalog, output = _catalog_and_output(ctx)
399400
table = catalog.load_table(identifier)
400401
if property_name in table.metadata.properties:
401-
output.exception(NotImplementedError("Writing is WIP"))
402-
ctx.exit(1)
402+
with table.transaction() as tx:
403+
tx.remove_properties(property_name)
404+
output.text(f"Property {property_name} removed from {identifier}")
403405
else:
404406
raise NoSuchPropertyException(f"Property {property_name} does not exist on {identifier}")
405407

tests/cli/test_console.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,8 @@ def test_properties_set_table(catalog: InMemoryCatalog) -> None:
476476

477477
runner = CliRunner()
478478
result = runner.invoke(run, ["properties", "set", "table", "default.my_table", "location", "s3://new_location"])
479-
assert result.exit_code == 1
480-
assert "Writing is WIP" in result.output
479+
assert result.exit_code == 0
480+
assert result.output == "Set location=s3://new_location on default.my_table\n"
481481

482482

483483
def test_properties_set_table_does_not_exist(catalog: InMemoryCatalog) -> None:
@@ -518,8 +518,8 @@ def test_properties_remove_table(catalog: InMemoryCatalog) -> None:
518518

519519
runner = CliRunner()
520520
result = runner.invoke(run, ["properties", "remove", "table", "default.my_table", "read.split.target.size"])
521-
assert result.exit_code == 1
522-
assert "Writing is WIP" in result.output
521+
assert result.exit_code == 0
522+
assert result.output == "Property read.split.target.size removed from default.my_table\n"
523523

524524

525525
def test_properties_remove_table_property_does_not_exists(catalog: InMemoryCatalog) -> None:
@@ -894,8 +894,8 @@ def test_json_properties_set_table(catalog: InMemoryCatalog) -> None:
894894
result = runner.invoke(
895895
run, ["--output=json", "properties", "set", "table", "default.my_table", "location", "s3://new_location"]
896896
)
897-
assert result.exit_code == 1
898-
assert "Writing is WIP" in result.output
897+
assert result.exit_code == 0
898+
assert result.output == """"Set location=s3://new_location on default.my_table"\n"""
899899

900900

901901
def test_json_properties_set_table_does_not_exist(catalog: InMemoryCatalog) -> None:
@@ -938,8 +938,8 @@ def test_json_properties_remove_table(catalog: InMemoryCatalog) -> None:
938938

939939
runner = CliRunner()
940940
result = runner.invoke(run, ["--output=json", "properties", "remove", "table", "default.my_table", "read.split.target.size"])
941-
assert result.exit_code == 1
942-
assert "Writing is WIP" in result.output
941+
assert result.exit_code == 0
942+
assert result.output == """"Property read.split.target.size removed from default.my_table"\n"""
943943

944944

945945
def test_json_properties_remove_table_property_does_not_exists(catalog: InMemoryCatalog) -> None:

0 commit comments

Comments
 (0)