Generate Airflow DAG from DOT language to execute BigQuery efficiently mainly for AlphaSQL
Project description
bq-airflow-dag-generator
Utility package to generate Airflow DAG from DOT language to execute BigQuery efficiently mainly for AlphaSQL.
Install
pip install bq-airflow-dag-generator
Usage
# You can set SQL_ROOT if your SQL file paths in dag.dot are not on current directory.
os.environ["SQL_ROOT"] = "/path/to/sql/root"
dagpath = "/path/to/dag.dot"
dag = generate_airflow_dag_by_dot_path(dagpath)
You can add tasks to existing DAG like
dagpath = "/path/to/dag.dot"
existing_airflow_dag
generate_airflow_dag_by_dot_path(dagpath, dag=existing_airflow_dag)
You can pass how to create Aiflow tasks like
def gen_task(sql_file_path, dag):
sql_root = os.environ.get("SQL_ROOT")
sql_file_path = os.path.join(sql_root, sql_file_path) if sql_root else sql_file_path
with open(sql_file_path, "r") as f:
query = f.read()
task = PythonOperator(
task_id=sql_file_path.replace("/", ""),
python_callable=get_bigquery_callable(query),
dag=dag,
)
task.doc = f"""\
# BigQuery Task Documentation: {sql_file_path}
This is automatically generated.
Query:
{query}
"""
return task
dagpath = "/path/to/dag.dot"
dag = generate_airflow_dag_by_dot_path(dagpath, get_task_by_sql_path_and_dag=gen_task)
Test
python -m unittest tests.test_dags
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file bq-airflow-dag-generator-0.2.0.tar.gz
.
File metadata
- Download URL: bq-airflow-dag-generator-0.2.0.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.5 CPython/3.7.10 Darwin/20.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cafa8ae0e0d20cf1112ef001cdbb4bb2504060dd8f5fd4b198ef1b94b617324e |
|
MD5 | 8c948ec5fd19ccf176aac69f9ce8f844 |
|
BLAKE2b-256 | 90d4fba59fee0871c06455e0cdd1effdb045cb5669db78e6b2d1892e8417434f |
File details
Details for the file bq_airflow_dag_generator-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: bq_airflow_dag_generator-0.2.0-py3-none-any.whl
- Upload date:
- Size: 3.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.5 CPython/3.7.10 Darwin/20.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5e455e49724ba827df68aaaf7a44c3ab5eb30c3ca9c95f24a5d7e1622072de3 |
|
MD5 | c548fda367de517745763e860e99a916 |
|
BLAKE2b-256 | e656bbaf886091680db1c05eadc04e0df50281c208f13df21602689b27ca7ca7 |