Copilot commented on code in PR #40776:
URL: https://github.com/apache/superset/pull/40776#discussion_r3364751900


##########
tests/unit_tests/db_engine_specs/test_bigquery.py:
##########
@@ -451,6 +451,42 @@ def test_adjust_engine_params_catalog_as_host() -> None:
     assert str(uri) == "bigquery://other-project/"
 
 
+def test_adjust_engine_params_schema_as_dataset() -> None:
+    """
+    Test that passing a schema sets it as the BigQuery default dataset.
+
+    BigQuery requires table names to be fully qualified (project.dataset.table)
+    unless a default dataset is set via the URL database component. When schema
+    is provided, the URL database should be updated so unqualified table names
+    resolve to schema.table_name.
+    """
+    from superset.db_engine_specs.bigquery import BigQueryEngineSpec
+
+    url = make_url("bigquery://project")
+
+    # Without schema, URL is unchanged
+    uri = BigQueryEngineSpec.adjust_engine_params(url, {})[0]
+    assert str(uri) == "bigquery://project"

Review Comment:
   This test covers the `bigquery://project` URL form, but BigQuery also 
supports `bigquery:///project` (project encoded in the URL database). Since 
`adjust_engine_params` is now mutating `database` based on `schema`, please add 
an assertion for the triple-slash form to ensure the project isn’t overwritten 
when setting the default dataset (eg normalize to 
`bigquery://project/<dataset>`).



##########
superset/db_engine_specs/bigquery.py:
##########
@@ -742,6 +742,10 @@ def adjust_engine_params(
     ) -> tuple[URL, dict[str, Any]]:
         if catalog:
             uri = uri.set(host=catalog, database="")
+        if schema:
+            # Setting database to schema makes it the BigQuery default dataset,
+            # so unqualified table names in SQL resolve to schema.table_name.
+            uri = uri.set(database=schema)

Review Comment:
   `adjust_engine_params` sets `uri.database = schema` unconditionally when 
`schema` is provided. For BigQuery URLs that encode the project in the database 
component (eg `bigquery:///my_project`), this overwrites the project with the 
dataset and yields an invalid URL (`bigquery:///my_dataset`). This can break 
existing configurations that use the triple-slash form mentioned in 
`get_default_catalog()`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to