Skip to content

Commit 7a4734e

Browse files
authored
Replace reference of Table.identifier with Table.name (apache#1346)
* fix Table.name * replace Table.identifier with Table.name * add warning filter
1 parent 8e0e6a1 commit 7a4734e

File tree

15 files changed

+105
-108
lines changed

15 files changed

+105
-108
lines changed

pyiceberg/catalog/glue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ def commit_table(
479479
NoSuchTableError: If a table with the given identifier does not exist.
480480
CommitFailedException: Requirement not met, or a conflict with a concurrent commit.
481481
"""
482-
table_identifier = self._identifier_to_tuple_without_catalog(table.identifier)
482+
table_identifier = table.name()
483483
database_name, table_name = self.identifier_to_database_and_table(table_identifier, NoSuchTableError)
484484

485485
current_glue_table: Optional[TableTypeDef]

pyiceberg/catalog/hive.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def _convert_hive_into_iceberg(self, table: HiveTable) -> Table:
314314
)
315315

316316
def _convert_iceberg_into_hive(self, table: Table) -> HiveTable:
317-
identifier_tuple = self._identifier_to_tuple_without_catalog(table.identifier)
317+
identifier_tuple = table.name()
318318
database_name, table_name = self.identifier_to_database_and_table(identifier_tuple, NoSuchTableError)
319319
current_time_millis = int(time.time() * 1000)
320320

@@ -455,7 +455,7 @@ def commit_table(
455455
NoSuchTableError: If a table with the given identifier does not exist.
456456
CommitFailedException: Requirement not met, or a conflict with a concurrent commit.
457457
"""
458-
table_identifier = self._identifier_to_tuple_without_catalog(table.identifier)
458+
table_identifier = table.name()
459459
database_name, table_name = self.identifier_to_database_and_table(table_identifier, NoSuchTableError)
460460
# commit to hive
461461
# https://github.com/apache/hive/blob/master/standalone-metastore/metastore-common/src/main/thrift/hive_metastore.thrift#L1232

pyiceberg/catalog/rest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ def commit_table(
775775
CommitFailedException: Requirement not met, or a conflict with a concurrent commit.
776776
CommitStateUnknownException: Failed due to an internal exception on the side of the catalog.
777777
"""
778-
identifier = self._identifier_to_tuple_without_catalog(table.identifier)
778+
identifier = table.name()
779779
table_identifier = TableIdentifier(namespace=identifier[:-1], name=identifier[-1])
780780
table_request = CommitTableRequest(identifier=table_identifier, requirements=requirements, updates=updates)
781781

pyiceberg/catalog/sql.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ def commit_table(
419419
NoSuchTableError: If a table with the given identifier does not exist.
420420
CommitFailedException: Requirement not met, or a conflict with a concurrent commit.
421421
"""
422-
table_identifier = self._identifier_to_tuple_without_catalog(table.identifier)
422+
table_identifier = table.name()
423423
namespace_tuple = Catalog.namespace_from(table_identifier)
424424
namespace = Catalog.namespace_to_string(namespace_tuple)
425425
table_name = Catalog.table_name_from(table_identifier)
@@ -430,7 +430,7 @@ def commit_table(
430430
except NoSuchTableError:
431431
current_table = None
432432

433-
updated_staged_table = self._update_and_stage_table(current_table, table.identifier, requirements, updates)
433+
updated_staged_table = self._update_and_stage_table(current_table, table.name(), requirements, updates)
434434
if current_table and updated_staged_table.metadata == current_table.metadata:
435435
# no changes, do nothing
436436
return CommitTableResponse(metadata=current_table.metadata, metadata_location=current_table.metadata_location)

pyiceberg/cli/output.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def files(self, table: Table, history: bool) -> None:
137137
else:
138138
snapshots = []
139139

140-
snapshot_tree = Tree(f"Snapshots: {'.'.join(table.identifier)}")
140+
snapshot_tree = Tree(f"Snapshots: {'.'.join(table.name())}")
141141
io = table.io
142142

143143
for snapshot in snapshots:
@@ -216,7 +216,7 @@ class FauxTable(IcebergBaseModel):
216216

217217
print(
218218
FauxTable(
219-
identifier=table.identifier, metadata=table.metadata, metadata_location=table.metadata_location
219+
identifier=table.name(), metadata=table.metadata, metadata_location=table.metadata_location
220220
).model_dump_json()
221221
)
222222

pyiceberg/table/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ def name(self) -> Identifier:
801801
Returns:
802802
An Identifier tuple of the table name
803803
"""
804-
return self.identifier
804+
return self._identifier
805805

806806
def scan(
807807
self,

tests/catalog/integration_test_dynamodb.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_create_table(
5757
test_catalog.create_namespace(database_name)
5858
test_catalog.create_table(identifier, table_schema_nested, get_s3_path(get_bucket_name(), database_name, table_name))
5959
table = test_catalog.load_table(identifier)
60-
assert table.identifier == (test_catalog.name,) + identifier
60+
assert table.name() == identifier
6161
metadata_location = table.metadata_location.split(get_bucket_name())[1][1:]
6262
s3.head_object(Bucket=get_bucket_name(), Key=metadata_location)
6363

@@ -78,7 +78,7 @@ def test_create_table_with_default_location(
7878
test_catalog.create_namespace(database_name)
7979
test_catalog.create_table(identifier, table_schema_nested)
8080
table = test_catalog.load_table(identifier)
81-
assert table.identifier == (test_catalog.name,) + identifier
81+
assert table.name() == identifier
8282
metadata_location = table.metadata_location.split(get_bucket_name())[1][1:]
8383
s3.head_object(Bucket=get_bucket_name(), Key=metadata_location)
8484

@@ -102,15 +102,15 @@ def test_create_table_if_not_exists_duplicated_table(
102102
test_catalog.create_namespace(database_name)
103103
table1 = test_catalog.create_table((database_name, table_name), table_schema_nested)
104104
table2 = test_catalog.create_table_if_not_exists((database_name, table_name), table_schema_nested)
105-
assert table1.identifier == table2.identifier
105+
assert table1.name() == table2.name()
106106

107107

108108
def test_load_table(test_catalog: Catalog, table_schema_nested: Schema, database_name: str, table_name: str) -> None:
109109
identifier = (database_name, table_name)
110110
test_catalog.create_namespace(database_name)
111111
table = test_catalog.create_table(identifier, table_schema_nested)
112112
loaded_table = test_catalog.load_table(identifier)
113-
assert table.identifier == loaded_table.identifier
113+
assert table.name() == loaded_table.name()
114114
assert table.metadata_location == loaded_table.metadata_location
115115
assert table.metadata == loaded_table.metadata
116116

@@ -134,11 +134,11 @@ def test_rename_table(
134134
new_table_name = f"rename-{table_name}"
135135
identifier = (database_name, table_name)
136136
table = test_catalog.create_table(identifier, table_schema_nested)
137-
assert table.identifier == (test_catalog.name,) + identifier
137+
assert table.name() == identifier
138138
new_identifier = (new_database_name, new_table_name)
139139
test_catalog.rename_table(identifier, new_identifier)
140140
new_table = test_catalog.load_table(new_identifier)
141-
assert new_table.identifier == (test_catalog.name,) + new_identifier
141+
assert new_table.name() == new_identifier
142142
assert new_table.metadata_location == table.metadata_location
143143
metadata_location = new_table.metadata_location.split(get_bucket_name())[1][1:]
144144
s3.head_object(Bucket=get_bucket_name(), Key=metadata_location)
@@ -150,7 +150,7 @@ def test_drop_table(test_catalog: Catalog, table_schema_nested: Schema, table_na
150150
identifier = (database_name, table_name)
151151
test_catalog.create_namespace(database_name)
152152
table = test_catalog.create_table(identifier, table_schema_nested)
153-
assert table.identifier == (test_catalog.name,) + identifier
153+
assert table.name() == identifier
154154
test_catalog.drop_table(identifier)
155155
with pytest.raises(NoSuchTableError):
156156
test_catalog.load_table(identifier)
@@ -163,7 +163,7 @@ def test_purge_table(
163163
test_catalog.create_namespace(database_name)
164164
test_catalog.create_table(identifier, table_schema_nested)
165165
table = test_catalog.load_table(identifier)
166-
assert table.identifier == (test_catalog.name,) + identifier
166+
assert table.name() == identifier
167167
metadata_location = table.metadata_location.split(get_bucket_name())[1][1:]
168168
s3.head_object(Bucket=get_bucket_name(), Key=metadata_location)
169169
test_catalog.purge_table(identifier)

tests/catalog/integration_test_glue.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def test_create_table(
119119
test_catalog.create_namespace(database_name)
120120
test_catalog.create_table(identifier, table_schema_nested, get_s3_path(get_bucket_name(), database_name, table_name))
121121
table = test_catalog.load_table(identifier)
122-
assert table.identifier == (CATALOG_NAME,) + identifier
122+
assert table.name() == identifier
123123
metadata_location = table.metadata_location.split(get_bucket_name())[1][1:]
124124
s3.head_object(Bucket=get_bucket_name(), Key=metadata_location)
125125
assert MetastoreCatalog._parse_metadata_version(table.metadata_location) == 0
@@ -183,7 +183,7 @@ def test_create_table_with_default_location(
183183
test_catalog.create_namespace(database_name)
184184
test_catalog.create_table(identifier, table_schema_nested)
185185
table = test_catalog.load_table(identifier)
186-
assert table.identifier == (CATALOG_NAME,) + identifier
186+
assert table.name() == identifier
187187
metadata_location = table.metadata_location.split(get_bucket_name())[1][1:]
188188
s3.head_object(Bucket=get_bucket_name(), Key=metadata_location)
189189
assert MetastoreCatalog._parse_metadata_version(table.metadata_location) == 0
@@ -208,15 +208,15 @@ def test_create_table_if_not_exists_duplicated_table(
208208
test_catalog.create_namespace(database_name)
209209
table1 = test_catalog.create_table((database_name, table_name), table_schema_nested)
210210
table2 = test_catalog.create_table_if_not_exists((database_name, table_name), table_schema_nested)
211-
assert table1.identifier == table2.identifier
211+
assert table1.name() == table2.name()
212212

213213

214214
def test_load_table(test_catalog: Catalog, table_schema_nested: Schema, table_name: str, database_name: str) -> None:
215215
identifier = (database_name, table_name)
216216
test_catalog.create_namespace(database_name)
217217
table = test_catalog.create_table(identifier, table_schema_nested)
218218
loaded_table = test_catalog.load_table(identifier)
219-
assert table.identifier == loaded_table.identifier
219+
assert table.name() == loaded_table.name()
220220
assert table.metadata_location == loaded_table.metadata_location
221221
assert table.metadata == loaded_table.metadata
222222
assert MetastoreCatalog._parse_metadata_version(table.metadata_location) == 0
@@ -242,11 +242,11 @@ def test_rename_table(
242242
identifier = (database_name, table_name)
243243
table = test_catalog.create_table(identifier, table_schema_nested)
244244
assert MetastoreCatalog._parse_metadata_version(table.metadata_location) == 0
245-
assert table.identifier == (CATALOG_NAME,) + identifier
245+
assert table.name() == identifier
246246
new_identifier = (new_database_name, new_table_name)
247247
test_catalog.rename_table(identifier, new_identifier)
248248
new_table = test_catalog.load_table(new_identifier)
249-
assert new_table.identifier == (CATALOG_NAME,) + new_identifier
249+
assert new_table.name() == new_identifier
250250
assert new_table.metadata_location == table.metadata_location
251251
metadata_location = new_table.metadata_location.split(get_bucket_name())[1][1:]
252252
s3.head_object(Bucket=get_bucket_name(), Key=metadata_location)
@@ -258,7 +258,7 @@ def test_drop_table(test_catalog: Catalog, table_schema_nested: Schema, table_na
258258
identifier = (database_name, table_name)
259259
test_catalog.create_namespace(database_name)
260260
table = test_catalog.create_table(identifier, table_schema_nested)
261-
assert table.identifier == (CATALOG_NAME,) + identifier
261+
assert table.name() == identifier
262262
test_catalog.drop_table(identifier)
263263
with pytest.raises(NoSuchTableError):
264264
test_catalog.load_table(identifier)
@@ -271,7 +271,7 @@ def test_purge_table(
271271
test_catalog.create_namespace(database_name)
272272
test_catalog.create_table(identifier, table_schema_nested)
273273
table = test_catalog.load_table(identifier)
274-
assert table.identifier == (CATALOG_NAME,) + identifier
274+
assert table.name() == identifier
275275
metadata_location = table.metadata_location.split(get_bucket_name())[1][1:]
276276
s3.head_object(Bucket=get_bucket_name(), Key=metadata_location)
277277
test_catalog.purge_table(identifier)
@@ -536,7 +536,7 @@ def test_create_table_transaction(
536536
update_snapshot.append_data_file(data_file)
537537

538538
table = test_catalog.load_table(identifier)
539-
assert table.identifier == (CATALOG_NAME,) + identifier
539+
assert table.name() == identifier
540540
metadata_location = table.metadata_location.split(get_bucket_name())[1][1:]
541541
s3.head_object(Bucket=get_bucket_name(), Key=metadata_location)
542542
assert MetastoreCatalog._parse_metadata_version(table.metadata_location) == 0
@@ -584,6 +584,6 @@ def test_register_table_with_given_location(
584584
test_catalog.drop_table(identifier) # drops the table but keeps the metadata file
585585
assert not test_catalog.table_exists(identifier)
586586
table = test_catalog.register_table(new_identifier, location)
587-
assert table.identifier == (CATALOG_NAME,) + new_identifier
587+
assert table.name() == new_identifier
588588
assert table.metadata_location == location
589589
assert test_catalog.table_exists(new_identifier)

tests/catalog/test_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def register_table(self, identifier: Union[str, Identifier], metadata_location:
133133
def commit_table(
134134
self, table: Table, requirements: Tuple[TableRequirement, ...], updates: Tuple[TableUpdate, ...]
135135
) -> CommitTableResponse:
136-
identifier_tuple = self._identifier_to_tuple_without_catalog(table.identifier)
136+
identifier_tuple = table.name()
137137
current_table = self.load_table(identifier_tuple)
138138
base_metadata = current_table.metadata
139139

0 commit comments

Comments
 (0)