@@ -287,3 +287,65 @@ def test_normalize_prequery_result_type_custom_sql() -> None:
287
287
sqla_table ._normalize_prequery_result_type (row , dimension , columns_by_name )
288
288
== "Car"
289
289
)
290
+
291
+
292
+ def test_get_sqla_table_with_catalog (mocker : MockerFixture ) -> None :
293
+ """Test that get_sqla_table includes catalog in table identifier
294
+ for databases with cross-catalog support
295
+ """
296
+ # Test case 1: Database supports cross-catalog queries (like BigQuery)
297
+ database_with_catalog = mocker .MagicMock ()
298
+ database_with_catalog .db_engine_spec .supports_cross_catalog_queries = True
299
+
300
+ table_with_catalog = SqlaTable (
301
+ table_name = "test_table" ,
302
+ database = database_with_catalog ,
303
+ schema = "test_dataset" ,
304
+ catalog = "test_project" ,
305
+ )
306
+
307
+ sqla_table = table_with_catalog .get_sqla_table ()
308
+ # Should generate "test_project.test_dataset.test_table"
309
+ assert sqla_table .name == "test_project.test_dataset.test_table"
310
+ # Schema should not be set as it's now part of the table name
311
+ assert sqla_table .schema is None
312
+
313
+ # Test case 2: Database doesn't support cross-catalog queries
314
+ database_no_catalog = mocker .MagicMock ()
315
+ database_no_catalog .db_engine_spec .supports_cross_catalog_queries = False
316
+
317
+ table_no_catalog_support = SqlaTable (
318
+ table_name = "test_table" ,
319
+ database = database_no_catalog ,
320
+ schema = "test_schema" ,
321
+ catalog = "test_catalog" ,
322
+ )
323
+
324
+ sqla_table_no_catalog = table_no_catalog_support .get_sqla_table ()
325
+ # Should ignore catalog and use traditional schema.table format
326
+ assert sqla_table_no_catalog .name == "test_table"
327
+ assert sqla_table_no_catalog .schema == "test_schema"
328
+
329
+ # Test case 3: Table with catalog but no schema (BigQuery style)
330
+ table_catalog_only = SqlaTable (
331
+ table_name = "test_table" ,
332
+ database = database_with_catalog ,
333
+ catalog = "test_project" ,
334
+ )
335
+
336
+ sqla_table_catalog_only = table_catalog_only .get_sqla_table ()
337
+ # Should generate "test_project.test_table"
338
+ assert sqla_table_catalog_only .name == "test_project.test_table"
339
+ assert sqla_table_catalog_only .schema is None
340
+
341
+ # Test case 4: Table with schema but no catalog (traditional behavior)
342
+ table_schema_only = SqlaTable (
343
+ table_name = "test_table" ,
344
+ database = database_with_catalog ,
345
+ schema = "test_schema" ,
346
+ )
347
+
348
+ sqla_table_schema_only = table_schema_only .get_sqla_table ()
349
+ # Should generate just "test_table" with schema set separately
350
+ assert sqla_table_schema_only .name == "test_table"
351
+ assert sqla_table_schema_only .schema == "test_schema"
0 commit comments