Add view operations to CLI (#3926) · apache/iceberg-python@76eb1d4 · GitHub
Skip to content

Commit 76eb1d4

Browse files
ebyhrCopilot
andauthored
Add view operations to CLI (#3926)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 0e4ac51 commit 76eb1d4

3 files changed

Lines changed: 221 additions & 13 deletions

File tree

‎pyiceberg/cli/console.py‎

Lines changed: 49 additions & 11 deletions

‎pyiceberg/cli/output.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
from rich.console import Console
2525
from rich.table import Table as RichTable
26+
from rich.text import Text
2627
from rich.tree import Tree
2728

2829
from pyiceberg.partitioning import PartitionSpec
@@ -31,6 +32,7 @@
3132
from pyiceberg.table.metadata import TableMetadata
3233
from pyiceberg.table.refs import SnapshotRefType
3334
from pyiceberg.typedef import IcebergBaseModel, Identifier, Properties
35+
from pyiceberg.view import View
3436

3537

3638
class Output(ABC):
@@ -45,6 +47,9 @@ def identifiers(self, identifiers: list[Identifier]) -> None: ...
4547
@abstractmethod
4648
def describe_table(self, table: Table) -> None: ...
4749

50+
@abstractmethod
51+
def describe_view(self, view: View) -> None: ...
52+
4853
@abstractmethod
4954
def files(self, table: Table, history: bool) -> None: ...
5055

@@ -123,6 +128,31 @@ def describe_table(self, table: Table) -> None:
123128
output_table.add_row("Properties", table_properties)
124129
Console().print(output_table)
125130

131+
def describe_view(self, view: View) -> None:
132+
metadata = view.metadata
133+
view_properties = self._table
134+
for key, value in metadata.properties.items():
135+
view_properties.add_row(key, value)
136+
137+
schema_tree = Tree(f"Schema, id={view.current_version().schema_id}")
138+
for field in view.schema().fields:
139+
schema_tree.add(str(field))
140+
141+
current_version = view.current_version()
142+
representations_tree = Tree("SQL representations")
143+
for repr in current_version.representations:
144+
representations_tree.add(Text(f"{repr.root.dialect}: {repr.root.sql}"))
145+
146+
output_table = self._table
147+
output_table.add_row("View format version", str(metadata.format_version))
148+
output_table.add_row("View UUID", str(metadata.view_uuid))
149+
output_table.add_row("Location", metadata.location)
150+
output_table.add_row("Current version", str(metadata.current_version_id))
151+
output_table.add_row("Current schema", schema_tree)
152+
output_table.add_row("SQL", representations_tree)
153+
output_table.add_row("Properties", view_properties)
154+
Console().print(output_table)
155+
126156
def files(self, table: Table, history: bool) -> None:
127157
if history:
128158
snapshots = table.metadata.snapshots
@@ -216,6 +246,9 @@ class FauxTable(IcebergBaseModel):
216246
).model_dump_json()
217247
)
218248

249+
def describe_view(self, view: View) -> None:
250+
print(view.metadata.model_dump_json())
251+
219252
def describe_properties(self, properties: Properties) -> None:
220253
self._out(properties)
221254

‎tests/cli/test_console.py‎

Lines changed: 139 additions & 2 deletions

0 commit comments

Comments
 (0)