-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added example DAG for MSSQL to Google Cloud Storage (GCS) (#19873)
- Loading branch information
Showing
5 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
airflow/providers/google/cloud/example_dags/example_mssql_to_gcs.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# 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 os | ||
from datetime import datetime | ||
|
||
from airflow import models | ||
from airflow.providers.google.cloud.transfers.mssql_to_gcs import MSSQLToGCSOperator | ||
|
||
GCS_BUCKET = os.environ.get("GCP_GCS_BUCKET", "example-airflow") | ||
FILENAME = 'test_file' | ||
|
||
SQL_QUERY = "USE airflow SELECT * FROM Country;" | ||
|
||
with models.DAG( | ||
'example_mssql_to_gcs', | ||
schedule_interval='@once', | ||
start_date=datetime(2021, 12, 1), | ||
catchup=False, | ||
tags=['example'], | ||
) as dag: | ||
# [START howto_operator_mssql_to_gcs] | ||
upload = MSSQLToGCSOperator( | ||
task_id='mssql_to_gcs', | ||
mssql_conn_id='airflow_mssql', | ||
sql=SQL_QUERY, | ||
bucket=GCS_BUCKET, | ||
filename=FILENAME, | ||
export_format='csv', | ||
) | ||
# [END howto_operator_mssql_to_gcs] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
docs/apache-airflow-providers-google/operators/transfer/mssql_to_gcs.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
.. 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. | ||
Microsoft SQL Server To Google Cloud Storage Operator | ||
===================================================== | ||
The `Google Cloud Storage <https://cloud.google.com/storage/>`__ (GCS) service is | ||
used to store large data from various applications. This page shows how to copy | ||
data from Microsoft SQL Server to GCS. | ||
|
||
Prerequisite Tasks | ||
^^^^^^^^^^^^^^^^^^ | ||
|
||
.. include::/howto/operator/google/_partials/prerequisite_tasks.rst | ||
.. _howto/operator:MSSQLToGCSOperator: | ||
|
||
MSSQLToGCSOperator | ||
~~~~~~~~~~~~~~~~~~ | ||
|
||
:class:`~airflow.providers.google.cloud.transfers.mssql_to_gcs.MSSQLToGCSOperator` allows you to upload | ||
data from Microsoft SQL Server database to GCS. | ||
|
||
Below is an example of using this operator to upload data to GCS. | ||
|
||
.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_mssql_to_gcs.py | ||
:language: python | ||
:start-after: [START howto_operator_mssql_to_gcs] | ||
:end-before: [END howto_operator_mssql_to_gcs] | ||
|
||
|
||
Reference | ||
--------- | ||
|
||
For further information, look at: | ||
* `Microsoft SQL Server Documentation <https://docs.microsoft.com/en-us/sql/?view=sql-server-ver15>`__ | ||
* `Google Cloud Storage Documentation <https://cloud.google.com/storage/>`__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters