Skip to content
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
14 changes: 14 additions & 0 deletions mkdocs/docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,17 @@ 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
```

You can drop a table from the catalog:

```sh
➜ pyiceberg drop table nyc.taxis
Dropped table: nyc.taxis
```

To request purge for the underlying table files through the configured catalog, pass `--purge`:

```sh
➜ pyiceberg drop table nyc.taxis --purge
Dropped table: nyc.taxis (purge requested)
```
11 changes: 8 additions & 3 deletions pyiceberg/cli/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,19 @@ def drop() -> None:

@drop.command()
@click.argument("identifier")
@click.option("--purge", is_flag=True, help="Physically delete all table files.", default=False)
@click.pass_context
@catch_exception()
def table(ctx: Context, identifier: str) -> None: # noqa: F811
def table(ctx: Context, identifier: str, purge: bool) -> None: # noqa: F811
"""Drop a table."""
catalog, output = _catalog_and_output(ctx)

catalog.drop_table(identifier)
output.text(f"Dropped table: {identifier}")
if purge:
catalog.purge_table(identifier)
else:
catalog.drop_table(identifier)
purge_message = " (purge requested)" if purge else ""
output.text(f"Dropped table: {identifier}{purge_message}")


@drop.command() # type: ignore
Expand Down
16 changes: 16 additions & 0 deletions tests/cli/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,22 @@ def test_drop_table(catalog: InMemoryCatalog) -> None:
assert result.output == """Dropped table: default.my_table\n"""


def test_drop_table_with_purge(catalog: InMemoryCatalog, mocker: MockFixture) -> None:
catalog.create_namespace(TEST_TABLE_NAMESPACE)
catalog.create_table(
identifier=TEST_TABLE_IDENTIFIER,
schema=TEST_TABLE_SCHEMA,
partition_spec=TEST_TABLE_PARTITION_SPEC,
)
purge_table = mocker.spy(catalog, "purge_table")

runner = CliRunner()
result = runner.invoke(run, ["drop", "table", "default.my_table", "--purge"])
assert result.exit_code == 0
assert result.output == """Dropped table: default.my_table (purge requested)\n"""
purge_table.assert_called_once_with("default.my_table")


def test_drop_table_does_not_exists(catalog: InMemoryCatalog) -> None:
# pylint: disable=unused-argument

Expand Down