You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2019/04/11 09:28:42 UTC

[GitHub] [airflow] Tomme commented on a change in pull request #5077: [AIRFLOW-4268] Add MsSqlToGoogleCloudStorageOperator

Tomme commented on a change in pull request #5077: [AIRFLOW-4268] Add MsSqlToGoogleCloudStorageOperator
URL: https://github.com/apache/airflow/pull/5077#discussion_r274336208
 
 

 ##########
 File path: airflow/contrib/operators/mssql_to_gcs.py
 ##########
 @@ -0,0 +1,224 @@
+# -*- 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.
+
+import sys
+import json
+import decimal
+
+from airflow.models import BaseOperator
+from airflow.utils.decorators import apply_defaults
+from airflow.contrib.hooks.gcs_hook import GoogleCloudStorageHook
+from airflow.hooks.mssql_hook import MsSqlHook
+from tempfile import NamedTemporaryFile
+
+PY3 = sys.version_info[0] == 3
+
+
+class DecimalEncoder(json.JSONEncoder):
+    def default(self, o):
+        if isinstance(o, decimal.Decimal):
+            return float(o)
+        return super(DecimalEncoder, self).default(o)
+
+
+class MsSqlToGoogleCloudStorageOperator(BaseOperator):
+    """
+    Copy data from Microsoft SQL Server to Google Cloud Storage
+    in JSON format.
+    """
+    template_fields = ('sql', 'bucket', 'filename', 'schema_filename')
+    template_ext = ('.sql',)
+
+    ui_color = '#e0a98c'
+
+    @apply_defaults
+    def __init__(self,
+                 sql,
+                 bucket,
+                 filename,
+                 schema_filename=None,
+                 approx_max_file_size_bytes=1900000000,
+                 mssql_conn_id='mssql_default',
+                 google_cloud_storage_conn_id='google_cloud_default',
+                 delegate_to=None,
+                 *args,
+                 **kwargs):
+        """
+        :param sql: The SQL to execute on the MSSQL table.
+        :type sql: str
+        :param bucket: The bucket to upload to.
+        :type bucket: str
+        :param filename: The filename to use as the object name when uploading
+            to Google Cloud Storage. A {} should be specified in the filename
+            to allow the operator to inject file numbers in cases where the
+            file is split due to size.
+        :type filename: str
+        :param schema_filename: If set, the filename to use as the object name
+            when uploading a .json file containing the BigQuery schema fields
+            for the table that was dumped from MSSQL.
+        :type schema_filename: str
+        :param approx_max_file_size_bytes: This operator supports the ability
+            to split large table dumps into multiple files. Google Cloud Storage
+            allows for files to be a maximum of 4GB. This param allows
+            developers to specify the file size of the splits.
+        :type approx_max_file_size_bytes: long
+        :param mssql_conn_id: Reference to a specific MSSQL hook.
+        :type mssql_conn_id: str
+        :param google_cloud_storage_conn_id: Reference to a specific Google
+            cloud storage hook.
+        :type google_cloud_storage_conn_id: str
+        :param delegate_to: The account to impersonate, if any. For this to
+            work, the service account making the request must have domain-wide
+            delegation enabled.
 
 Review comment:
   Resolved with [797c4e1](https://github.com/apache/airflow/pull/5077/commits/797c4e11c0c4eab873ed8e3a4843646665d6b407).

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services