Skip to content

Commit 50791ae

Browse files
committed
remove support for catalog_name in identifier string
1 parent 3966263 commit 50791ae

File tree

13 files changed

+82
-125
lines changed

13 files changed

+82
-125
lines changed

pyiceberg/catalog/dynamodb.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,7 @@ def load_table(self, identifier: Union[str, Identifier]) -> Table:
247247
Raises:
248248
NoSuchTableError: If a table with the name does not exist, or the identifier is invalid.
249249
"""
250-
identifier_tuple = self.identifier_to_tuple_without_catalog(identifier)
251-
database_name, table_name = self.identifier_to_database_and_table(identifier_tuple, NoSuchTableError)
250+
database_name, table_name = self.identifier_to_database_and_table(identifier, NoSuchTableError)
252251
dynamo_table_item = self._get_iceberg_table_item(database_name=database_name, table_name=table_name)
253252
return self._convert_dynamo_table_item_to_iceberg_table(dynamo_table_item=dynamo_table_item)
254253

@@ -639,7 +638,7 @@ def _convert_dynamo_table_item_to_iceberg_table(self, dynamo_table_item: Dict[st
639638
file = io.new_input(metadata_location)
640639
metadata = FromInputFile.table_metadata(file)
641640
return Table(
642-
identifier=(self.name, database_name, table_name),
641+
identifier=(database_name, table_name),
643642
metadata=metadata,
644643
metadata_location=metadata_location,
645644
io=self._load_file_io(metadata.properties, metadata_location),

pyiceberg/catalog/glue.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def _convert_glue_to_iceberg(self, glue_table: TableTypeDef) -> Table:
348348
file = io.new_input(metadata_location)
349349
metadata = FromInputFile.table_metadata(file)
350350
return Table(
351-
identifier=(self.name, database_name, table_name),
351+
identifier=(database_name, table_name),
352352
metadata=metadata,
353353
metadata_location=metadata_location,
354354
io=self._load_file_io(metadata.properties, metadata_location),
@@ -543,8 +543,7 @@ def load_table(self, identifier: Union[str, Identifier]) -> Table:
543543
Raises:
544544
NoSuchTableError: If a table with the name does not exist, or the identifier is invalid.
545545
"""
546-
identifier_tuple = self.identifier_to_tuple_without_catalog(identifier)
547-
database_name, table_name = self.identifier_to_database_and_table(identifier_tuple, NoSuchTableError)
546+
database_name, table_name = self.identifier_to_database_and_table(identifier, NoSuchTableError)
548547

549548
return self._convert_glue_to_iceberg(self._get_glue_table(database_name=database_name, table_name=table_name))
550549

