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 2020/03/14 13:29:57 UTC

[GitHub] [airflow] mik-laj commented on a change in pull request #7718: [AIRFLOW-5421] Add Presto to GCS transfer operator

mik-laj commented on a change in pull request #7718: [AIRFLOW-5421] Add Presto to GCS transfer operator
URL: https://github.com/apache/airflow/pull/7718#discussion_r392588497
 
 

 ##########
 File path: airflow/providers/google/cloud/example_dags/example_presto_to_gcs.py
 ##########
 @@ -0,0 +1,152 @@
+#
+# 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.
+"""
+Example DAG using PrestoToGCSOperator.
+"""
+import os
+import re
+
+from airflow import models
+from airflow.providers.google.cloud.operators.bigquery import (
+    BigQueryCreateEmptyDatasetOperator,
+    BigQueryCreateExternalTableOperator,
+    BigQueryDeleteDatasetOperator,
+    BigQueryExecuteQueryOperator,
+)
+from airflow.providers.google.cloud.operators.presto_to_gcs import PrestoToGCSOperator
+from airflow.utils.dates import days_ago
+
+GCP_PROJECT_ID = os.environ["GCP_PROJECT_ID"]
+GCS_BUCKET = os.environ.get("GCP_PRESTO_TO_GCS_BUCKET_NAME", "test-presto-to-gcs-bucket")
+DATASET_NAME = os.environ.get("GCP_PRESTO_TO_GCS_DATASET_NAME", "test_presto_to_gcs_dataset")
+
+SOURCE_MULTIPLE_TYPES = "memory.default.test_multiple_types"
+SOURCE_CUSTOMER_TABLE = "tpch.sf1.customer"
+
+
+def safe_name(s: str) -> str:
+    """
+    Remove invalid characters for filename
+    """
+    return re.sub("[^0-9a-zA-Z_]+", "_", s)
+
+
+default_args = {"start_date": days_ago(1)}
+
+with models.DAG(
+    dag_id=f"example_presto_to_gcs",
+    default_args=default_args,
+    schedule_interval=None,  # Override to match your needs
+    tags=["example"],
+) as dag:
+
+    create_dataset = BigQueryCreateEmptyDatasetOperator(task_id="create-dataset", dataset_id=DATASET_NAME)
+
+    delete_dataset = BigQueryDeleteDatasetOperator(
+        task_id="delete_dataset", dataset_id=DATASET_NAME, delete_contents=True
+    )
+
+    # [START howto_operator_presto_to_gcs_basic]
+    presto_to_gcs_basic = PrestoToGCSOperator(
 
 Review comment:
   I tried to make the example as simple as possible. This example is tested using system tests, so I'm sure it works fine.

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