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.1.5.tar.gz
.
File metadata
- Download URL: bq-airflow-dag-generator-0.1.5.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.3 CPython/3.8.3 Darwin/19.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a713522ce292360aad63e50875fb7334f403e1ae6dd6e99e2c02a9d0abb1fc41 |
|
MD5 | 5937ad1fdd1e45aeea86b5b6e6b349d5 |
|
BLAKE2b-256 | 720bc02bd8813efae892f198da19e9484775653d1d05a632b0f7be983c4f4b9f |
File details
Details for the file bq_airflow_dag_generator-0.1.5-py3-none-any.whl
.
File metadata
- Download URL: bq_airflow_dag_generator-0.1.5-py3-none-any.whl
- Upload date:
- Size: 3.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.3 CPython/3.8.3 Darwin/19.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27bd74dc7d9d1bbe7fc40e5e421f169e3cf8570d73fa9793b7ecaada1db4d543 |
|
MD5 | 04ef585ece2bdafa7917d12320455b4f |
|
BLAKE2b-256 | fba60e5df80da21652095a9ea91ff3f2f8120f327773c697e759610cbdab2fef |