diff --git a/mkdocs/docs/cli.md b/mkdocs/docs/cli.md index 7393aa1806..a6cf807fda 100644 --- a/mkdocs/docs/cli.md +++ b/mkdocs/docs/cli.md @@ -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 also purge the table files through the configured catalog, pass `--purge`: + +```sh +➜ pyiceberg drop table nyc.taxis --purge +Dropped table: nyc.taxis (purge requested) +``` diff --git a/pyiceberg/cli/console.py b/pyiceberg/cli/console.py index 3feed9fb21..95bba620ff 100644 --- a/pyiceberg/cli/console.py +++ b/pyiceberg/cli/console.py @@ -269,14 +269,19 @@ def drop() -> None: @drop.command() @click.argument("identifier") +@click.option("--purge", is_flag=True, help="Physically delete all table files.") @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 diff --git a/tests/cli/test_console.py b/tests/cli/test_console.py index 27a1bfebe4..e04fd9c96d 100644 --- a/tests/cli/test_console.py +++ b/tests/cli/test_console.py @@ -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