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 2018/08/20 20:57:52 UTC

[GitHub] feng-tao closed pull request #3763: [AIRFLOW-2915] Add example DAG for GoogleCloudStorageToBigQueryOperator

feng-tao closed pull request #3763: [AIRFLOW-2915] Add example DAG for GoogleCloudStorageToBigQueryOperator
URL: https://github.com/apache/incubator-airflow/pull/3763
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/airflow/contrib/example_dags/example_gcs_to_bq_operator.py b/airflow/contrib/example_dags/example_gcs_to_bq_operator.py
new file mode 100644
index 0000000000..ee9fe09391
--- /dev/null
+++ b/airflow/contrib/example_dags/example_gcs_to_bq_operator.py
@@ -0,0 +1,63 @@
+# -*- 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 airflow
+try:
+    from airflow.contrib.operators import gcs_to_bq
+except ImportError:
+    gcs_to_bq = None
+from airflow import models
+from airflow.operators import bash_operator
+
+
+if gcs_to_bq is not None:
+    args = {
+        'owner': 'airflow',
+        'start_date': airflow.utils.dates.days_ago(2)
+    }
+
+    dag = models.DAG(
+        dag_id='example_gcs_to_bq_operator', default_args=args,
+        schedule_interval=None)
+
+    create_test_dataset = bash_operator.BashOperator(
+        task_id='create_airflow_test_dataset',
+        bash_command='bq mk airflow_test',
+        dag=dag)
+
+    # [START howto_operator_gcs_to_bq]
+    load_csv = gcs_to_bq.GoogleCloudStorageToBigQueryOperator(
+        task_id='gcs_to_bq_example',
+        bucket='cloud-samples-data',
+        source_objects=['bigquery/us-states/us-states.csv'],
+        destination_project_dataset_table='airflow_test.gcs_to_bq_table',
+        schema_fields=[
+            {'name': 'name', 'type': 'STRING', 'mode': 'NULLABLE'},
+            {'name': 'post_abbr', 'type': 'STRING', 'mode': 'NULLABLE'},
+        ],
+        write_disposition='WRITE_TRUNCATE',
+        dag=dag)
+    # [END howto_operator_gcs_to_bq]
+
+    delete_test_dataset = bash_operator.BashOperator(
+        task_id='delete_airflow_test_dataset',
+        bash_command='bq rm -rf airflow_test',
+        dag=dag)
+
+    create_test_dataset >> load_csv >> delete_test_dataset
diff --git a/docs/howto/operator.rst b/docs/howto/operator.rst
index 243e06febe..efd544efed 100644
--- a/docs/howto/operator.rst
+++ b/docs/howto/operator.rst
@@ -85,3 +85,19 @@ template variables <macros>` and a ``templates_dict`` argument.
 
 The ``templates_dict`` argument is templated, so each value in the dictionary
 is evaluated as a :ref:`Jinja template <jinja-templating>`.
+
+Google Cloud Platform Operators
+-------------------------------
+
+GoogleCloudStorageToBigQueryOperator
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Use the
+:class:`~airflow.contrib.operators.gcs_to_bq.GoogleCloudStorageToBigQueryOperator`
+to execute a BigQuery load job.
+
+.. literalinclude:: ../../airflow/contrib/example_dags/example_gcs_to_bq_operator.py
+    :language: python
+    :dedent: 4
+    :start-after: [START howto_operator_gcs_to_bq]
+    :end-before: [END howto_operator_gcs_to_bq]


 

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