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/08/06 09:44:35 UTC

[GitHub] [airflow] adussarps commented on a change in pull request #5711: [AIRFLOW-4161] BigQuery to Mysql Operator

adussarps commented on a change in pull request #5711: [AIRFLOW-4161] BigQuery to Mysql Operator
URL: https://github.com/apache/airflow/pull/5711#discussion_r310974554
 
 

 ##########
 File path: airflow/contrib/operators/bigquery_to_mysql_operator.py
 ##########
 @@ -0,0 +1,143 @@
+# -*- 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.
+"""
+This module contains a Google BigQuery to MySQL operator.
+"""
+
+from airflow.contrib.hooks.bigquery_hook import BigQueryHook
+from airflow.models import BaseOperator
+from airflow.utils.decorators import apply_defaults
+from airflow.hooks.mysql_hook import MySqlHook
+
+
+class BigQueryToMySqlOperator(BaseOperator):
+    """
+    Fetches the data from a BigQuery table (alternatively fetch data for selected columns)
+    and insert that data into a MySQL table.
+
+
+    .. note::
+        If you pass fields to ``selected_fields`` which are in different order than the
+        order of columns already in
+        BQ table, the data will still be in the order of BQ table.
+        For example if the BQ table has 3 columns as
+        ``[A,B,C]`` and you pass 'B,A' in the ``selected_fields``
+        the data would still be of the form ``'A,B'`` and passed through this form
+        to MySQL
+
+    **Example**: ::
+
+       transfer_data = BigQueryToMySqlOperator(
+            task_id='task_id',
+            dataset_id='dataset_id',
+            table_id='table_name',
+            mysql_table='dest_table_name',
+            replace=True,
+        )
+
+    :param dataset_id: The dataset ID of the requested table. (templated)
+    :type dataset_id: string
+    :param table_id: The table ID of the requested table. (templated)
+    :type table_id: string
+    :param max_results: The maximum number of records (rows) to be fetched
+        from the table. (templated)
+    :type max_results: string
+    :param selected_fields: List of fields to return (comma-separated). If
+        unspecified, all fields are returned.
+    :type selected_fields: string
+    :param bigquery_conn_id: reference to a specific BigQuery hook.
+    :type bigquery_conn_id: string
+    :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.
+    :type delegate_to: string
+    :param mysql_conn_id: reference to a specific mysql hook
+    :type mysql_conn_id: string
+    :param database: name of database which overwrite defined one in connection
+    :type database: string
+    :param replace: Whether to replace instead of insert
+    :type replace: bool
+    """
+    template_fields = ('dataset_id', 'table_id', 'mysql_table')
+
+    @apply_defaults
+    def __init__(self,
+                 dataset_id,
+                 table_id,
+                 mysql_table,
+                 selected_fields=None,
+                 bigquery_conn_id='bigquery_default',
+                 mysql_conn_id='mysql_default',
 
 Review comment:
   Thanks for the input, this is fixed!

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