flolas commented on code in PR #36171:
URL: https://github.com/apache/airflow/pull/36171#discussion_r1427917066


##########
airflow/providers/amazon/aws/hooks/athena_sql.py:
##########
@@ -0,0 +1,103 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+from functools import cached_property
+from typing import TYPE_CHECKING
+
+import pyathena
+from sqlalchemy.engine.url import URL
+
+from airflow.providers.amazon.aws.hooks.base_aws import AwsBaseHook
+from airflow.providers.common.sql.hooks.sql import DbApiHook
+
+if TYPE_CHECKING:
+    from mypy_boto3_athena.client import athena  # noqa
+    from pyathena.connection import Connection as AthenaConnection
+
+
+class AthenaSQLHook(AwsBaseHook, DbApiHook):
+    """Interact with Amazon Athena.
+
+    Provide wrapper around PyAthena library.
+
+    :param athena_conn_id: :ref:`Amazon Athena Connection 
<howto/connection:athena_sql>`.
+
+    PyAthena parameters could be passed in extra field of ``athena_conn_id`` 
connection.
+
+    Additional arguments (such as ``aws_conn_id``) may be specified and
+    are passed down to the underlying AwsBaseHook.
+
+    .. note::
+        get_uri() depends on SQLAlchemy and PyAthena.
+
+    .. seealso::
+        :class:`~airflow.providers.amazon.aws.hooks.base_aws.AwsBaseHook`
+    """
+
+    conn_name_attr = "athena_conn_id"
+    default_conn_name = "athena_default"
+    conn_type = "athena"
+    hook_name = "Amazon Athena"
+    supports_autocommit = True
+
+    def __init__(self, athena_conn_id: str | None = default_conn_name, *args, 
**kwargs) -> None:
+        super().__init__(*args, **kwargs)
+        self.athena_conn_id = athena_conn_id
+        if "aws_conn_id" not in kwargs:
+            self.aws_conn_id = athena_conn_id
+
+    @cached_property
+    def conn(self):
+        """Get athena connection object."""
+        return self.get_connection(self.athena_conn_id)  # type: 
ignore[attr-defined]
+
+    def _get_conn_params(self) -> dict[str, str | None]:
+        """Retrieve connection parameters."""
+        return dict(
+            driver=self.conn.extra_dejson.get("driver", "rest"),
+            schema_name=self.conn.schema,
+            region_name=self.region_name,
+        )
+
+    def get_uri(self) -> str:
+        """Overridden to use the Athena dialect as driver name."""
+        creds = self.get_credentials(region_name=self.region_name)
+        conn_params = self._get_conn_params()

Review Comment:
   ```suggestion
           conn_params = self._get_conn_params()
           creds = self.get_credentials(region_name=conn_params["region_name"])
   ```



-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to