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


##########
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:
   Good catch. Fixed in the latest commit (d0eef45629): when the URL is in the 
triple-slash form (`bigquery:///project`), we now detect that the host is empty 
while database holds the project, and normalize to the two-slash form 
(`bigquery://project`) before setting `database=schema`.



##########
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:
   Added in the same commit (d0eef45629): the test now includes a 
`bigquery:///my_project` assertion that verifies `uri.host == "my_project"` and 
`uri.database == "my_dataset"` after the fix.



-- 
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