diff --git a/tests/catalog/integration_test_dynamodb.py b/tests/catalog/integration_test_dynamodb.py index 591e489b83..5b9584c69f 100644 --- a/tests/catalog/integration_test_dynamodb.py +++ b/tests/catalog/integration_test_dynamodb.py @@ -262,3 +262,9 @@ def test_update_namespace_properties(test_catalog: Catalog, database_name: str) else: assert k in update_report.removed assert "updated test description" == test_catalog.load_namespace_properties(database_name)["comment"] + + +def test_table_exists(test_catalog: Catalog, table_schema_nested: Schema, database_name: str, table_name: str) -> None: + test_catalog.create_namespace(database_name) + test_catalog.create_table((database_name, table_name), table_schema_nested) + assert test_catalog.table_exists((database_name, table_name)) is True diff --git a/tests/catalog/integration_test_glue.py b/tests/catalog/integration_test_glue.py index 393271c644..a2c430de5f 100644 --- a/tests/catalog/integration_test_glue.py +++ b/tests/catalog/integration_test_glue.py @@ -558,3 +558,9 @@ def test_create_table_transaction( ] }, ] + + +def test_table_exists(test_catalog: Catalog, table_schema_nested: Schema, table_name: str, database_name: str) -> None: + test_catalog.create_namespace(database_name) + test_catalog.create_table((database_name, table_name), table_schema_nested) + assert test_catalog.table_exists((database_name, table_name)) is True diff --git a/tests/catalog/test_dynamodb.py b/tests/catalog/test_dynamodb.py index 218b0e8be7..1c647cf828 100644 --- a/tests/catalog/test_dynamodb.py +++ b/tests/catalog/test_dynamodb.py @@ -562,3 +562,17 @@ def test_passing_provided_profile() -> None: assert test_catalog.dynamodb is mock_client mock_session.assert_called_with(**session_props) assert test_catalog.dynamodb is mock_session().client() + + +@mock_aws +def test_table_exists( + _bucket_initialize: None, moto_endpoint_url: str, table_schema_nested: Schema, database_name: str, table_name: str +) -> None: + identifier = (database_name, table_name) + test_catalog = DynamoDbCatalog("test_ddb_catalog", **{"warehouse": f"s3://{BUCKET_NAME}", "s3.endpoint": moto_endpoint_url}) + test_catalog.create_namespace(namespace=database_name) + test_catalog.create_table(identifier, table_schema_nested) + # Act and Assert for an existing table + assert test_catalog.table_exists(identifier) is True + # Act and Assert for an non-existing table + assert test_catalog.table_exists(('non', 'exist')) is False diff --git a/tests/catalog/test_glue.py b/tests/catalog/test_glue.py index 7b12261bb6..5999b192a2 100644 --- a/tests/catalog/test_glue.py +++ b/tests/catalog/test_glue.py @@ -817,3 +817,18 @@ def test_create_table_transaction( assert table.spec().fields_by_source_id(2)[0].name == "bar" assert table.spec().fields_by_source_id(2)[0].field_id == 1001 assert table.spec().fields_by_source_id(2)[0].transform == IdentityTransform() + + +@mock_aws +def test_table_exists( + _bucket_initialize: None, moto_endpoint_url: str, table_schema_simple: Schema, database_name: str, table_name: str +) -> None: + catalog_name = "glue" + identifier = (database_name, table_name) + test_catalog = GlueCatalog(catalog_name, **{"s3.endpoint": moto_endpoint_url, "warehouse": f"s3://{BUCKET_NAME}"}) + test_catalog.create_namespace(namespace=database_name) + test_catalog.create_table(identifier=identifier, schema=table_schema_simple) + # Act and Assert for an existing table + assert test_catalog.table_exists(identifier) is True + # Act and Assert for a non-existing table + assert test_catalog.table_exists(('non', 'exist')) is False diff --git a/tests/catalog/test_sql.py b/tests/catalog/test_sql.py index 99b8550602..40a1566e2f 100644 --- a/tests/catalog/test_sql.py +++ b/tests/catalog/test_sql.py @@ -982,3 +982,22 @@ def test_table_properties_raise_for_none_value( with pytest.raises(ValidationError) as exc_info: _ = catalog.create_table(random_identifier, table_schema_simple, properties=property_with_none) assert "None type is not a supported value in properties: property_name" in str(exc_info.value) + + +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) +def test_table_exists(catalog: SqlCatalog, table_schema_simple: Schema, random_identifier: Identifier) -> None: + database_name, _table_name = random_identifier + catalog.create_namespace(database_name) + catalog.create_table(random_identifier, table_schema_simple, properties={"format-version": "2"}) + existing_table = random_identifier + # Act and Assert for an existing table + assert catalog.table_exists(existing_table) is True + + # Act and Assert for a non-existing table + assert catalog.table_exists(('non', 'exist')) is False