diff --git a/pyiceberg/catalog/glue.py b/pyiceberg/catalog/glue.py index 5742173fa6..f5f8e30af8 100644 --- a/pyiceberg/catalog/glue.py +++ b/pyiceberg/catalog/glue.py @@ -459,7 +459,7 @@ def commit_table( NoSuchTableError: If a table with the given identifier does not exist. CommitFailedException: Requirement not met, or a conflict with a concurrent commit. """ - table_identifier = self._identifier_to_tuple_without_catalog(table.identifier) + table_identifier = table.name() database_name, table_name = self.identifier_to_database_and_table(table_identifier, NoSuchTableError) current_glue_table: Optional[TableTypeDef] diff --git a/pyiceberg/catalog/hive.py b/pyiceberg/catalog/hive.py index 030470e164..48643d751b 100644 --- a/pyiceberg/catalog/hive.py +++ b/pyiceberg/catalog/hive.py @@ -314,7 +314,7 @@ def _convert_hive_into_iceberg(self, table: HiveTable) -> Table: ) def _convert_iceberg_into_hive(self, table: Table) -> HiveTable: - identifier_tuple = self._identifier_to_tuple_without_catalog(table.identifier) + identifier_tuple = table.name() database_name, table_name = self.identifier_to_database_and_table(identifier_tuple, NoSuchTableError) current_time_millis = int(time.time() * 1000) @@ -455,7 +455,7 @@ def commit_table( NoSuchTableError: If a table with the given identifier does not exist. CommitFailedException: Requirement not met, or a conflict with a concurrent commit. """ - table_identifier = self._identifier_to_tuple_without_catalog(table.identifier) + table_identifier = table.name() database_name, table_name = self.identifier_to_database_and_table(table_identifier, NoSuchTableError) # commit to hive # https://github.com/apache/hive/blob/master/standalone-metastore/metastore-common/src/main/thrift/hive_metastore.thrift#L1232 diff --git a/pyiceberg/catalog/rest.py b/pyiceberg/catalog/rest.py index 5664084c7e..e2584921ea 100644 --- a/pyiceberg/catalog/rest.py +++ b/pyiceberg/catalog/rest.py @@ -775,7 +775,7 @@ def commit_table( CommitFailedException: Requirement not met, or a conflict with a concurrent commit. CommitStateUnknownException: Failed due to an internal exception on the side of the catalog. """ - identifier = self._identifier_to_tuple_without_catalog(table.identifier) + identifier = table.name() table_identifier = TableIdentifier(namespace=identifier[:-1], name=identifier[-1]) table_request = CommitTableRequest(identifier=table_identifier, requirements=requirements, updates=updates) diff --git a/pyiceberg/catalog/sql.py b/pyiceberg/catalog/sql.py index 6a4318253f..9776cc6bec 100644 --- a/pyiceberg/catalog/sql.py +++ b/pyiceberg/catalog/sql.py @@ -419,7 +419,7 @@ def commit_table( NoSuchTableError: If a table with the given identifier does not exist. CommitFailedException: Requirement not met, or a conflict with a concurrent commit. """ - table_identifier = self._identifier_to_tuple_without_catalog(table.identifier) + table_identifier = table.name() namespace_tuple = Catalog.namespace_from(table_identifier) namespace = Catalog.namespace_to_string(namespace_tuple) table_name = Catalog.table_name_from(table_identifier) @@ -430,7 +430,7 @@ def commit_table( except NoSuchTableError: current_table = None - updated_staged_table = self._update_and_stage_table(current_table, table.identifier, requirements, updates) + updated_staged_table = self._update_and_stage_table(current_table, table.name(), requirements, updates) if current_table and updated_staged_table.metadata == current_table.metadata: # no changes, do nothing return CommitTableResponse(metadata=current_table.metadata, metadata_location=current_table.metadata_location) diff --git a/pyiceberg/cli/output.py b/pyiceberg/cli/output.py index 56b544c99f..13a15c53f9 100644 --- a/pyiceberg/cli/output.py +++ b/pyiceberg/cli/output.py @@ -137,7 +137,7 @@ def files(self, table: Table, history: bool) -> None: else: snapshots = [] - snapshot_tree = Tree(f"Snapshots: {'.'.join(table.identifier)}") + snapshot_tree = Tree(f"Snapshots: {'.'.join(table.name())}") io = table.io for snapshot in snapshots: @@ -216,7 +216,7 @@ class FauxTable(IcebergBaseModel): print( FauxTable( - identifier=table.identifier, metadata=table.metadata, metadata_location=table.metadata_location + identifier=table.name(), metadata=table.metadata, metadata_location=table.metadata_location ).model_dump_json() ) diff --git a/tests/catalog/integration_test_dynamodb.py b/tests/catalog/integration_test_dynamodb.py index 05d51bb0ef..895f233c45 100644 --- a/tests/catalog/integration_test_dynamodb.py +++ b/tests/catalog/integration_test_dynamodb.py @@ -57,7 +57,7 @@ def test_create_table( test_catalog.create_namespace(database_name) test_catalog.create_table(identifier, table_schema_nested, get_s3_path(get_bucket_name(), database_name, table_name)) table = test_catalog.load_table(identifier) - assert table.identifier == (test_catalog.name,) + identifier + assert table.name() == identifier metadata_location = table.metadata_location.split(get_bucket_name())[1][1:] s3.head_object(Bucket=get_bucket_name(), Key=metadata_location) @@ -78,7 +78,7 @@ def test_create_table_with_default_location( test_catalog.create_namespace(database_name) test_catalog.create_table(identifier, table_schema_nested) table = test_catalog.load_table(identifier) - assert table.identifier == (test_catalog.name,) + identifier + assert table.name() == identifier metadata_location = table.metadata_location.split(get_bucket_name())[1][1:] s3.head_object(Bucket=get_bucket_name(), Key=metadata_location) @@ -102,7 +102,7 @@ def test_create_table_if_not_exists_duplicated_table( test_catalog.create_namespace(database_name) table1 = test_catalog.create_table((database_name, table_name), table_schema_nested) table2 = test_catalog.create_table_if_not_exists((database_name, table_name), table_schema_nested) - assert table1.identifier == table2.identifier + assert table1.name() == table2.name() def test_load_table(test_catalog: Catalog, table_schema_nested: Schema, database_name: str, table_name: str) -> None: @@ -110,7 +110,7 @@ def test_load_table(test_catalog: Catalog, table_schema_nested: Schema, database test_catalog.create_namespace(database_name) table = test_catalog.create_table(identifier, table_schema_nested) loaded_table = test_catalog.load_table(identifier) - assert table.identifier == loaded_table.identifier + assert table.name() == loaded_table.name() assert table.metadata_location == loaded_table.metadata_location assert table.metadata == loaded_table.metadata @@ -134,11 +134,11 @@ def test_rename_table( new_table_name = f"rename-{table_name}" identifier = (database_name, table_name) table = test_catalog.create_table(identifier, table_schema_nested) - assert table.identifier == (test_catalog.name,) + identifier + assert table.name() == identifier new_identifier = (new_database_name, new_table_name) test_catalog.rename_table(identifier, new_identifier) new_table = test_catalog.load_table(new_identifier) - assert new_table.identifier == (test_catalog.name,) + new_identifier + assert new_table.name() == new_identifier assert new_table.metadata_location == table.metadata_location metadata_location = new_table.metadata_location.split(get_bucket_name())[1][1:] 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 identifier = (database_name, table_name) test_catalog.create_namespace(database_name) table = test_catalog.create_table(identifier, table_schema_nested) - assert table.identifier == (test_catalog.name,) + identifier + assert table.name() == identifier test_catalog.drop_table(identifier) with pytest.raises(NoSuchTableError): test_catalog.load_table(identifier) @@ -163,7 +163,7 @@ def test_purge_table( test_catalog.create_namespace(database_name) test_catalog.create_table(identifier, table_schema_nested) table = test_catalog.load_table(identifier) - assert table.identifier == (test_catalog.name,) + identifier + assert table.name() == identifier metadata_location = table.metadata_location.split(get_bucket_name())[1][1:] s3.head_object(Bucket=get_bucket_name(), Key=metadata_location) test_catalog.purge_table(identifier) diff --git a/tests/catalog/integration_test_glue.py b/tests/catalog/integration_test_glue.py index a5293e38f2..475fc07ead 100644 --- a/tests/catalog/integration_test_glue.py +++ b/tests/catalog/integration_test_glue.py @@ -119,7 +119,7 @@ def test_create_table( test_catalog.create_namespace(database_name) test_catalog.create_table(identifier, table_schema_nested, get_s3_path(get_bucket_name(), database_name, table_name)) table = test_catalog.load_table(identifier) - assert table.identifier == (CATALOG_NAME,) + identifier + assert table.name() == identifier metadata_location = table.metadata_location.split(get_bucket_name())[1][1:] s3.head_object(Bucket=get_bucket_name(), Key=metadata_location) assert MetastoreCatalog._parse_metadata_version(table.metadata_location) == 0 @@ -183,7 +183,7 @@ def test_create_table_with_default_location( test_catalog.create_namespace(database_name) test_catalog.create_table(identifier, table_schema_nested) table = test_catalog.load_table(identifier) - assert table.identifier == (CATALOG_NAME,) + identifier + assert table.name() == identifier metadata_location = table.metadata_location.split(get_bucket_name())[1][1:] s3.head_object(Bucket=get_bucket_name(), Key=metadata_location) assert MetastoreCatalog._parse_metadata_version(table.metadata_location) == 0 @@ -208,7 +208,7 @@ def test_create_table_if_not_exists_duplicated_table( test_catalog.create_namespace(database_name) table1 = test_catalog.create_table((database_name, table_name), table_schema_nested) table2 = test_catalog.create_table_if_not_exists((database_name, table_name), table_schema_nested) - assert table1.identifier == table2.identifier + assert table1.name() == table2.name() def test_load_table(test_catalog: Catalog, table_schema_nested: Schema, table_name: str, database_name: str) -> None: @@ -216,7 +216,7 @@ def test_load_table(test_catalog: Catalog, table_schema_nested: Schema, table_na test_catalog.create_namespace(database_name) table = test_catalog.create_table(identifier, table_schema_nested) loaded_table = test_catalog.load_table(identifier) - assert table.identifier == loaded_table.identifier + assert table.name() == loaded_table.name() assert table.metadata_location == loaded_table.metadata_location assert table.metadata == loaded_table.metadata assert MetastoreCatalog._parse_metadata_version(table.metadata_location) == 0 @@ -242,11 +242,11 @@ def test_rename_table( identifier = (database_name, table_name) table = test_catalog.create_table(identifier, table_schema_nested) assert MetastoreCatalog._parse_metadata_version(table.metadata_location) == 0 - assert table.identifier == (CATALOG_NAME,) + identifier + assert table.name() == identifier new_identifier = (new_database_name, new_table_name) test_catalog.rename_table(identifier, new_identifier) new_table = test_catalog.load_table(new_identifier) - assert new_table.identifier == (CATALOG_NAME,) + new_identifier + assert new_table.name() == new_identifier assert new_table.metadata_location == table.metadata_location metadata_location = new_table.metadata_location.split(get_bucket_name())[1][1:] 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 identifier = (database_name, table_name) test_catalog.create_namespace(database_name) table = test_catalog.create_table(identifier, table_schema_nested) - assert table.identifier == (CATALOG_NAME,) + identifier + assert table.name() == identifier test_catalog.drop_table(identifier) with pytest.raises(NoSuchTableError): test_catalog.load_table(identifier) @@ -271,7 +271,7 @@ def test_purge_table( test_catalog.create_namespace(database_name) test_catalog.create_table(identifier, table_schema_nested) table = test_catalog.load_table(identifier) - assert table.identifier == (CATALOG_NAME,) + identifier + assert table.name() == identifier metadata_location = table.metadata_location.split(get_bucket_name())[1][1:] s3.head_object(Bucket=get_bucket_name(), Key=metadata_location) test_catalog.purge_table(identifier) @@ -536,7 +536,7 @@ def test_create_table_transaction( update_snapshot.append_data_file(data_file) table = test_catalog.load_table(identifier) - assert table.identifier == (CATALOG_NAME,) + identifier + assert table.name() == identifier metadata_location = table.metadata_location.split(get_bucket_name())[1][1:] s3.head_object(Bucket=get_bucket_name(), Key=metadata_location) assert MetastoreCatalog._parse_metadata_version(table.metadata_location) == 0 @@ -584,6 +584,6 @@ def test_register_table_with_given_location( test_catalog.drop_table(identifier) # drops the table but keeps the metadata file assert not test_catalog.table_exists(identifier) table = test_catalog.register_table(new_identifier, location) - assert table.identifier == (CATALOG_NAME,) + new_identifier + assert table.name() == new_identifier assert table.metadata_location == location assert test_catalog.table_exists(new_identifier) diff --git a/tests/catalog/test_base.py b/tests/catalog/test_base.py index e212854ee2..92e0a7236b 100644 --- a/tests/catalog/test_base.py +++ b/tests/catalog/test_base.py @@ -133,7 +133,7 @@ def register_table(self, identifier: Union[str, Identifier], metadata_location: def commit_table( self, table: Table, requirements: Tuple[TableRequirement, ...], updates: Tuple[TableUpdate, ...] ) -> CommitTableResponse: - identifier_tuple = self._identifier_to_tuple_without_catalog(table.identifier) + identifier_tuple = table.name() current_table = self.load_table(identifier_tuple) base_metadata = current_table.metadata diff --git a/tests/catalog/test_dynamodb.py b/tests/catalog/test_dynamodb.py index 0f89d12642..7ab875af90 100644 --- a/tests/catalog/test_dynamodb.py +++ b/tests/catalog/test_dynamodb.py @@ -73,7 +73,7 @@ def test_create_table_with_database_location( test_catalog = DynamoDbCatalog(catalog_name, **{"s3.endpoint": moto_endpoint_url}) test_catalog.create_namespace(namespace=database_name, properties={"location": f"s3://{BUCKET_NAME}/{database_name}.db"}) table = test_catalog.create_table(identifier, table_schema_nested) - assert table.identifier == (catalog_name,) + identifier + assert table.name() == identifier assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location) @@ -90,7 +90,7 @@ def test_create_table_with_pyarrow_schema( test_catalog = DynamoDbCatalog(catalog_name, **{"s3.endpoint": moto_endpoint_url}) test_catalog.create_namespace(namespace=database_name, properties={"location": f"s3://{BUCKET_NAME}/{database_name}.db"}) table = test_catalog.create_table(identifier, pyarrow_schema_simple_without_ids) - assert table.identifier == (catalog_name,) + identifier + assert table.name() == identifier assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location) @@ -103,7 +103,7 @@ def test_create_table_with_default_warehouse( test_catalog = DynamoDbCatalog(catalog_name, **{"s3.endpoint": moto_endpoint_url, "warehouse": f"s3://{BUCKET_NAME}"}) test_catalog.create_namespace(namespace=database_name) table = test_catalog.create_table(identifier, table_schema_nested) - assert table.identifier == (catalog_name,) + identifier + assert table.name() == identifier assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location) @@ -118,7 +118,7 @@ def test_create_table_with_given_location( table = test_catalog.create_table( identifier=identifier, schema=table_schema_nested, location=f"s3://{BUCKET_NAME}/{database_name}.db/{table_name}" ) - assert table.identifier == (catalog_name,) + identifier + assert table.name() == identifier assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location) @@ -132,7 +132,7 @@ def test_create_table_removes_trailing_slash_in_location( test_catalog.create_namespace(namespace=database_name) location = f"s3://{BUCKET_NAME}/{database_name}.db/{table_name}" table = test_catalog.create_table(identifier=identifier, schema=table_schema_nested, location=f"{location}/") - assert table.identifier == (catalog_name,) + identifier + assert table.name() == identifier assert table.location() == location assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location) @@ -157,7 +157,7 @@ def test_create_table_with_strips( test_catalog = DynamoDbCatalog(catalog_name, **{"s3.endpoint": moto_endpoint_url}) test_catalog.create_namespace(namespace=database_name, properties={"location": f"s3://{BUCKET_NAME}/{database_name}.db/"}) table = test_catalog.create_table(identifier, table_schema_nested) - assert table.identifier == (catalog_name,) + identifier + assert table.name() == identifier assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location) @@ -170,7 +170,7 @@ def test_create_table_with_strips_bucket_root( test_catalog = DynamoDbCatalog(catalog_name, **{"s3.endpoint": moto_endpoint_url, "warehouse": f"s3://{BUCKET_NAME}/"}) test_catalog.create_namespace(namespace=database_name) table_strip = test_catalog.create_table(identifier, table_schema_nested) - assert table_strip.identifier == (catalog_name,) + identifier + assert table_strip.name() == identifier assert TABLE_METADATA_LOCATION_REGEX.match(table_strip.metadata_location) @@ -205,7 +205,7 @@ def test_create_table_if_not_exists_duplicated_table( test_catalog.create_namespace(namespace=database_name) table1 = test_catalog.create_table(identifier, table_schema_nested) table2 = test_catalog.create_table_if_not_exists(identifier, table_schema_nested) - assert table1.identifier == table2.identifier + assert table1.name() == table2.name() @mock_aws @@ -218,7 +218,7 @@ def test_load_table( test_catalog.create_namespace(namespace=database_name) test_catalog.create_table(identifier, table_schema_nested) table = test_catalog.load_table(identifier) - assert table.identifier == (catalog_name,) + identifier + assert table.name() == identifier assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location) @@ -232,8 +232,8 @@ def test_load_table_from_self_identifier( test_catalog.create_namespace(namespace=database_name) test_catalog.create_table(identifier, table_schema_nested) intermediate = test_catalog.load_table(identifier) - table = test_catalog.load_table(intermediate.identifier) - assert table.identifier == (catalog_name,) + identifier + table = test_catalog.load_table(intermediate.name()) + assert table.name() == identifier assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location) @@ -256,7 +256,7 @@ def test_drop_table( test_catalog.create_namespace(namespace=database_name) test_catalog.create_table(identifier, table_schema_nested) table = test_catalog.load_table(identifier) - assert table.identifier == (catalog_name,) + identifier + assert table.name() == identifier assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location) test_catalog.drop_table(identifier) with pytest.raises(NoSuchTableError): @@ -273,13 +273,13 @@ def test_drop_table_from_self_identifier( test_catalog.create_namespace(namespace=database_name) test_catalog.create_table(identifier, table_schema_nested) table = test_catalog.load_table(identifier) - assert table.identifier == (catalog_name,) + identifier + assert table.name() == identifier assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location) - test_catalog.drop_table(table.identifier) + test_catalog.drop_table(table.name()) with pytest.raises(NoSuchTableError): test_catalog.load_table(identifier) with pytest.raises(NoSuchTableError): - test_catalog.load_table(table.identifier) + test_catalog.load_table(table.name()) @mock_aws @@ -301,11 +301,11 @@ def test_rename_table( test_catalog = DynamoDbCatalog(catalog_name, **{"warehouse": f"s3://{BUCKET_NAME}", "s3.endpoint": moto_endpoint_url}) test_catalog.create_namespace(namespace=database_name) table = test_catalog.create_table(identifier, table_schema_nested) - assert table.identifier == (catalog_name,) + identifier + assert table.name() == identifier assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location) test_catalog.rename_table(identifier, new_identifier) new_table = test_catalog.load_table(new_identifier) - assert new_table.identifier == (catalog_name,) + new_identifier + assert new_table.name() == new_identifier # the metadata_location should not change assert new_table.metadata_location == table.metadata_location # old table should be dropped @@ -324,18 +324,18 @@ def test_rename_table_from_self_identifier( test_catalog = DynamoDbCatalog(catalog_name, **{"warehouse": f"s3://{BUCKET_NAME}", "s3.endpoint": moto_endpoint_url}) test_catalog.create_namespace(namespace=database_name) table = test_catalog.create_table(identifier, table_schema_nested) - assert table.identifier == (catalog_name,) + identifier + assert table.name() == identifier assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location) - test_catalog.rename_table(table.identifier, new_identifier) + test_catalog.rename_table(table.name(), new_identifier) new_table = test_catalog.load_table(new_identifier) - assert new_table.identifier == (catalog_name,) + new_identifier + assert new_table.name() == new_identifier # the metadata_location should not change assert new_table.metadata_location == table.metadata_location # old table should be dropped with pytest.raises(NoSuchTableError): test_catalog.load_table(identifier) with pytest.raises(NoSuchTableError): - test_catalog.load_table(table.identifier) + test_catalog.load_table(table.name()) @mock_aws diff --git a/tests/catalog/test_glue.py b/tests/catalog/test_glue.py index 26c80bc968..fb6254ac3d 100644 --- a/tests/catalog/test_glue.py +++ b/tests/catalog/test_glue.py @@ -59,7 +59,7 @@ def test_create_table_with_database_location( test_catalog = GlueCatalog(catalog_name, **{"s3.endpoint": moto_endpoint_url}) test_catalog.create_namespace(namespace=database_name, properties={"location": f"s3://{BUCKET_NAME}/{database_name}.db"}) table = test_catalog.create_table(identifier, table_schema_nested) - assert table.identifier == (catalog_name,) + identifier + assert table.name() == identifier assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location) assert test_catalog._parse_metadata_version(table.metadata_location) == 0 @@ -121,7 +121,7 @@ def test_create_table_with_default_warehouse( test_catalog = GlueCatalog(catalog_name, **{"s3.endpoint": moto_endpoint_url, "warehouse": f"s3://{BUCKET_NAME}"}) test_catalog.create_namespace(namespace=database_name) table = test_catalog.create_table(identifier, table_schema_nested) - assert table.identifier == (catalog_name,) + identifier + assert table.name() == identifier assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location) assert test_catalog._parse_metadata_version(table.metadata_location) == 0 @@ -137,7 +137,7 @@ def test_create_table_with_given_location( table = test_catalog.create_table( identifier=identifier, schema=table_schema_nested, location=f"s3://{BUCKET_NAME}/{database_name}.db/{table_name}" ) - assert table.identifier == (catalog_name,) + identifier + assert table.name() == identifier assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location) assert test_catalog._parse_metadata_version(table.metadata_location) == 0 @@ -152,7 +152,7 @@ def test_create_table_removes_trailing_slash_in_location( test_catalog.create_namespace(namespace=database_name) location = f"s3://{BUCKET_NAME}/{database_name}.db/{table_name}" table = test_catalog.create_table(identifier=identifier, schema=table_schema_nested, location=f"{location}/") - assert table.identifier == (catalog_name,) + identifier + assert table.name() == identifier assert table.location() == location assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location) assert test_catalog._parse_metadata_version(table.metadata_location) == 0 @@ -175,7 +175,7 @@ def test_create_table_with_pyarrow_schema( schema=pyarrow_schema_simple_without_ids, location=f"s3://{BUCKET_NAME}/{database_name}.db/{table_name}", ) - assert table.identifier == (catalog_name,) + identifier + assert table.name() == identifier assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location) assert test_catalog._parse_metadata_version(table.metadata_location) == 0 @@ -201,7 +201,7 @@ def test_create_table_with_strips( test_catalog = GlueCatalog(catalog_name, **{"s3.endpoint": moto_endpoint_url}) test_catalog.create_namespace(namespace=database_name, properties={"location": f"s3://{BUCKET_NAME}/{database_name}.db/"}) table = test_catalog.create_table(identifier, table_schema_nested) - assert table.identifier == (catalog_name,) + identifier + assert table.name() == identifier assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location) assert test_catalog._parse_metadata_version(table.metadata_location) == 0 @@ -210,12 +210,11 @@ def test_create_table_with_strips( def test_create_table_with_strips_bucket_root( _bucket_initialize: None, moto_endpoint_url: str, table_schema_nested: Schema, database_name: str, table_name: str ) -> None: - catalog_name = "glue" identifier = (database_name, table_name) test_catalog = GlueCatalog("glue", **{"s3.endpoint": moto_endpoint_url, "warehouse": f"s3://{BUCKET_NAME}/"}) test_catalog.create_namespace(namespace=database_name) table_strip = test_catalog.create_table(identifier, table_schema_nested) - assert table_strip.identifier == (catalog_name,) + identifier + assert table_strip.name() == identifier assert TABLE_METADATA_LOCATION_REGEX.match(table_strip.metadata_location) assert test_catalog._parse_metadata_version(table_strip.metadata_location) == 0 @@ -242,7 +241,7 @@ def test_create_table_with_glue_catalog_id( ) test_catalog.create_namespace(namespace=database_name) table = test_catalog.create_table(identifier, table_schema_nested) - assert table.identifier == (catalog_name,) + identifier + assert table.name() == identifier assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location) assert test_catalog._parse_metadata_version(table.metadata_location) == 0 @@ -273,7 +272,7 @@ def test_load_table( test_catalog.create_namespace(namespace=database_name) test_catalog.create_table(identifier, table_schema_nested) table = test_catalog.load_table(identifier) - assert table.identifier == (catalog_name,) + identifier + assert table.name() == identifier assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location) assert test_catalog._parse_metadata_version(table.metadata_location) == 0 @@ -287,8 +286,8 @@ def test_load_table_from_self_identifier( test_catalog = GlueCatalog(catalog_name, **{"s3.endpoint": moto_endpoint_url, "warehouse": f"s3://{BUCKET_NAME}/"}) test_catalog.create_namespace(namespace=database_name) intermediate = test_catalog.create_table(identifier, table_schema_nested) - table = test_catalog.load_table(intermediate.identifier) - assert table.identifier == (catalog_name,) + identifier + table = test_catalog.load_table(intermediate.name()) + assert table.name() == identifier assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location) @@ -311,7 +310,7 @@ def test_drop_table( test_catalog.create_namespace(namespace=database_name) test_catalog.create_table(identifier, table_schema_nested) table = test_catalog.load_table(identifier) - assert table.identifier == (catalog_name,) + identifier + assert table.name() == identifier assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location) test_catalog.drop_table(identifier) with pytest.raises(NoSuchTableError): @@ -328,13 +327,13 @@ def test_drop_table_from_self_identifier( test_catalog.create_namespace(namespace=database_name) test_catalog.create_table(identifier, table_schema_nested) table = test_catalog.load_table(identifier) - assert table.identifier == (catalog_name,) + identifier + assert table.name() == identifier assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location) - test_catalog.drop_table(table.identifier) + test_catalog.drop_table(table.name()) with pytest.raises(NoSuchTableError): test_catalog.load_table(identifier) with pytest.raises(NoSuchTableError): - test_catalog.load_table(table.identifier) + test_catalog.load_table(table.name()) @mock_aws @@ -349,19 +348,18 @@ def test_drop_non_exist_table(_bucket_initialize: None, moto_endpoint_url: str, def test_rename_table( _bucket_initialize: None, moto_endpoint_url: str, table_schema_nested: Schema, database_name: str, table_name: str ) -> None: - catalog_name = "glue" new_table_name = f"{table_name}_new" identifier = (database_name, table_name) new_identifier = (database_name, new_table_name) test_catalog = GlueCatalog("glue", **{"s3.endpoint": moto_endpoint_url, "warehouse": f"s3://{BUCKET_NAME}/"}) test_catalog.create_namespace(namespace=database_name) table = test_catalog.create_table(identifier, table_schema_nested) - assert table.identifier == (catalog_name,) + identifier + assert table.name() == identifier assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location) assert test_catalog._parse_metadata_version(table.metadata_location) == 0 test_catalog.rename_table(identifier, new_identifier) new_table = test_catalog.load_table(new_identifier) - assert new_table.identifier == (catalog_name,) + new_identifier + assert new_table.name() == new_identifier # the metadata_location should not change assert new_table.metadata_location == table.metadata_location # old table should be dropped @@ -373,25 +371,24 @@ def test_rename_table( def test_rename_table_from_self_identifier( _bucket_initialize: None, moto_endpoint_url: str, table_schema_nested: Schema, database_name: str, table_name: str ) -> None: - catalog_name = "glue" new_table_name = f"{table_name}_new" identifier = (database_name, table_name) new_identifier = (database_name, new_table_name) test_catalog = GlueCatalog("glue", **{"s3.endpoint": moto_endpoint_url, "warehouse": f"s3://{BUCKET_NAME}/"}) test_catalog.create_namespace(namespace=database_name) table = test_catalog.create_table(identifier, table_schema_nested) - assert table.identifier == (catalog_name,) + identifier + assert table.name() == identifier assert TABLE_METADATA_LOCATION_REGEX.match(table.metadata_location) - test_catalog.rename_table(table.identifier, new_identifier) + test_catalog.rename_table(table.name(), new_identifier) new_table = test_catalog.load_table(new_identifier) - assert new_table.identifier == (catalog_name,) + new_identifier + assert new_table.name() == new_identifier # the metadata_location should not change assert new_table.metadata_location == table.metadata_location # old table should be dropped with pytest.raises(NoSuchTableError): test_catalog.load_table(identifier) with pytest.raises(NoSuchTableError): - test_catalog.load_table(table.identifier) + test_catalog.load_table(table.name()) @mock_aws @@ -914,7 +911,7 @@ def test_register_table_with_given_location( test_catalog = GlueCatalog(catalog_name, **{"s3.endpoint": moto_endpoint_url, "warehouse": f"s3://{BUCKET_NAME}"}) test_catalog.create_namespace(namespace=database_name, properties={"location": f"s3://{BUCKET_NAME}/{database_name}.db"}) table = test_catalog.register_table(identifier, location) - assert table.identifier == (catalog_name,) + identifier + assert table.name() == identifier assert test_catalog.table_exists(identifier) is True diff --git a/tests/catalog/test_hive.py b/tests/catalog/test_hive.py index 7756611dd7..3ff9bef775 100644 --- a/tests/catalog/test_hive.py +++ b/tests/catalog/test_hive.py @@ -699,7 +699,7 @@ def test_load_table(hive_table: HiveTable) -> None: last_sequence_number=34, ) - assert table.identifier == (HIVE_CATALOG_NAME, "default", "new_tabl2e") + assert table.name() == ("default", "new_tabl2e") assert expected == table.metadata @@ -709,7 +709,7 @@ def test_load_table_from_self_identifier(hive_table: HiveTable) -> None: catalog._client = MagicMock() catalog._client.__enter__().get_table.return_value = hive_table intermediate = catalog.load_table(("default", "new_tabl2e")) - table = catalog.load_table(intermediate.identifier) + table = catalog.load_table(intermediate.name()) catalog._client.__enter__().get_table.assert_called_with(dbname="default", tbl_name="new_tabl2e") @@ -800,7 +800,7 @@ def test_load_table_from_self_identifier(hive_table: HiveTable) -> None: last_sequence_number=34, ) - assert table.identifier == (HIVE_CATALOG_NAME, "default", "new_tabl2e") + assert table.name() == ("default", "new_tabl2e") assert expected == table.metadata @@ -819,7 +819,7 @@ def test_rename_table(hive_table: HiveTable) -> None: to_identifier = ("default", "new_tabl3e") table = catalog.rename_table(from_identifier, to_identifier) - assert table.identifier == ("hive",) + to_identifier + assert table.name() == to_identifier calls = [call(dbname="default", tbl_name="new_tabl2e"), call(dbname="default", tbl_name="new_tabl3e")] catalog._client.__enter__().get_table.assert_has_calls(calls) @@ -843,9 +843,9 @@ def test_rename_table_from_self_identifier(hive_table: HiveTable) -> None: catalog._client.__enter__().get_table.side_effect = [hive_table, renamed_table] catalog._client.__enter__().alter_table.return_value = None to_identifier = ("default", "new_tabl3e") - table = catalog.rename_table(from_table.identifier, to_identifier) + table = catalog.rename_table(from_table.name(), to_identifier) - assert table.identifier == ("hive",) + to_identifier + assert table.name() == to_identifier calls = [call(dbname="default", tbl_name="new_tabl2e"), call(dbname="default", tbl_name="new_tabl3e")] catalog._client.__enter__().get_table.assert_has_calls(calls) @@ -962,7 +962,7 @@ def test_drop_table_from_self_identifier(hive_table: HiveTable) -> None: table = catalog.load_table(("default", "new_tabl2e")) catalog._client.__enter__().get_all_databases.return_value = ["namespace1", "namespace2"] - catalog.drop_table(table.identifier) + catalog.drop_table(table.name()) catalog._client.__enter__().drop_table.assert_called_with(dbname="default", name="new_tabl2e", deleteData=False) diff --git a/tests/catalog/test_rest.py b/tests/catalog/test_rest.py index f8662c1bf4..5d633ed006 100644 --- a/tests/catalog/test_rest.py +++ b/tests/catalog/test_rest.py @@ -763,7 +763,7 @@ def test_load_table_from_self_identifier_200( ) catalog = RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN) table = catalog.load_table(("pdames", "table")) - actual = catalog.load_table(table.identifier) + actual = catalog.load_table(table.name()) expected = Table( identifier=("pdames", "table"), metadata_location=example_table_metadata_with_snapshot_v1_rest_json["metadata-location"], @@ -1111,7 +1111,7 @@ def test_register_table_200( ) assert actual.metadata.model_dump() == expected.metadata.model_dump() assert actual.metadata_location == expected.metadata_location - assert actual.identifier == expected.identifier + assert actual.name() == expected.name() def test_register_table_409(rest_mock: Mocker, table_schema_simple: Schema) -> None: @@ -1174,7 +1174,7 @@ def test_delete_table_from_self_identifier_204( status_code=204, request_headers=TEST_HEADERS, ) - catalog.drop_table(table.identifier) + catalog.drop_table(table.name()) def test_rename_table_200(rest_mock: Mocker, example_table_metadata_with_snapshot_v1_rest_json: Dict[str, Any]) -> None: @@ -1236,7 +1236,7 @@ def test_rename_table_from_self_identifier_200( status_code=200, request_headers=TEST_HEADERS, ) - actual = catalog.rename_table(table.identifier, to_identifier) + actual = catalog.rename_table(table.name(), to_identifier) expected = Table( identifier=("pdames", "destination"), metadata_location=example_table_metadata_with_snapshot_v1_rest_json["metadata-location"], diff --git a/tests/catalog/test_sql.py b/tests/catalog/test_sql.py index d3815fec04..fcefc597d2 100644 --- a/tests/catalog/test_sql.py +++ b/tests/catalog/test_sql.py @@ -493,7 +493,7 @@ def test_create_table_with_default_warehouse_location( catalog.create_namespace(namespace) catalog.create_table(table_identifier, table_schema_nested) table = catalog.load_table(table_identifier) - assert table.identifier == (catalog.name,) + table_identifier_nocatalog + assert table.name() == table_identifier_nocatalog assert table.metadata_location.startswith(f"file://{warehouse}") assert os.path.exists(table.metadata_location[len("file://") :]) catalog.drop_table(table_identifier) @@ -524,7 +524,7 @@ def test_create_table_with_given_location_removes_trailing_slash( catalog.create_namespace(namespace) catalog.create_table(table_identifier, table_schema_nested, location=f"{location}/") table = catalog.load_table(table_identifier) - assert table.identifier == (catalog.name,) + table_identifier_nocatalog + assert table.name() == table_identifier_nocatalog assert table.metadata_location.startswith(f"file://{warehouse}") assert os.path.exists(table.metadata_location[len("file://") :]) assert table.location() == location @@ -578,7 +578,7 @@ def test_create_table_if_not_exists_duplicated_table( catalog.create_namespace(namespace) table1 = catalog.create_table(table_identifier, table_schema_nested) table2 = catalog.create_table_if_not_exists(table_identifier, table_schema_nested) - assert table1.identifier == table2.identifier + assert table1.name() == table2.name() @pytest.mark.parametrize( @@ -626,7 +626,7 @@ def test_register_table(catalog: SqlCatalog, table_identifier: Identifier, metad namespace = Catalog.namespace_from(table_identifier_nocatalog) catalog.create_namespace(namespace) table = catalog.register_table(table_identifier, metadata_location) - assert table.identifier == (catalog.name,) + table_identifier_nocatalog + assert table.name() == table_identifier_nocatalog assert table.metadata_location == metadata_location assert os.path.exists(metadata_location) catalog.drop_table(table_identifier) @@ -702,7 +702,7 @@ def test_load_table(catalog: SqlCatalog, table_schema_nested: Schema, table_iden catalog.create_namespace(namespace) table = catalog.create_table(table_identifier, table_schema_nested) loaded_table = catalog.load_table(table_identifier) - assert table.identifier == loaded_table.identifier + assert table.name() == loaded_table.name() assert table.metadata_location == loaded_table.metadata_location assert table.metadata == loaded_table.metadata @@ -728,9 +728,9 @@ def test_load_table_from_self_identifier(catalog: SqlCatalog, table_schema_neste catalog.create_namespace(namespace) table = catalog.create_table(table_identifier, table_schema_nested) intermediate = catalog.load_table(table_identifier) - assert intermediate.identifier == (catalog.name,) + table_identifier_nocatalog - loaded_table = catalog.load_table(intermediate.identifier) - assert table.identifier == loaded_table.identifier + assert intermediate.name() == table_identifier_nocatalog + loaded_table = catalog.load_table(intermediate.name()) + assert table.name() == loaded_table.name() assert table.metadata_location == loaded_table.metadata_location assert table.metadata == loaded_table.metadata @@ -756,7 +756,7 @@ def test_drop_table(catalog: SqlCatalog, table_schema_nested: Schema, table_iden namespace = Catalog.namespace_from(table_identifier_nocatalog) catalog.create_namespace(namespace) table = catalog.create_table(table_identifier, table_schema_nested) - assert table.identifier == (catalog.name,) + table_identifier_nocatalog + assert table.name() == table_identifier_nocatalog catalog.drop_table(table_identifier) with pytest.raises(NoSuchTableError): catalog.load_table(table_identifier) @@ -783,10 +783,10 @@ def test_drop_table_from_self_identifier(catalog: SqlCatalog, table_schema_neste namespace = Catalog.namespace_from(table_identifier_nocatalog) catalog.create_namespace(namespace) table = catalog.create_table(table_identifier, table_schema_nested) - assert table.identifier == (catalog.name,) + table_identifier_nocatalog - catalog.drop_table(table.identifier) + assert table.name() == table_identifier_nocatalog + catalog.drop_table(table.name()) with pytest.raises(NoSuchTableError): - catalog.load_table(table.identifier) + catalog.load_table(table.name()) with pytest.raises(NoSuchTableError): catalog.load_table(table_identifier) @@ -846,10 +846,10 @@ def test_rename_table( catalog.create_namespace(from_namespace) catalog.create_namespace(to_namespace) table = catalog.create_table(from_table_identifier, table_schema_nested) - assert table.identifier == (catalog.name,) + from_table_identifier_nocatalog + assert table.name() == from_table_identifier_nocatalog catalog.rename_table(from_table_identifier, to_table_identifier) new_table = catalog.load_table(to_table_identifier) - assert new_table.identifier == (catalog.name,) + to_table_identifier_nocatalog + assert new_table.name() == to_table_identifier_nocatalog assert new_table.metadata_location == table.metadata_location with pytest.raises(NoSuchTableError): catalog.load_table(from_table_identifier) @@ -889,13 +889,13 @@ def test_rename_table_from_self_identifier( catalog.create_namespace(from_namespace) catalog.create_namespace(to_namespace) table = catalog.create_table(from_table_identifier, table_schema_nested) - assert table.identifier == (catalog.name,) + from_table_identifier_nocatalog - catalog.rename_table(table.identifier, to_table_identifier) + assert table.name() == from_table_identifier_nocatalog + catalog.rename_table(table.name(), to_table_identifier) new_table = catalog.load_table(to_table_identifier) - assert new_table.identifier == (catalog.name,) + to_table_identifier_nocatalog + assert new_table.name() == to_table_identifier_nocatalog assert new_table.metadata_location == table.metadata_location with pytest.raises(NoSuchTableError): - catalog.load_table(table.identifier) + catalog.load_table(table.name()) with pytest.raises(NoSuchTableError): catalog.load_table(from_table_identifier) @@ -934,9 +934,9 @@ def test_rename_table_to_existing_one( catalog.create_namespace(from_namespace) catalog.create_namespace(to_namespace) table = catalog.create_table(from_table_identifier, table_schema_nested) - assert table.identifier == (catalog.name,) + from_table_identifier_nocatalog + assert table.name() == from_table_identifier_nocatalog new_table = catalog.create_table(to_table_identifier, table_schema_nested) - assert new_table.identifier == (catalog.name,) + to_table_identifier_nocatalog + assert new_table.name() == to_table_identifier_nocatalog with pytest.raises(TableAlreadyExistsError): catalog.rename_table(from_table_identifier, to_table_identifier) @@ -1004,7 +1004,7 @@ def test_rename_table_to_missing_namespace( from_namespace = Catalog.namespace_from(from_table_identifier_nocatalog) catalog.create_namespace(from_namespace) table = catalog.create_table(from_table_identifier, table_schema_nested) - assert table.identifier == (catalog.name,) + from_table_identifier_nocatalog + assert table.name() == from_table_identifier_nocatalog with pytest.raises(NoSuchNamespaceError): catalog.rename_table(from_table_identifier, to_table_identifier) diff --git a/tests/integration/test_reads.py b/tests/integration/test_reads.py index 3cf17c0e8c..006e1f3af1 100644 --- a/tests/integration/test_reads.py +++ b/tests/integration/test_reads.py @@ -673,7 +673,7 @@ def test_hive_locking(session_catalog_hive: HiveCatalog) -> None: database_name: str table_name: str - _, database_name, table_name = table.identifier + database_name, table_name = table.name() hive_client: _HiveClient = _HiveClient(session_catalog_hive.properties["uri"]) blocking_lock_request: LockRequest = session_catalog_hive._create_lock_request(database_name, table_name) @@ -694,7 +694,7 @@ def test_hive_locking_with_retry(session_catalog_hive: HiveCatalog) -> None: table = create_table(session_catalog_hive) database_name: str table_name: str - _, database_name, table_name = table.identifier + database_name, table_name = table.name() session_catalog_hive._lock_check_min_wait_time = 0.1 session_catalog_hive._lock_check_max_wait_time = 0.5 session_catalog_hive._lock_check_retries = 5