airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] phani8996 commented on a change in pull request #4111: [AIRFLOW-3266] Add AWS Athena Operator and hook
Date Tue, 30 Oct 2018 08:20:58 GMT
phani8996 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_r229209605
 
 

 ##########
 File path: airflow/contrib/operators/aws_athena_operator.py
 ##########
 @@ -0,0 +1,69 @@
+# -*- 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 airflow.models import BaseOperator
+from airflow.utils.decorators import apply_defaults
+from airflow.contrib.hooks.aws_athena_hook import AWSAthenaHook
+
+
+class AWSAthenaOperator(BaseOperator):
+
+    ui_color = '#44b5e2'
+    template_fields = ('query', 'database', 'output_location')
+
+    @apply_defaults
+    def __init__(self, query, database, output_location, aws_conn_id='aws_default', *args,
**kwargs):
+        super(AWSAthenaOperator, self).__init__(*args, **kwargs)
+        self.query = query
+        self.database = database
+        self.output_location = output_location
+        self.aws_conn_id = aws_conn_id
+        self.client_request_token = kwargs.get('client_request_token')
+        self.query_execution_context = kwargs.get('query_execution_context') or {}
+        self.result_configuration = kwargs.get('result_configuration') or {}
+        self.query_execution_context['Database'] = self.database
+        self.result_configuration['OutputLocation'] = self.output_location
+        self.query_execution_id = None
+        self.hook = self.get_hook(*args, **kwargs)
+
+    def get_hook(self, *args, **kwargs):
+        return AWSAthenaHook(self.aws_conn_id, *args, **kwargs)
+
+    def execute(self, context):
+        self.query_execution_id = self.hook.run_query(self.query, self.query_execution_context,
+                                                      self.result_configuration, self.client_request_token)
+
+    def post_execute(self, context, result=None):
+        self.hook.poll_query_status(self.query_execution_id)
+
+    def on_kill(self):
+        self.log.info('⚰️⚰️⚰️ Received a kill Signal. Time to Die.️')
 
 Review comment:
   This will be rendered as it is since our logging supports unicode. Please see attached
screenshot of above log 
   
   ![img-20181030-wa0000](https://user-images.githubusercontent.com/12140904/47704786-cc6a2880-dc4a-11e8-96e0-30027db92f45.jpg)
   
   
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message