pyiceberg/catalog/hive.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def _convert_hive_into_iceberg(self, table: HiveTable) -> Table:
293293
file = io.new_input(metadata_location)
294294
metadata = FromInputFile.table_metadata(file)
295295
return Table(
296-
identifier=(self.name, table.dbName, table.tableName),
296+
identifier=(table.dbName, table.tableName),
297297
metadata=metadata,
298298
metadata_location=metadata_location,
299299
io=self._load_file_io(metadata.properties, metadata_location),
@@ -513,8 +513,7 @@ def load_table(self, identifier: Union[str, Identifier]) -> Table:
513513
Raises:
514514
NoSuchTableError: If a table with the name does not exist, or the identifier is invalid.
515515
"""
516-
identifier_tuple = self.identifier_to_tuple_without_catalog(identifier)
517-
database_name, table_name = self.identifier_to_database_and_table(identifier_tuple, NoSuchTableError)
516+
database_name, table_name = self.identifier_to_database_and_table(identifier, NoSuchTableError)
518517

519518
with self._client as open_client:
520519
hive_table = self._get_hive_table(open_client, database_name, table_name)

pyiceberg/catalog/rest.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -347,14 +347,15 @@ def _fetch_config(self) -> None:
347347
self.uri = config[URI]
348348

349349
def _identifier_to_validated_tuple(self, identifier: Union[str, Identifier]) -> Identifier:
350+
print(f"DEBUG: {identifier}")
350351
identifier_tuple = self.identifier_to_tuple(identifier)
351352
if len(identifier_tuple) <= 1:
352353
raise NoSuchTableError(f"Missing namespace or invalid identifier: {'.'.join(identifier_tuple)}")
353354
return identifier_tuple
354355

355356
def _split_identifier_for_path(self, identifier: Union[str, Identifier, TableIdentifier]) -> Properties:
356357
if isinstance(identifier, TableIdentifier):
357-
return {"namespace": NAMESPACE_SEPARATOR.join(identifier.namespace.root[1:]), "table": identifier.name}
358+
return {"namespace": NAMESPACE_SEPARATOR.join(identifier.namespace.root), "table": identifier.name}
358359
identifier_tuple = self._identifier_to_validated_tuple(identifier)
359360
return {"namespace": NAMESPACE_SEPARATOR.join(identifier_tuple[:-1]), "table": identifier_tuple[-1]}
360361

@@ -462,7 +463,7 @@ def add_headers(self, request: PreparedRequest, **kwargs: Any) -> None: # pylin
462463

463464
def _response_to_table(self, identifier_tuple: Tuple[str, ...], table_response: TableResponse) -> Table:
464465
return Table(
465-
identifier=(self.name,) + identifier_tuple if self.name else identifier_tuple,
466+
identifier=identifier_tuple,
466467
metadata_location=table_response.metadata_location, # type: ignore
467468
metadata=table_response.metadata,
468469
io=self._load_file_io(
@@ -473,7 +474,7 @@ def _response_to_table(self, identifier_tuple: Tuple[str, ...], table_response:
473474

474475
def _response_to_staged_table(self, identifier_tuple: Tuple[str, ...], table_response: TableResponse) -> StagedTable:
475476
return StagedTable(
476-
identifier=(self.name,) + identifier_tuple if self.name else identifier_tuple,
477+
identifier=identifier_tuple,
477478
metadata_location=table_response.metadata_location, # type: ignore
478479
metadata=table_response.metadata,
479480
io=self._load_file_io(
@@ -631,17 +632,15 @@ def list_tables(self, namespace: Union[str, Identifier]) -> List[Identifier]:
631632

632633
@retry(**_RETRY_ARGS)
633634
def load_table(self, identifier: Union[str, Identifier]) -> Table:
634-
identifier_tuple = self.identifier_to_tuple_without_catalog(identifier)
635-
response = self._session.get(
636-
self.url(Endpoints.load_table, prefixed=True, **self._split_identifier_for_path(identifier_tuple))
637-
)
635+
print(f"LOAD_TABLE: {identifier=}")
636+
response = self._session.get(self.url(Endpoints.load_table, prefixed=True, **self._split_identifier_for_path(identifier)))
638637
try:
639638
response.raise_for_status()
640639
except HTTPError as exc:
641640
self._handle_non_200_response(exc, {404: NoSuchTableError})
642641

643642
table_response = TableResponse(**response.json())
644-
return self._response_to_table(identifier_tuple, table_response)
643+
return self._response_to_table(self.identifier_to_tuple(identifier), table_response)
645644

646645
@retry(**_RETRY_ARGS)
647646
def drop_table(self, identifier: Union[str, Identifier], purge_requested: bool = False) -> None:

pyiceberg/catalog/sql.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def _convert_orm_to_iceberg(self, orm_table: IcebergTables) -> Table:
155155
file = io.new_input(metadata_location)
156156
metadata = FromInputFile.table_metadata(file)
157157
return Table(
158-
identifier=(self.name,) + Catalog.identifier_to_tuple(table_namespace) + (table_name,),
158+
identifier=Catalog.identifier_to_tuple(table_namespace) + (table_name,),
159159
metadata=metadata,
160160
metadata_location=metadata_location,
161161
io=self._load_file_io(metadata.properties, metadata_location),
@@ -277,10 +277,9 @@ def load_table(self, identifier: Union[str, Identifier]) -> Table:
277277
Raises:
278278
NoSuchTableError: If a table with the name does not exist.
279279
"""
280-
identifier_tuple = self.identifier_to_tuple_without_catalog(identifier)
281-
namespace_tuple = Catalog.namespace_from(identifier_tuple)
280+
namespace_tuple = Catalog.namespace_from(identifier)
282281
namespace = Catalog.namespace_to_string(namespace_tuple)
283-
table_name = Catalog.table_name_from(identifier_tuple)
282+
table_name = Catalog.table_name_from(identifier)
284283
with Session(self.engine) as session:
285284
stmt = select(IcebergTables).where(
286285
IcebergTables.catalog_name == self.name,

pyiceberg/table/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,7 @@ def inspect(self) -> InspectTable:
14021402

14031403
def refresh(self) -> Table:
14041404
"""Refresh the current table metadata."""
1405-
fresh = self.catalog.load_table(self.identifier[1:])
1405+
fresh = self.catalog.load_table(self.identifier)
14061406
self.metadata = fresh.metadata
14071407
self.io = fresh.io
14081408
self.metadata_location = fresh.metadata_location

tests/catalog/integration_test_glue.py

Lines changed: 8 additions & 8 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.identifier == 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.identifier == 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
@@ -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.identifier == 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.identifier == 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.identifier == 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.identifier == 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.identifier == 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.identifier == new_identifier
588588
assert table.metadata_location == location
589589
assert test_catalog.table_exists(new_identifier)

tests/catalog/test_dynamodb.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_create_table_with_database_location(
7474
test_catalog = DynamoDbCatalog(catalog_name, **{"s3.endpoint": moto_endpoint_url})
7575
test_catalog.create_namespace(namespace=database_name, properties={"location": f"s3://{BUCKET_NAME}/{database_name}.db"})
7676
table = test_catalog.create_table(identifier, table_schema_nested)
77-
assert table.identifier == (catalog_name,) + identifier
77+
assert table.identifier == identifier
7878
assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location)
7979

8080

@@ -91,7 +91,7 @@ def test_create_table_with_pyarrow_schema(
9191
test_catalog = DynamoDbCatalog(catalog_name, **{"s3.endpoint": moto_endpoint_url})
9292
test_catalog.create_namespace(namespace=database_name, properties={"location": f"s3://{BUCKET_NAME}/{database_name}.db"})
9393
table = test_catalog.create_table(identifier, pyarrow_schema_simple_without_ids)
94-
assert table.identifier == (catalog_name,) + identifier
94+
assert table.identifier == identifier
9595
assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location)
9696

9797

@@ -104,7 +104,7 @@ def test_create_table_with_default_warehouse(
104104
test_catalog = DynamoDbCatalog(catalog_name, **{"s3.endpoint": moto_endpoint_url, "warehouse": f"s3://{BUCKET_NAME}"})
105105
test_catalog.create_namespace(namespace=database_name)
106106
table = test_catalog.create_table(identifier, table_schema_nested)
107-
assert table.identifier == (catalog_name,) + identifier
107+
assert table.identifier == identifier
108108
assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location)
109109

110110

@@ -119,7 +119,7 @@ def test_create_table_with_given_location(
119119
table = test_catalog.create_table(
120120
identifier=identifier, schema=table_schema_nested, location=f"s3://{BUCKET_NAME}/{database_name}.db/{table_name}"
121121
)
122-
assert table.identifier == (catalog_name,) + identifier
122+
assert table.identifier == identifier
123123
assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location)
124124

125125

@@ -133,7 +133,7 @@ def test_create_table_removes_trailing_slash_in_location(
133133
test_catalog.create_namespace(namespace=database_name)
134134
location = f"s3://{BUCKET_NAME}/{database_name}.db/{table_name}"
135135
table = test_catalog.create_table(identifier=identifier, schema=table_schema_nested, location=f"{location}/")
136-
assert table.identifier == (catalog_name,) + identifier
136+
assert table.identifier == identifier
137137
assert table.location() == location
138138
assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location)
139139

@@ -158,7 +158,7 @@ def test_create_table_with_strips(
158158
test_catalog = DynamoDbCatalog(catalog_name, **{"s3.endpoint": moto_endpoint_url})
159159
test_catalog.create_namespace(namespace=database_name, properties={"location": f"s3://{BUCKET_NAME}/{database_name}.db/"})
160160
table = test_catalog.create_table(identifier, table_schema_nested)
161-
assert table.identifier == (catalog_name,) + identifier
161+
assert table.identifier == identifier
162162
assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location)
163163

164164

@@ -171,7 +171,7 @@ def test_create_table_with_strips_bucket_root(
171171
test_catalog = DynamoDbCatalog(catalog_name, **{"s3.endpoint": moto_endpoint_url, "warehouse": f"s3://{BUCKET_NAME}/"})
172172
test_catalog.create_namespace(namespace=database_name)
173173
table_strip = test_catalog.create_table(identifier, table_schema_nested)
174-
assert table_strip.identifier == (catalog_name,) + identifier
174+
assert table_strip.identifier == identifier
175175
assert TABLE_METADATA_LOCATION_REGEX.match(table_strip.metadata_location)
176176

177177

@@ -219,7 +219,7 @@ def test_load_table(
219219
test_catalog.create_namespace(namespace=database_name)
220220
test_catalog.create_table(identifier, table_schema_nested)
221221
table = test_catalog.load_table(identifier)
222-
assert table.identifier == (catalog_name,) + identifier
222+
assert table.identifier == identifier
223223
assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location)
224224

225225

@@ -234,7 +234,7 @@ def test_load_table_from_self_identifier(
234234
test_catalog.create_table(identifier, table_schema_nested)
235235
intermediate = test_catalog.load_table(identifier)
236236
table = test_catalog.load_table(intermediate.identifier)
237-
assert table.identifier == (catalog_name,) + identifier
237+
assert table.identifier == identifier
238238
assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location)
239239

240240

@@ -257,7 +257,7 @@ def test_drop_table(
257257
test_catalog.create_namespace(namespace=database_name)
258258
test_catalog.create_table(identifier, table_schema_nested)
259259
table = test_catalog.load_table(identifier)
260-
assert table.identifier == (catalog_name,) + identifier
260+
assert table.identifier == identifier
261261
assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location)
262262
test_catalog.drop_table(identifier)
263263
with pytest.raises(NoSuchTableError):
@@ -274,7 +274,7 @@ def test_drop_table_from_self_identifier(
274274
test_catalog.create_namespace(namespace=database_name)
275275
test_catalog.create_table(identifier, table_schema_nested)
276276
table = test_catalog.load_table(identifier)
277-
assert table.identifier == (catalog_name,) + identifier
277+
assert table.identifier == identifier
278278
assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location)
279279
test_catalog.drop_table(table.identifier)
280280
with pytest.raises(NoSuchTableError):
@@ -302,11 +302,11 @@ def test_rename_table(
302302
test_catalog = DynamoDbCatalog(catalog_name, **{"warehouse": f"s3://{BUCKET_NAME}", "s3.endpoint": moto_endpoint_url})
303303
test_catalog.create_namespace(namespace=database_name)
304304
table = test_catalog.create_table(identifier, table_schema_nested)
305-
assert table.identifier == (catalog_name,) + identifier
305+
assert table.identifier == identifier
306306
assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location)
307307
test_catalog.rename_table(identifier, new_identifier)
308308
new_table = test_catalog.load_table(new_identifier)
309-
assert new_table.identifier == (catalog_name,) + new_identifier
309+
assert new_table.identifier == new_identifier
310310
# the metadata_location should not change
311311
assert new_table.metadata_location == table.metadata_location
312312
# old table should be dropped
@@ -325,11 +325,11 @@ def test_rename_table_from_self_identifier(
325325
test_catalog = DynamoDbCatalog(catalog_name, **{"warehouse": f"s3://{BUCKET_NAME}", "s3.endpoint": moto_endpoint_url})
326326
test_catalog.create_namespace(namespace=database_name)
327327
table = test_catalog.create_table(identifier, table_schema_nested)
328-
assert table.identifier == (catalog_name,) + identifier
328+
assert table.identifier == identifier
329329
assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location)
330330
test_catalog.rename_table(table.identifier, new_identifier)
331331
new_table = test_catalog.load_table(new_identifier)
332-
assert new_table.identifier == (catalog_name,) + new_identifier
332+
assert new_table.identifier == new_identifier
333333
# the metadata_location should not change
334334
assert new_table.metadata_location == table.metadata_location
335335
# old table should be dropped

0 commit comments

Comments
 (0)