External files in Airflow DAG

不羁岁月 提交于 2019-12-05 02:09:36
zhongjiajie

Here is an example use Variable to make it easy.

  • First add Variable in Airflow UI -> Admin -> Variable, eg. {key: 'sql_path', values: 'your_sql_script_folder'}

  • Then add following code in your DAG, to use Variable from Airflow you just add.

DAG code:

import airflow
from airflow.models import Variable

tmpl_search_path = Variable.get("sql_path")

dag = airflow.DAG(
   'tutorial',
    schedule_interval="@daily",
    template_searchpath=tmpl_search_path,  # this
    default_args=default_args
)
  • Now you can use sql script name or path under folder Variable

  • You can learn more in this

All relative paths are taken in reference to the AIRFLOW_HOME environment variable. Try:

  • Giving absolute path
  • place the file relative to AIRFLOW_HOME
  • try logging the PWD in the python callable and then decide what path to give (Best option)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!