Skip to content

Add hook_params to template_fields for BaseSQLOperator-related Operators - #38724

Merged
potiuk merged 4 commits into
apache:mainfrom
odaneau-astro:main
Apr 7, 2024
Merged

potiuk merged 4 commits into
apache:mainfrom
odaneau-astro:main

Conversation

@odaneau-astro

@odaneau-astro odaneau-astro commented Apr 3, 2024 •

Copy link
Copy Markdown
Contributor

This PR adds hook_params to template_fields for all Operators inheriting from BaseSQLOperator.

This change is necessary to pass DAG related attributes as query tags / labels when interacting with databases such as Snowflake or Big Query.
For example, here is how we can add meaningful tags to a Snowflake query with templated hook_params:

...
sql_execute_query_operator = SQLExecuteQueryOperator(
        task_id="sql_execute_query_operator_task",
        conn_id=snowflake_conn_id,
        sql="SELECT '1';",
        hook_params={
            "session_parameters": {
                "query_tag": "'dag_id': '{{ dag.dag_id }}'"
            }
        }
    )
...

@odaneau-astro
odaneau-astro marked this pull request as ready for review April 3, 2024 20:15
@odaneau-astro
odaneau-astro requested a review from eladkal as a code owner April 3, 2024 20:15
@potiuk
potiuk merged commit ef97ed2 into apache:main Apr 7, 2024
@potiuk

potiuk commented Apr 7, 2024

Copy link
Copy Markdown
Member

Nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants