GCS relative path for jinja2 .sql templates

899 views
Skip to first unread message

Filip Popić

unread,
Dec 11, 2018, 10:22:33 AM12/11/18
to cloud-compo...@googlegroups.com
Hi guys, can somebody explain to me how to setup jinja2

`template_searchpath=[....]` and PostgresToGoogleCloudStorageOperator `sql` parametar


```with DAG( template_searchpath=[XXX], ... ) as dag:
    psql_to_gcs = PostgresToGoogleCloudStorageOperator(sql=('YYY.sql'), ... )```

to be able to pick up all `.sql` files for the following GCS structure:

```/home/airflow/gcs/dags/my_project/dag/*.py
/home/airflow/gcs/dags/my_project/schema/*.schema
/home/ariflow/gcs/dags/my_project/sql/*.sql```

I see only solutions with `.sql` files inside DAG folder or as a subfolder in a DAG folder.

Thanks!

(I asked on composer slack but this is better place I guess to ask)

Guillaume Wibaux

unread,
Dec 12, 2018, 4:09:26 AM12/12/18
to cloud-composer-discuss
hi Filip

may be use something like template_searchpath = os.path.dirname(os.path.realpath(__file__) to get the path to the dag file and then add a dose of os.chdir to navigate relatively from your dag folder to your file with the sql files os.chdir('../sql')

Then for each task you can specify the files you want to run relatively to the template_searchpath.
Reply all
Reply to author
Forward
0 new messages