Copilot commented on code in PR #36003:
URL: https://github.com/apache/superset/pull/36003#discussion_r2495666971
##########
superset/db_engine_specs/athena.py:
##########
@@ -92,3 +94,41 @@ def _mutate_label(label: str) -> str:
:return: Conditionally mutated label
"""
return label.lower()
+
+ @classmethod
+ def adjust_engine_params(
+ cls,
+ uri: URL,
+ connect_args: dict[str, Any],
+ catalog: str | None = None,
+ schema: str | None = None,
+ ) -> tuple[URL, dict[str, Any]]:
+ """
+ Adjust the SQLAlchemy URI for Athena with a provided catalog and
schema.
+
+ For AWS Athena the SQLAlchemy URI looks like this:
+
+
awsathena+rest://athena.{region_name}.amazonaws.com:443/{schema_name}?catalog_name={catalog_name}&s3_staging_dir={s3_staging_dir}
+ """
+ if catalog:
+ uri = uri.update_query_dict({"catalog_name": catalog})
+
+ if schema:
+ uri = uri.set(database=schema)
+
+ return uri, connect_args
+
+ @classmethod
+ def get_schema_from_engine_params(
+ cls,
+ sqlalchemy_uri: URL,
+ connect_args: dict[str, Any],
+ ) -> str | None:
+ """
+ Return the configured schema.
+
+ For AWS Athena the SQLAlchemy URI looks like this:
+
+
awsathena+rest://athena.{region_name}.amazonaws.com:443/{schema_name}?catalog_name={catalog_name}&s3_staging_dir={s3_staging_dir}
+ """
+ return sqlalchemy_uri.database
Review Comment:
Consider adding explicit handling for empty strings to match the pattern
used in similar implementations. The current code returns the database
attribute directly, but if the database is an empty string, it should return
`None` instead. Add: `return sqlalchemy_uri.database or None` to ensure
consistent behavior.
```suggestion
return sqlalchemy_uri.database or None
```
##########
superset/db_engine_specs/athena.py:
##########
@@ -92,3 +94,41 @@ def _mutate_label(label: str) -> str:
:return: Conditionally mutated label
"""
return label.lower()
+
+ @classmethod
+ def adjust_engine_params(
+ cls,
+ uri: URL,
+ connect_args: dict[str, Any],
+ catalog: str | None = None,
+ schema: str | None = None,
+ ) -> tuple[URL, dict[str, Any]]:
+ """
+ Adjust the SQLAlchemy URI for Athena with a provided catalog and
schema.
+
+ For AWS Athena the SQLAlchemy URI looks like this:
+
+
awsathena+rest://athena.{region_name}.amazonaws.com:443/{schema_name}?catalog_name={catalog_name}&s3_staging_dir={s3_staging_dir}
+ """
+ if catalog:
+ uri = uri.update_query_dict({"catalog_name": catalog})
+
+ if schema:
+ uri = uri.set(database=schema)
+
+ return uri, connect_args
+
+ @classmethod
+ def get_schema_from_engine_params(
+ cls,
+ sqlalchemy_uri: URL,
+ connect_args: dict[str, Any],
+ ) -> str | None:
+ """
+ Return the configured schema.
+
+ For AWS Athena the SQLAlchemy URI looks like this:
+
+
awsathena+rest://athena.{region_name}.amazonaws.com:443/{schema_name}?catalog_name={catalog_name}&s3_staging_dir={s3_staging_dir}
+ """
+ return sqlalchemy_uri.database
Review Comment:
The `get_schema_from_engine_params` method should handle the case where
`sqlalchemy_uri.database` is `None` or an empty string. Without this check,
accessing `.database` on a URL without a database component could lead to
issues. Consider adding a guard to return `None` if `database` is falsy,
similar to how Presto and Snowflake handle this (they check `if \"/\" not in
database`).
```suggestion
database = sqlalchemy_uri.database
if not database:
return None
return database
```
--
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]