Skip to main content

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"
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

bq-airflow-dag-generator-0.1.3.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

bq_airflow_dag_generator-0.1.3-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file bq-airflow-dag-generator-0.1.3.tar.gz.

File metadata

  • Download URL: bq-airflow-dag-generator-0.1.3.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

Hashes for bq-airflow-dag-generator-0.1.3.tar.gz
Algorithm Hash digest
SHA256 5fde8f4eede366627be724245593e2829282fb9b48b012b9367d31d79a1897b8
MD5 d8411cbe3a16679c81e5d92803df681a
BLAKE2b-256 0e9da9fa358706cdf853635aa90db41f72ed74bdf978f3f4cd667804d8abf4b4

See more details on using hashes here.

File details

Details for the file bq_airflow_dag_generator-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for bq_airflow_dag_generator-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b4f893c40a95c4b9fc50ebb7da499433c2d6491b8d85dde31f35bcc7b78a24f0
MD5 5bbb398eaa2c35217fb7afd51c1db172
BLAKE2b-256 eda5b0d38a775e4cfff0932789d6360a5968ab73b4d5021113b1f6fc87f2f215

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page