@@ -340,3 +340,34 @@ def test_get_table_names_smoke_test(samples_engine: Engine):
340
340
with samples_engine .connect () as conn :
341
341
_names = samples_engine .table_names (schema = "nyctaxi" , connection = conn )
342
342
_names is not None , "get_table_names did not succeed"
343
+
344
+ def test_has_table_across_schemas (db_engine : Engine , samples_engine : Engine ):
345
+ """For this test to pass these conditions must be met:
346
+ - Table samples.nyctaxi.trips must exist
347
+ - Table samples.tpch.customer must exist
348
+ - The `catalog` and `schema` environment variables must be set and valid
349
+ """
350
+
351
+ with samples_engine .connect () as conn :
352
+
353
+ # Check for table within schema declared at engine creation time
354
+ assert samples_engine .dialect .has_table (connection = conn , table_name = "trips" )
355
+
356
+ # Check for table within another schema in the same catalog
357
+ assert samples_engine .dialect .has_table (connection = conn , table_name = "customer" , schema = "tpch" )
358
+
359
+ # Check for a table within a different catalog
360
+ other_catalog = os .environ .get ("catalog" )
361
+ other_schema = os .environ .get ("schema" )
362
+
363
+ # Create a table in a different catalog
364
+ with db_engine .connect () as conn :
365
+ conn .execute ("CREATE TABLE test_has_table (numbers_are_cool INT);" )
366
+
367
+ try :
368
+ # Verify with a different engine that this table is not found in the samples catalog
369
+ assert not samples_engine .dialect .has_table (connection = conn , table_name = "test_has_table" )
370
+ # Verify with a different engine that this table is found in a separate catalog
371
+ assert samples_engine .dialect .has_table (connection = conn , table_name = "test_has_table" , schema = other_schema , catalog = other_catalog )
372
+ finally :
373
+ conn .execute ("DROP TABLE test_has_table;" )
0 commit comments