Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate MySQL example DAGs to new design #22453 #24142

Merged
merged 1 commit into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions airflow/providers/mysql/example_dags/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion docs/apache-airflow-providers-mysql/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Content
:maxdepth: 1
:caption: Resources

Example DAGs <https://github.com/apache/airflow/tree/main/airflow/providers/mysql/example_dags>
Example DAGs <https://github.com/apache/airflow/tree/tests/system/providers/mysql>
PyPI Repository <https://pypi.org/project/apache-airflow-providers-mysql/>
Installing from sources <installing-providers-from-sources>

Expand Down
4 changes: 2 additions & 2 deletions docs/apache-airflow-providers-mysql/operators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ the connection metadata is structured as follows:

An example usage of the MySqlOperator is as follows:

.. exampleinclude:: /../../airflow/providers/mysql/example_dags/example_mysql.py
.. exampleinclude:: /../../tests/system/providers/mysql/example_mysql.py
:language: python
:start-after: [START howto_operator_mysql]
:end-before: [END howto_operator_mysql]

You can also use an external file to execute the SQL commands. Script folder must be at the same level as DAG.py file.

.. exampleinclude:: /../../airflow/providers/mysql/example_dags/example_mysql.py
.. exampleinclude:: /../../tests/system/providers/mysql/example_mysql.py
:language: python
:start-after: [START howto_operator_mysql_external_file]
:end-before: [END howto_operator_mysql_external_file]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,45 @@
"""
Example use of MySql related operators.
"""

import os
from datetime import datetime

from airflow import DAG
from airflow.providers.mysql.operators.mysql import MySqlOperator

dag = DAG(
'example_mysql',
ENV_ID = os.environ.get("SYSTEM_TESTS_ENV_ID")
DAG_ID = "example_mysql"

with DAG(
DAG_ID,
start_date=datetime(2021, 1, 1),
default_args={'mysql_conn_id': 'mysql_conn_id'},
tags=['example'],
catchup=False,
)
) as dag:

# [START howto_operator_mysql]

drop_table_mysql_task = MySqlOperator(
task_id='drop_table_mysql', sql=r"""DROP TABLE table_name;""", dag=dag
)

# [END howto_operator_mysql]

# [START howto_operator_mysql]
# [START howto_operator_mysql_external_file]

drop_table_mysql_task = MySqlOperator(task_id='drop_table_mysql', sql=r"""DROP TABLE table_name;""", dag=dag)
mysql_task = MySqlOperator(
task_id='drop_table_mysql_external_file',
sql='/scripts/drop_table.sql',
dag=dag,
)

# [END howto_operator_mysql]
# [END howto_operator_mysql_external_file]

# [START howto_operator_mysql_external_file]
drop_table_mysql_task >> mysql_task

mysql_task = MySqlOperator(
task_id='drop_table_mysql_external_file',
sql='/scripts/drop_table.sql',
dag=dag,
)

# [END howto_operator_mysql_external_file]
from tests.system.utils import get_test_run # noqa: E402

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