Skip to content

feat: add support for setting and removing table properties on console #2153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions mkdocs/docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,19 @@ Or output in JSON for automation:
}
}
```

You can also add, update or remove properties on tables or namespaces:

```sh
➜ pyiceberg properties set table nyc.taxis write.metadata.delete-after-commit.enabled true
Set write.metadata.delete-after-commit.enabled=true on nyc.taxis

➜ pyiceberg properties get table nyc.taxis
write.metadata.delete-after-commit.enabled true

➜ pyiceberg properties remove table nyc.taxis write.metadata.delete-after-commit.enabled
Property write.metadata.delete-after-commit.enabled removed from nyc.taxis

➜ pyiceberg properties get table nyc.taxis write.metadata.delete-after-commit.enabled
Could not find property write.metadata.delete-after-commit.enabled on nyc.taxis
```
12 changes: 7 additions & 5 deletions pyiceberg/cli/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,10 @@ def table(ctx: Context, identifier: str, property_name: str, property_value: str
catalog, output = _catalog_and_output(ctx)
identifier_tuple = Catalog.identifier_to_tuple(identifier)

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


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

Expand Down
16 changes: 8 additions & 8 deletions tests/cli/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,8 @@ def test_properties_set_table(catalog: InMemoryCatalog) -> None:

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


def test_properties_set_table_does_not_exist(catalog: InMemoryCatalog) -> None:
Expand Down Expand Up @@ -518,8 +518,8 @@ def test_properties_remove_table(catalog: InMemoryCatalog) -> None:

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


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


def test_json_properties_set_table_does_not_exist(catalog: InMemoryCatalog) -> None:
Expand Down Expand Up @@ -938,8 +938,8 @@ def test_json_properties_remove_table(catalog: InMemoryCatalog) -> None:

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


def test_json_properties_remove_table_property_does_not_exists(catalog: InMemoryCatalog) -> None:
Expand Down