eladkal commented on code in PR #36171: URL: https://github.com/apache/airflow/pull/36171#discussion_r1427842314
########## 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] Review Comment: Why do we need this type ignore? We don't have this in other hooks ########## docs/apache-airflow-providers-amazon/operators/athena/index.rst: ########## @@ -0,0 +1,41 @@ + .. 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. + + + +Amazon Athena Operators +========================= + +Amazon Athena is an interactive query service that makes it easy to analyze data in Amazon S3 using standard SQL. While Amazon Athena itself does not provide a DB API 2.0 (PEP 249) compliant connection, the PyAthena library offers this functionality, building upon the boto3 library. + +This documentation covers two primary ways to interact with Amazon Athena with Airflow: + +1. API (HTTP Boto3): This method uses Amazon Athena's direct API through the boto3 library. It is the preferred method for users who wish to interact with Athena at a lower level, directly through HTTP requests. + +2. DB API Connection (Amazon Athena SQL): For users who prefer a more traditional database interaction, PyAthena implements the DB API 2.0 specification, allowing Athena to be used similarly to other relational databases through SQL. + +Choosing Your Connection Method +========================= +**Amazon Athena (API):** Choose this option if you need to execute a single statement without bringing back the results in airflow. + +**Amazon Athena SQL (DB API Connection):** Opt for this if you need to execute multiple queries in the same operator and it's essential to retrieve and process query results directly in Airflow, such as for sensing values or further data manipulation. Review Comment: The choice is just about functionality or are there things you can do with one of the options but not with the other? For example using IAM role works with both? ########## docs/apache-airflow-providers-amazon/connections/athena.rst: ########## @@ -0,0 +1,45 @@ + .. 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. + +.. _howto/connection:athena: + +Amazon Athena Connection +========================== + +The Athena connection type enables DBApi integrations with Athena. + +Authenticating to Amazon Athena +--------------------------------- + +Authentication may be performed using any of the authentication methods supported by `Amazon Web Services Connection <./aws.rst>`_. + +Default Connection IDs +---------------------- + +The default connection ID is ``athena_default``. Review Comment: Correct me if I am worng but this in fact is relevant only for athena sql does it not? For the athena API user needs to set aws conn id We need to clarify this to avoid confusion. Simply by adding a note in the top of this doc and refrence to aws connection rst file for the other case -- 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