You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by bl...@apache.org on 2022/08/24 19:19:22 UTC

[iceberg] branch master updated: Python: Add additional information to the describe command (#5609)

This is an automated email from the ASF dual-hosted git repository.

blue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iceberg.git


The following commit(s) were added to refs/heads/master by this push:
     new 12cd59b97d Python: Add additional information to the describe command (#5609)
12cd59b97d is described below

commit 12cd59b97d64e4493db3f0264c440a17619a5cef
Author: Fokko Driesprong <fo...@apache.org>
AuthorDate: Wed Aug 24 21:19:16 2022 +0200

    Python: Add additional information to the describe command (#5609)
---
 python/pyiceberg/cli/output.py      |  8 +++++---
 python/pyiceberg/manifest.py        | 12 ++++++++++++
 python/pyiceberg/table/__init__.py  |  2 --
 python/pyiceberg/table/snapshots.py |  7 +++++++
 python/tests/cli/test_console.py    | 10 +++++++---
 5 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/python/pyiceberg/cli/output.py b/python/pyiceberg/cli/output.py
index 20cc8b4890..270567930e 100644
--- a/python/pyiceberg/cli/output.py
+++ b/python/pyiceberg/cli/output.py
@@ -97,13 +97,14 @@ class ConsoleOutput(Output):
         for key, value in metadata.properties.items():
             table_properties.add_row(key, value)
 
-        schema_tree = Tree("Schema")
+        schema_tree = Tree(f"Schema, id={table.metadata.current_schema_id}")
         for field in table.schema().fields:
             schema_tree.add(str(field))
 
         snapshot_tree = Tree("Snapshots")
         for snapshot in metadata.snapshots:
-            snapshot_tree.add(f"Snapshot {snapshot.schema_id}: {snapshot.manifest_list}")
+            manifest_list_str = f": {snapshot.manifest_list}" if snapshot.manifest_list else ""
+            snapshot_tree.add(f"Snapshot {snapshot.snapshot_id}, schema {snapshot.schema_id}{manifest_list_str}")
 
         output_table = self._table
         output_table.add_row("Table format version", str(metadata.format_version))
@@ -112,7 +113,8 @@ class ConsoleOutput(Output):
         output_table.add_row("Last Updated", str(metadata.last_updated_ms))
         output_table.add_row("Partition spec", str(table.spec()))
         output_table.add_row("Sort order", str(table.sort_order()))
-        output_table.add_row("Schema", schema_tree)
+        output_table.add_row("Current schema", schema_tree)
+        output_table.add_row("Current snapshot", str(table.current_snapshot()))
         output_table.add_row("Snapshots", snapshot_tree)
         output_table.add_row("Properties", table_properties)
         Console().print(output_table)
diff --git a/python/pyiceberg/manifest.py b/python/pyiceberg/manifest.py
index ffb1c3b910..6079fcc336 100644
--- a/python/pyiceberg/manifest.py
+++ b/python/pyiceberg/manifest.py
@@ -46,23 +46,35 @@ class DataFileContent(int, Enum):
     POSITION_DELETES = 1
     EQUALITY_DELETES = 2
 
+    def __repr__(self) -> str:
+        return f"DataFileContent.{self.name}"
+
 
 class ManifestContent(int, Enum):
     DATA = 0
     DELETES = 1
 
+    def __repr__(self) -> str:
+        return f"ManifestContent.{self.name}"
+
 
 class ManifestEntryStatus(int, Enum):
     EXISTING = 0
     ADDED = 1
     DELETED = 2
 
+    def __repr__(self) -> str:
+        return f"ManifestEntryStatus.{self.name}"
+
 
 class FileFormat(str, Enum):
     AVRO = "AVRO"
     PARQUET = "PARQUET"
     ORC = "ORC"
 
+    def __repr__(self) -> str:
+        return f"FileFormat.{self.name}"
+
 
 class DataFile(IcebergBaseModel):
     content: DataFileContent = Field(default=DataFileContent.DATA)
diff --git a/python/pyiceberg/table/__init__.py b/python/pyiceberg/table/__init__.py
index bf9f128a32..edcd1a3230 100644
--- a/python/pyiceberg/table/__init__.py
+++ b/python/pyiceberg/table/__init__.py
@@ -14,8 +14,6 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-
-
 from typing import (
     Dict,
     List,
diff --git a/python/pyiceberg/table/snapshots.py b/python/pyiceberg/table/snapshots.py
index 8f061777f7..849b2f3c06 100644
--- a/python/pyiceberg/table/snapshots.py
+++ b/python/pyiceberg/table/snapshots.py
@@ -96,6 +96,13 @@ class Snapshot(IcebergBaseModel):
     summary: Optional[Summary] = Field()
     schema_id: Optional[int] = Field(alias="schema-id", default=None)
 
+    def __str__(self) -> str:
+        operation = f"{self.summary.operation}: " if self.summary else ""
+        parent_id = f", parent_id={self.parent_snapshot_id}" if self.parent_snapshot_id else ""
+        schema_id = f", schema_id={self.schema_id}" if self.schema_id is not None else ""
+        result_str = f"{operation}id={self.snapshot_id}{parent_id}{schema_id}"
+        return result_str
+
 
 class MetadataLogEntry(IcebergBaseModel):
     metadata_file: str = Field(alias="metadata-file")
diff --git a/python/tests/cli/test_console.py b/python/tests/cli/test_console.py
index 9f8ac2245a..c0a2022e03 100644
--- a/python/tests/cli/test_console.py
+++ b/python/tests/cli/test_console.py
@@ -189,13 +189,17 @@ Sort order            [
                         2 ASC NULLS FIRST
                         bucket[4](3) DESC NULLS LAST
                       ]
-Schema                Schema
+Current schema        Schema, id=1
                       ├── 1: x: required long
                       ├── 2: y: required long (comment)
                       └── 3: z: required long
+Current snapshot      Operation.APPEND: id=3055729675574597004,
+                      parent_id=3051729675574597004, schema_id=1
 Snapshots             Snapshots
-                      ├── Snapshot None: s3://a/b/1.avro
-                      └── Snapshot 1: s3://a/b/2.avro
+                      ├── Snapshot 3051729675574597004, schema None:
+                      │   s3://a/b/1.avro
+                      └── Snapshot 3055729675574597004, schema 1:
+                          s3://a/b/2.avro
 Properties            read.split.target.size  134217728
 """
     )