josh-fell commented on issue #39651: URL: https://github.com/apache/airflow/issues/39651#issuecomment-2116489404
You can use [Jinja's `include` tag](https://jinja.palletsprojects.com/en/3.1.x/templates/#include) to render a file's contents. For example, using this SQL file; ```sql # dags/sql/default.sql SELECT 'from a templated file'; ``` and this task definition: ```py from airflow.models.dag import DAG from airflow.models.param import Param from airflow.providers.common.sql.operators.sql import SQLExecuteQueryOperator with DAG( "generate_password_dag", params={"test": Param("default", type="string")}, ): sql_operator = SQLExecuteQueryOperator( task_id="sql_operator", sql="{% include 'sql/' ~ params.test ~ '.sql' %}", conn_id="postgres", ) ``` In the above task definition, `~` is string concatenation in Jinja. Task log: <img width="941" alt="image" src="https://github.com/apache/airflow/assets/48934154/3ddf0c00-c10a-40fa-97f0-b2993bc26bc9"> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
