{"action":"created","comment":{"url":"https://api.github.com/repos/apache/incubator-airflow/pulls/comments/100949549","pull_request_review_id":21665870,"id":100949549,"diff_hunk":"@@ -0,0 +1,114 @@\n+# -*- coding: utf-8 -*-\n+#\n+# Licensed under the Apache License, Version 2.0 (the \"License\");\n+# you may not use this file except in compliance with the License.\n+# You may obtain a copy of the License at\n+#\n+# http://www.apache.org/licenses/LICENSE-2.0\n+#\n+# Unless required by applicable law or agreed to in writing, software\n+# distributed under the License is distributed on an \"AS IS\" BASIS,\n+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+# See the License for the specific language governing permissions and\n+# limitations under the License.\n+\n+\n+import logging\n+import os\n+import tempfile\n+import zipfile\n+import csv\n+\n+from airflow.models import BaseOperator\n+from airflow.utils.decorators import apply_defaults\n+from airflow.hooks.base_hook import BaseHook\n+from airflow.hooks.S3_hook import S3Hook\n+\n+\n+class SqlToS3(BaseOperator):\n+    \"\"\"\n+    Moves data querying from a connection to s3 csv file\n+\n+    :param db_conn_id: source connection id\n+    :type db_conn_id: str\n+    :param sql: SQL query to execute against the source database\n+    :type sql: str\n+    :param s3_bucket: bucket name in s3\n+    :type s3_bucket: str\n+    :param s3_file_key: file key to refeer file in s3. See s3_replace_file.\n+    :type s3_file_key: str\n+    :param s3_replace_file: A flag to decide whether or not to overwrite the key\n+            if it already exists. If replace is False and the key exists, an\n+            error will be raised.\n+    :type s3_replace_file: bool\n+    :param s3_zip_file: A flag to decide if the csv file will be zipped.\n+    :type s3_zip_file: bool\n+    :param s3_conn_id: s3 connection id\n+    :type s3_conn_id: str\n+    \"\"\"\n+\n+    @apply_defaults\n+    def __init__(\n+            self,\n+            db_conn_id,\n+            sql,\n+            s3_bucket,\n+            s3_file_key,\n+            s3_conn_id,\n+            s3_replace_file=False,\n+            s3_zip_file=False,\n+            *args, **kwargs):\n+\n+        super(SqlToS3, self).__init__(*args, **kwargs)\n+        self.db_conn_id=db_conn_id\n+        self.sql=sql\n+        self.s3_bucket=s3_bucket\n+        self.s3_file_key=s3_file_key\n+        self.s3_conn_id=s3_conn_id\n+        self.s3_replace_file=s3_replace_file\n+        self.s3_zip_file=s3_zip_file\n+        self.source_hook=self.get_source_hook()\n+        self.s3_hook=self.get_s3_hook()\n+\n+    def execute(self, context):\n+        \"\"\"\n+        Creates files into a temporary directory\n+        which will be cleaned afterwards\n+        \"\"\"\n+        logging.info(\"Extracting data from {}\".format(self.db_conn_id))\n+        logging.info(\"Executing: \\n\" + self.sql)\n+        cursor =self.source_hook.get_conn().cursor()\n+        cursor.execute(self.sql)\n+\n+        tmpdir = tempfile.mkdtemp()\n+        filename = self.s3_file_key + '.csv'","path":"airflow/contrib/operators/sql_to_s3.py","position":84,"original_position":84,"commit_id":"c30c413860948adb23fb5c67c00da228cbabf771","original_commit_id":"c30c413860948adb23fb5c67c00da228cbabf771","user":{"login":"krishnabhupatiraju","id":11150833,"avatar_url":"https://avatars.githubusercontent.com/u/11150833?v=3","gravatar_id":"","url":"https://api.github.com/users/krishnabhupatiraju","html_url":"https://github.com/krishnabhupatiraju","followers_url":"https://api.github.com/users/krishnabhupatiraju/followers","following_url":"https://api.github.com/users/krishnabhupatiraju/following{/other_user}","gists_url":"https://api.github.com/users/krishnabhupatiraju/gists{/gist_id}","starred_url":"https://api.github.com/users/krishnabhupatiraju/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krishnabhupatiraju/subscriptions","organizations_url":"https://api.github.com/users/krishnabhupatiraju/orgs","repos_url":"https://api.github.com/users/krishnabhupatiraju/repos","events_url":"https://api.github.com/users/krishnabhupatiraju/events{/privacy}","received_events_url":"https://api.github.com/users/krishnabhupatiraju/received_events","type":"User","site_admin":false},"body":"leave it to the user to specify the correct file name. As a basic check, if the zip option is enabled throw an exception if the input s3_file_key  extension doesnt end in .zip","created_at":"2017-02-14T02:36:51Z","updated_at":"2017-02-14T02:37:35Z","html_url":"https://github.com/apache/incubator-airflow/pull/2040#discussion_r100949549","pull_request_url":"https://api.github.com/repos/apache/incubator-airflow/pulls/2040","_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-airflow/pulls/comments/100949549"},"html":{"href":"https://github.com/apache/incubator-airflow/pull/2040#discussion_r100949549"},"pull_request":{"href":"https://api.github.com/repos/apache/incubator-airflow/pulls/2040"}}},"pull_request":{"url":"https://api.github.com/repos/apache/incubator-airflow/pulls/2040","id":103934420,"html_url":"https://github.com/apache/incubator-airflow/pull/2040","diff_url":"https://github.com/apache/incubator-airflow/pull/2040.diff","patch_url":"https://github.com/apache/incubator-airflow/pull/2040.patch","issue_url":"https://api.github.com/repos/apache/incubator-airflow/issues/2040","number":2040,"state":"open","locked":false,"title":"[AIRFLOW-808] - SqlToS3 Operator","user":{"login":"abnerrolim","id":683925,"avatar_url":"https://avatars.githubusercontent.com/u/683925?v=3","gravatar_id":"","url":"https://api.github.com/users/abnerrolim","html_url":"https://github.com/abnerrolim","followers_url":"https://api.github.com/users/abnerrolim/followers","following_url":"https://api.github.com/users/abnerrolim/following{/other_user}","gists_url":"https://api.github.com/users/abnerrolim/gists{/gist_id}","starred_url":"https://api.github.com/users/abnerrolim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abnerrolim/subscriptions","organizations_url":"https://api.github.com/users/abnerrolim/orgs","repos_url":"https://api.github.com/users/abnerrolim/repos","events_url":"https://api.github.com/users/abnerrolim/events{/privacy}","received_events_url":"https://api.github.com/users/abnerrolim/received_events","type":"User","site_admin":false},"body":"Dear Airflow Maintainers,\r\n\r\nPlease accept this PR that addresses the following issues:\r\n- *https://issues.apache.org/jira/browse/AIRFLOW-808*\r\n\r\nTesting Done:\r\n- Unit tests (constructor and execute methods): test_sql_to_s3\r\n- Travis CI ok (https://travis-ci.org/abnerrolim/incubator-airflow)\r\n- Usage test in production\r\n\r\n","created_at":"2017-01-31T13:22:21Z","updated_at":"2017-02-14T02:37:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b0ba3f443d9374873f9985201cc9f6a59f09f875","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/incubator-airflow/pulls/2040/commits","review_comments_url":"https://api.github.com/repos/apache/incubator-airflow/pulls/2040/comments","review_comment_url":"https://api.github.com/repos/apache/incubator-airflow/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/incubator-airflow/issues/2040/comments","statuses_url":"https://api.github.com/repos/apache/incubator-airflow/statuses/c30c413860948adb23fb5c67c00da228cbabf771","head":{"label":"abnerrolim:AIRFLOW-808","ref":"AIRFLOW-808","sha":"c30c413860948adb23fb5c67c00da228cbabf771","user":{"login":"abnerrolim","id":683925,"avatar_url":"https://avatars.githubusercontent.com/u/683925?v=3","gravatar_id":"","url":"https://api.github.com/users/abnerrolim","html_url":"https://github.com/abnerrolim","followers_url":"https://api.github.com/users/abnerrolim/followers","following_url":"https://api.github.com/users/abnerrolim/following{/other_user}","gists_url":"https://api.github.com/users/abnerrolim/gists{/gist_id}","starred_url":"https://api.github.com/users/abnerrolim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abnerrolim/subscriptions","organizations_url":"https://api.github.com/users/abnerrolim/orgs","repos_url":"https://api.github.com/users/abnerrolim/repos","events_url":"https://api.github.com/users/abnerrolim/events{/privacy}","received_events_url":"https://api.github.com/users/abnerrolim/received_events","type":"User","site_admin":false},"repo":{"id":80055555,"name":"incubator-airflow","full_name":"abnerrolim/incubator-airflow","owner":{"login":"abnerrolim","id":683925,"avatar_url":"https://avatars.githubusercontent.com/u/683925?v=3","gravatar_id":"","url":"https://api.github.com/users/abnerrolim","html_url":"https://github.com/abnerrolim","followers_url":"https://api.github.com/users/abnerrolim/followers","following_url":"https://api.github.com/users/abnerrolim/following{/other_user}","gists_url":"https://api.github.com/users/abnerrolim/gists{/gist_id}","starred_url":"https://api.github.com/users/abnerrolim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abnerrolim/subscriptions","organizations_url":"https://api.github.com/users/abnerrolim/orgs","repos_url":"https://api.github.com/users/abnerrolim/repos","events_url":"https://api.github.com/users/abnerrolim/events{/privacy}","received_events_url":"https://api.github.com/users/abnerrolim/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/abnerrolim/incubator-airflow","description":"Apache Airflow (Incubating)","fork":true,"url":"https://api.github.com/repos/abnerrolim/incubator-airflow","forks_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/forks","keys_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/keys{/key_id}","collaborators_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/teams","hooks_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/hooks","issue_events_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/issues/events{/number}","events_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/events","assignees_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/assignees{/user}","branches_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/branches{/branch}","tags_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/tags","blobs_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/git/refs{/sha}","trees_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/git/trees{/sha}","statuses_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/statuses/{sha}","languages_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/languages","stargazers_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/stargazers","contributors_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/contributors","subscribers_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/subscribers","subscription_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/subscription","commits_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/commits{/sha}","git_commits_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/git/commits{/sha}","comments_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/comments{/number}","issue_comment_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/issues/comments{/number}","contents_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/contents/{+path}","compare_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/compare/{base}...{head}","merges_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/merges","archive_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/downloads","issues_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/issues{/number}","pulls_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/pulls{/number}","milestones_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/milestones{/number}","notifications_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/labels{/name}","releases_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/releases{/id}","deployments_url":"https://api.github.com/repos/abnerrolim/incubator-airflow/deployments","created_at":"2017-01-25T20:38:09Z","updated_at":"2017-01-25T20:38:13Z","pushed_at":"2017-01-30T21:09:04Z","git_url":"git://github.com/abnerrolim/incubator-airflow.git","ssh_url":"git@github.com:abnerrolim/incubator-airflow.git","clone_url":"https://github.com/abnerrolim/incubator-airflow.git","svn_url":"https://github.com/abnerrolim/incubator-airflow","homepage":"","size":11360,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"a67e4390d2217dd0fdc3429e943cdc6c552fac73","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":33884891,"name":"incubator-airflow","full_name":"apache/incubator-airflow","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/incubator-airflow","description":"Apache Airflow (Incubating)","fork":false,"url":"https://api.github.com/repos/apache/incubator-airflow","forks_url":"https://api.github.com/repos/apache/incubator-airflow/forks","keys_url":"https://api.github.com/repos/apache/incubator-airflow/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/incubator-airflow/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/incubator-airflow/teams","hooks_url":"https://api.github.com/repos/apache/incubator-airflow/hooks","issue_events_url":"https://api.github.com/repos/apache/incubator-airflow/issues/events{/number}","events_url":"https://api.github.com/repos/apache/incubator-airflow/events","assignees_url":"https://api.github.com/repos/apache/incubator-airflow/assignees{/user}","branches_url":"https://api.github.com/repos/apache/incubator-airflow/branches{/branch}","tags_url":"https://api.github.com/repos/apache/incubator-airflow/tags","blobs_url":"https://api.github.com/repos/apache/incubator-airflow/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/incubator-airflow/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/incubator-airflow/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/incubator-airflow/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/incubator-airflow/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/incubator-airflow/languages","stargazers_url":"https://api.github.com/repos/apache/incubator-airflow/stargazers","contributors_url":"https://api.github.com/repos/apache/incubator-airflow/contributors","subscribers_url":"https://api.github.com/repos/apache/incubator-airflow/subscribers","subscription_url":"https://api.github.com/repos/apache/incubator-airflow/subscription","commits_url":"https://api.github.com/repos/apache/incubator-airflow/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/incubator-airflow/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/incubator-airflow/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/incubator-airflow/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/incubator-airflow/contents/{+path}","compare_url":"https://api.github.com/repos/apache/incubator-airflow/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/incubator-airflow/merges","archive_url":"https://api.github.com/repos/apache/incubator-airflow/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/incubator-airflow/downloads","issues_url":"https://api.github.com/repos/apache/incubator-airflow/issues{/number}","pulls_url":"https://api.github.com/repos/apache/incubator-airflow/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/incubator-airflow/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/incubator-airflow/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/incubator-airflow/labels{/name}","releases_url":"https://api.github.com/repos/apache/incubator-airflow/releases{/id}","deployments_url":"https://api.github.com/repos/apache/incubator-airflow/deployments","created_at":"2015-04-13T18:04:58Z","updated_at":"2017-02-14T00:52:44Z","pushed_at":"2017-02-14T02:23:12Z","git_url":"git://github.com/apache/incubator-airflow.git","ssh_url":"git@github.com:apache/incubator-airflow.git","clone_url":"https://github.com/apache/incubator-airflow.git","svn_url":"https://github.com/apache/incubator-airflow","homepage":"","size":11506,"stargazers_count":4283,"watchers_count":4283,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1114,"mirror_url":null,"open_issues_count":186,"forks":1114,"open_issues":186,"watchers":4283,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-airflow/pulls/2040"},"html":{"href":"https://github.com/apache/incubator-airflow/pull/2040"},"issue":{"href":"https://api.github.com/repos/apache/incubator-airflow/issues/2040"},"comments":{"href":"https://api.github.com/repos/apache/incubator-airflow/issues/2040/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/incubator-airflow/pulls/2040/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/incubator-airflow/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/incubator-airflow/pulls/2040/commits"},"statuses":{"href":"https://api.github.com/repos/apache/incubator-airflow/statuses/c30c413860948adb23fb5c67c00da228cbabf771"}}}}
{"actor":{"display_login":"krishnabhupatiraju"}}