airflowairflow-2.xsqlfluff

How to support Airflow jinja template in sqlfluff


I want to run sqlfluff fix command to this sql file. This SQL is for Snowflake and will be executed in Airflow. ti.xcom_pull is a function used in Airflow DAG.

DELETE FROM test
WHERE date = '{{ti.xcom_pull(key='filedate')}}';    

then I got this error in fix command.

L:   1 | P:   1 |  TMP | Unrecoverable failure in Jinja templating: 'ti' is
                       | undefined. Have you configured your variables?
                       | https://docs.sqlfluff.com/en/latest/configuration.html

This means that sqlfluff does not directly support Airflow template and we have to provide variable for ti.xcom_pull. How can I do it?


Solution

  • Use --ignore=templating with sqlfluff fix, if you don't want to provide variables. See https://docs.sqlfluff.com/en/stable/configuration.html#interaction-with-ignore-templating