From 5973eaa900fcf21dad6351e1d59b8cf817f6220b Mon Sep 17 00:00:00 2001 From: jx2lee Date: Tue, 28 Jul 2026 21:39:37 +0900 Subject: [PATCH 1/3] add flags in drop table cmd --- pyiceberg/cli/console.py | 8 ++++++-- tests/cli/test_console.py | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/pyiceberg/cli/console.py b/pyiceberg/cli/console.py index 3feed9fb21..98f608263e 100644 --- a/pyiceberg/cli/console.py +++ b/pyiceberg/cli/console.py @@ -269,13 +269,17 @@ 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) + if purge: + catalog.purge_table(identifier) + else: + catalog.drop_table(identifier) output.text(f"Dropped table: {identifier}") diff --git a/tests/cli/test_console.py b/tests/cli/test_console.py index 27a1bfebe4..9ee827fbcd 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\n""" + purge_table.assert_called_once_with("default.my_table") + + def test_drop_table_does_not_exists(catalog: InMemoryCatalog) -> None: # pylint: disable=unused-argument From 2378f13c2ec204383306c97cc5b3e06832073c7a Mon Sep 17 00:00:00 2001 From: jx2lee Date: Wed, 29 Jul 2026 09:29:55 +0900 Subject: [PATCH 2/3] add drop cmd in cli.md --- mkdocs/docs/cli.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mkdocs/docs/cli.md b/mkdocs/docs/cli.md index 7393aa1806..21ec99eb31 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 +``` From 6e3e4954c4cc115f463d917432fd28f5d11afe4f Mon Sep 17 00:00:00 2001 From: jx2lee Date: Wed, 29 Jul 2026 09:44:28 +0900 Subject: [PATCH 3/3] include purgable with flags --- mkdocs/docs/cli.md | 2 +- pyiceberg/cli/console.py | 3 ++- tests/cli/test_console.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/mkdocs/docs/cli.md b/mkdocs/docs/cli.md index 21ec99eb31..a6cf807fda 100644 --- a/mkdocs/docs/cli.md +++ b/mkdocs/docs/cli.md @@ -252,5 +252,5 @@ To also purge the table files through the configured catalog, pass `--purge`: ```sh ➜ pyiceberg drop table nyc.taxis --purge -Dropped table: nyc.taxis +Dropped table: nyc.taxis (purge requested) ``` diff --git a/pyiceberg/cli/console.py b/pyiceberg/cli/console.py index 98f608263e..95bba620ff 100644 --- a/pyiceberg/cli/console.py +++ b/pyiceberg/cli/console.py @@ -280,7 +280,8 @@ def table(ctx: Context, identifier: str, purge: bool) -> None: # noqa: F811 catalog.purge_table(identifier) else: catalog.drop_table(identifier) - output.text(f"Dropped 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 9ee827fbcd..e04fd9c96d 100644 --- a/tests/cli/test_console.py +++ b/tests/cli/test_console.py @@ -352,7 +352,7 @@ def test_drop_table_with_purge(catalog: InMemoryCatalog, mocker: MockFixture) -> 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\n""" + assert result.output == """Dropped table: default.my_table (purge requested)\n""" purge_table.assert_called_once_with("default.my_table")