XD-DENG commented on a change in pull request #4111: [AIRFLOW-3266] Add AWS Athena Operator and hook URL: https://github.com/apache/incubator-airflow/pull/4111#discussion_r229559111
########## File path: airflow/contrib/hooks/aws_athena_hook.py ########## @@ -0,0 +1,140 @@ +# -*- coding: utf-8 -*- +# +# 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 time import sleep +from airflow.contrib.hooks.aws_hook import AwsHook +from uuid import uuid4 + +INTERMEDIATE_STATES = ('QUEUED', 'RUNNING',) +FAILURE_STATES = ('FAILED', 'CANCELLED',) +SUCCESS_STATES = ('SUCCEEDED',) + + +class AWSAthenaHook(AwsHook): + """ + Interact with AWS Athena to run, poll queries and return query results + """ + + def __init__(self, aws_conn_id='aws_default', *args, **kwargs): + super(AWSAthenaHook, self).__init__(aws_conn_id, **kwargs) + self.sleep_time = kwargs.get('sleep_time') or 30 + self.conn = None + + def get_conn(self): + """ + check if aws conn exists already or create one and return it + :return: boto3 session + """ + if not hasattr(self, 'conn'): + self.conn = self.get_client_type('athena') + return self.conn + + def run_query(self, query, query_context, result_configuration, client_request_token=None): + """ + Run Presto query on athena with provided config and return submitted query_execution_id + :param query: Presto query to run Review comment: Minor stuff: there should be an empty line after line 50, otherwise the docstring can't be parsed properly by Sphinx. Also applicable for line 72, 86, 103, 135 ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
