Skip to content

Commit e2c1e78

Browse files
kevinjqliuCopilot
andauthored
CLI: Show metadata location in describe view (#4153)
CLI: show metadata location in describe view Match describe table text output by including the view's metadata location, and document the view CLI commands. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent c8502b3 commit e2c1e78

3 files changed

Lines changed: 45 additions & 4 deletions

File tree

‎mkdocs/docs/cli.md‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ Options:
4444

4545
Commands:
4646
create Operation to create a namespace.
47-
describe Describe a namespace or a table.
47+
describe Describe a namespace, a table, or a view.
4848
drop Operations to drop a namespace or table.
4949
files List all the files of the table.
5050
list List tables or namespaces.
5151
list-refs List all the refs in the provided table.
52+
list-views List all views in a namespace.
5253
location Return the location of the table.
5354
properties Properties on tables/namespaces.
5455
rename Rename a table.
@@ -254,3 +255,26 @@ To request purge for the underlying table files through the configured catalog,
254255
➜ pyiceberg drop table nyc.taxis --purge
255256
Dropped table: nyc.taxis (purge requested)
256257
```
258+
259+
For catalogs that support views, you can also list, describe, and drop views:
260+
261+
```sh
262+
➜ pyiceberg list-views nyc
263+
nyc.taxi_trips
264+
265+
➜ pyiceberg describe --entity view nyc.taxi_trips
266+
View format version 1
267+
Metadata location s3://warehouse/nyc/taxi_trips/metadata/00001-b3a9c6e2-6c1f-4e47-9d4f-2f9a1d0e5c7b.metadata.json
268+
View UUID fa6506c3-7681-40c8-86dc-e36561f83385
269+
Location s3://warehouse/nyc/taxi_trips
270+
Current version 1
271+
Current schema Schema, id=1
272+
├── 1: VendorID: optional long
273+
└── 2: trip_distance: optional double
274+
SQL SQL representations
275+
└── spark: SELECT VendorID, trip_distance FROM nyc.taxis
276+
Properties comment Taxi trip distances
277+
278+
➜ pyiceberg drop view nyc.taxi_trips
279+
Dropped view: nyc.taxi_trips
280+
```

‎pyiceberg/cli/output.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ def describe_view(self, view: View) -> None:
145145

146146
output_table = self._table
147147
output_table.add_row("View format version", str(metadata.format_version))
148+
output_table.add_row("Metadata location", view.metadata_location)
148149
output_table.add_row("View UUID", str(metadata.view_uuid))
149150
output_table.add_row("Location", metadata.location)
150151
output_table.add_row("Current version", str(metadata.current_version_id))

‎tests/cli/test_console.py‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,11 @@ def test_warehouse_cli_option_forwarded_to_catalog(mocker: MockFixture) -> None:
12091209

12101210
@pytest.fixture(name="catalog_with_view")
12111211
def fixture_catalog_with_view(mocker: MockFixture, catalog: InMemoryCatalog) -> tuple[InMemoryCatalog, View]:
1212-
view = View(TEST_VIEW_IDENTIFIER, ViewMetadata.model_validate(TEST_VIEW_METADATA))
1212+
view = View(
1213+
TEST_VIEW_IDENTIFIER,
1214+
ViewMetadata.model_validate(TEST_VIEW_METADATA),
1215+
metadata_location="s3://warehouse/default/my_view/metadata/metadata.json",
1216+
)
12131217
catalog.list_views = MagicMock(return_value=[TEST_VIEW_IDENTIFIER]) # type: ignore
12141218
catalog.load_view = MagicMock(return_value=view) # type: ignore
12151219
catalog.drop_view = MagicMock() # type: ignore
@@ -1238,8 +1242,20 @@ def test_describe_view(catalog_with_view: tuple[InMemoryCatalog, View]) -> None:
12381242
runner = CliRunner()
12391243
result = runner.invoke(run, ["describe", "--entity=view", "default.my_view"])
12401244
assert result.exit_code == 0
1241-
assert "b30125c8-7284-442c-9aea-15fee620737c" in result.output
1242-
assert "spark: SELECT * FROM my_table" in result.output
1245+
assert (
1246+
"\n".join([line.rstrip() for line in result.output.split("\n")])
1247+
== """View format version 1
1248+
Metadata location s3://warehouse/default/my_view/metadata/metadata.json
1249+
View UUID b30125c8-7284-442c-9aea-15fee620737c
1250+
Location s3://warehouse/default/my_view
1251+
Current version 1
1252+
Current schema Schema, id=1
1253+
└── 1: x: required long
1254+
SQL SQL representations
1255+
└── spark: SELECT * FROM my_table
1256+
Properties
1257+
"""
1258+
)
12431259

12441260

12451261
def test_describe_view_does_not_exist(catalog: InMemoryCatalog) -> None:

0 commit comments

Comments
 (0)