Skip to content

Commit

Permalink
Migrate Google example sql_to_sheets to new design AIP-47 (#24814)
Browse files Browse the repository at this point in the history
related: #22447, #22430
  • Loading branch information
chenglongyan committed Jul 6, 2022
1 parent 2c4fd05 commit 80b6754
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
Expand Up @@ -35,7 +35,7 @@ Upload data from SQL to Google Sheets
To upload data from and Database using SQL to Google Spreadsheet you can use the
:class:`~airflow.providers.google.suite.transfers.sql_to_sheets.SQLToGoogleSheetsOperator`.

.. exampleinclude:: /../../airflow/providers/google/suite/example_dags/example_sql_to_sheets.py
.. exampleinclude:: /../../tests/system/providers/google/cloud/sql_to_sheets/example_sql_to_sheets.py
:language: python
:dedent: 4
:start-after: [START upload_sql_to_sheets]
Expand Down
16 changes: 16 additions & 0 deletions tests/system/providers/google/cloud/sql_to_sheets/__init__.py
@@ -0,0 +1,16 @@
# 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.
Expand Up @@ -15,23 +15,25 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

import os
from datetime import datetime

from airflow import models
from airflow.providers.google.suite.transfers.sql_to_sheets import SQLToGoogleSheetsOperator

ENV_ID = os.environ.get("SYSTEM_TESTS_ENV_ID")
DAG_ID = "example_sql_to_sheets"

SQL = "select 1 as my_col"
NEW_SPREADSHEET_ID = "123"
NEW_SPREADSHEET_ID = os.environ.get("NEW_SPREADSHEET_ID", "123")

with models.DAG(
"example_sql_to_sheets",
DAG_ID,
start_date=datetime(2021, 1, 1),
schedule_interval=None, # Override to match your needs
schedule_interval='@once', # Override to match your needs
catchup=False,
tags=["example"],
tags=["example", "sql"],
) as dag:

# [START upload_sql_to_sheets]
upload_gcs_to_sheet = SQLToGoogleSheetsOperator(
task_id="upload_sql_to_sheet",
Expand All @@ -40,3 +42,9 @@
spreadsheet_id=NEW_SPREADSHEET_ID,
)
# [END upload_sql_to_sheets]


from tests.system.utils import get_test_run # noqa: E402

# Needed to run the example DAG with pytest (see: tests/system/README.md#run_via_pytest)
test_run = get_test_run(dag)

0 comments on commit 80b6754

Please sign in to comment.