Skip to content

Commit

Permalink
add sort_order to table repr
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiPhan committed Sep 21, 2023
1 parent 01a7479 commit b602573
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
9 changes: 5 additions & 4 deletions python/pyiceberg/table/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,10 +543,11 @@ def __eq__(self, other: Any) -> bool:
def __repr__(self) -> str:
"""Return the string representation of the Table class."""
table_name = self.catalog.table_name_from(self.identifier)
schema_str = ",\n ".join(f"{column.name}: {column.field_type}" for column in self.schema().columns)
partition_str = ", ".join(field.name for field in self.spec().fields)
snapshot_str = str(self.current_snapshot()) if self.current_snapshot() else "null"
result_str = f"{table_name}(\n {schema_str}\n),\npartition by: [{partition_str}],\nsnapshot: {snapshot_str}"
schema_str = ",\n ".join(str(column) for column in self.schema().columns if self.schema())
partition_str = f"partition by: [{', '.join(field.name for field in self.spec().fields if self.spec())}]"
sort_order_str = f"sort order: [{', '.join(str(field) for field in self.sort_order().fields if self.sort_order())}]"
snapshot_str = f"snapshot: {str(self.current_snapshot()) if self.current_snapshot() else 'null'}"
result_str = f"{table_name}(\n {schema_str}\n),\n{partition_str},\n{sort_order_str},\n{snapshot_str}"
return result_str


Expand Down
7 changes: 4 additions & 3 deletions python/tests/table/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,12 @@ def test_snapshot_by_name_does_not_exist(table: Table) -> None:

def test_repr(table: Table) -> None:
expected = """table(
x: long,
y: long,
z: long
1: x: required long,
2: y: required long (comment),
3: z: required long
),
partition by: [x],
sort order: [2 ASC NULLS FIRST, bucket[4](3) DESC NULLS LAST],
snapshot: Operation.APPEND: id=3055729675574597004, parent_id=3051729675574597004, schema_id=1"""
assert repr(table) == expected

Expand Down

0 comments on commit b602573

Please sign in to comment.