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


##########
airflow/providers/amazon/aws/hooks/athena_sql.py:
##########
@@ -0,0 +1,110 @@
+# 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 import create_engine
+
+from airflow.exceptions import AirflowException
+from airflow.providers.common.sql.hooks.sql import DbApiHook
+
+if TYPE_CHECKING:
+    from pyathena.connection import Connection as AthenaConnection
+
+
+class AthenaSQLHook(DbApiHook):
+    """Execute statements against Amazon Athena.
+
+    .. note::
+    get_sqlalchemy_engine() and get_uri() depends on SQLAlchemy and PyAthena.
+    """
+
+    conn_name_attr = "athena_conn_id"
+    default_conn_name = "athena_default"
+    conn_type = "athena"
+    hook_name = "Amazon Athena"
+    supports_autocommit = True
+
+    def __init__(self, *args, athena_conn_id: str = "athena_default", 
**kwargs) -> None:
+        super().__init__(*args, **kwargs)
+        self.athena_conn_id = athena_conn_id
+
+    @cached_property
+    def conn(self):
+        return self.get_connection(self.athena_conn_id)  # type: 
ignore[attr-defined]
+
+    def _get_conn_params(self) -> dict[str, str | int | None]:
+        """Retrieve connection parameters."""
+        conn = self.conn
+
+        conn_params: dict[str, str | int | None] = {}
+
+        conn_params["aws_access_key_id"] = conn.login if conn.login else None
+
+        conn_params["aws_secret_access_key"] = conn.password if conn.password 
else None
+
+        conn_params["schema_name"] = conn.schema if conn.schema else "default"
+
+        conn_params["region_name"] = conn.extra_dejson.get("region_name", 
"us-east-1")

Review Comment:
   
   
   ```suggestion
   conn_params: dict[str, str | int | None] = {
       "aws_access_key_id": conn.login if conn.login else None,
       "aws_secret_access_key": conn.password if conn.password else None,
       "schema_name": conn.schema if conn.schema else "default",
       "region_name": conn.extra_dejson.get("region_name", "us-east-1"),
   }
   ```



##########
airflow/providers/amazon/aws/hooks/athena_sql.py:
##########
@@ -0,0 +1,110 @@
+# 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 import create_engine
+
+from airflow.exceptions import AirflowException
+from airflow.providers.common.sql.hooks.sql import DbApiHook
+
+if TYPE_CHECKING:
+    from pyathena.connection import Connection as AthenaConnection
+
+
+class AthenaSQLHook(DbApiHook):
+    """Execute statements against Amazon Athena.
+
+    .. note::
+    get_sqlalchemy_engine() and get_uri() depends on SQLAlchemy and PyAthena.
+    """
+
+    conn_name_attr = "athena_conn_id"
+    default_conn_name = "athena_default"
+    conn_type = "athena"
+    hook_name = "Amazon Athena"
+    supports_autocommit = True
+
+    def __init__(self, *args, athena_conn_id: str = "athena_default", 
**kwargs) -> None:
+        super().__init__(*args, **kwargs)
+        self.athena_conn_id = athena_conn_id
+
+    @cached_property
+    def conn(self):
+        return self.get_connection(self.athena_conn_id)  # type: 
ignore[attr-defined]
+
+    def _get_conn_params(self) -> dict[str, str | int | None]:
+        """Retrieve connection parameters."""
+        conn = self.conn
+
+        conn_params: dict[str, str | int | None] = {}
+
+        conn_params["aws_access_key_id"] = conn.login if conn.login else None
+
+        conn_params["aws_secret_access_key"] = conn.password if conn.password 
else None
+
+        conn_params["schema_name"] = conn.schema if conn.schema else "default"
+
+        conn_params["region_name"] = conn.extra_dejson.get("region_name", 
"us-east-1")
+
+        s3_staging_dir = conn.extra_dejson.get("s3_staging_dir", None)
+        if not s3_staging_dir:
+            raise AirflowException(
+                "S3 Staging directory (s3_staging_dir) must be specified in 
the extra field"
+            )
+        conn_params["s3_staging_dir"] = s3_staging_dir

Review Comment:
   You can move this whole section (from line 67) before initialization of 
`conn_params` so that you can define the key `s3_staging_dir` when initializing 
 `conn_params`



##########
airflow/providers/amazon/aws/hooks/athena_sql.py:
##########
@@ -0,0 +1,110 @@
+# 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 import create_engine
+
+from airflow.exceptions import AirflowException
+from airflow.providers.common.sql.hooks.sql import DbApiHook
+
+if TYPE_CHECKING:
+    from pyathena.connection import Connection as AthenaConnection
+
+
+class AthenaSQLHook(DbApiHook):
+    """Execute statements against Amazon Athena.
+
+    .. note::
+    get_sqlalchemy_engine() and get_uri() depends on SQLAlchemy and PyAthena.
+    """
+
+    conn_name_attr = "athena_conn_id"
+    default_conn_name = "athena_default"
+    conn_type = "athena"
+    hook_name = "Amazon Athena"
+    supports_autocommit = True
+
+    def __init__(self, *args, athena_conn_id: str = "athena_default", 
**kwargs) -> None:
+        super().__init__(*args, **kwargs)
+        self.athena_conn_id = athena_conn_id
+
+    @cached_property
+    def conn(self):
+        return self.get_connection(self.athena_conn_id)  # type: 
ignore[attr-defined]
+
+    def _get_conn_params(self) -> dict[str, str | int | None]:
+        """Retrieve connection parameters."""
+        conn = self.conn
+
+        conn_params: dict[str, str | int | None] = {}
+
+        conn_params["aws_access_key_id"] = conn.login if conn.login else None
+
+        conn_params["aws_secret_access_key"] = conn.password if conn.password 
else None
+
+        conn_params["schema_name"] = conn.schema if conn.schema else "default"
+
+        conn_params["region_name"] = conn.extra_dejson.get("region_name", 
"us-east-1")
+
+        s3_staging_dir = conn.extra_dejson.get("s3_staging_dir", None)
+        if not s3_staging_dir:
+            raise AirflowException(
+                "S3 Staging directory (s3_staging_dir) must be specified in 
the extra field"

Review Comment:
   ```suggestion
                   "S3 Staging directory (`s3_staging_dir`) must be specified 
in the extra field"
   ```



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