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