SnowflakeToSlackOperator

Snowflake

Executes an SQL statement in Snowflake and sends the results to Slack. The results of the query are rendered into the ‘slack_message’ parameter as a Pandas dataframe using a JINJA variable called ‘{{ results_df }}’. The ‘results_df’ variable name can be changed by specifying a different ‘results_df_name’ parameter. The Tabulate library is added to the JINJA environment as a filter to allow the dataframe to be rendered nicely. For example, set ‘slack_message’ to {{ results_df | tabulate(tablefmt=”pretty”, headers=”keys”) }} to send the results to Slack as an ascii rendered table.

View Source

Last Updated: Apr. 25, 2021

Access Instructions

Install the Snowflake provider package into your Airflow environment.

Import the module into your DAG file and instantiate it with your desired params.

Parameters

sqlstrThe SQL statement to execute on Snowflake (templated)
slack_messagestrThe templated Slack message to send with the data returned from Snowflake. You can use the default JINJA variable {{ results_df }} to access the pandas dataframe containing the SQL results
snowflake_conn_idstrThe Snowflake connection id
slack_conn_idstrThe connection id for Slack
results_df_namestrThe name of the JINJA template's dataframe variable, default is 'results_df'
parametersOptional[Union[Iterable, Mapping]]The parameters to pass to the SQL query
warehouseOptional[str]The Snowflake virtual warehouse to use to run the SQL query
databaseOptional[str]The Snowflake database to use for the SQL query
schemaOptional[str]The schema to run the SQL against in Snowflake
roleOptional[str]The role to use when connecting to Snowflake
slack_tokenOptional[str]The token to use to authenticate to Slack. If this is not provided, the 'webhook_token' attribute needs to be specified in the 'Extra' JSON field against the slack_conn_id

Documentation

Executes an SQL statement in Snowflake and sends the results to Slack. The results of the query are rendered into the ‘slack_message’ parameter as a Pandas dataframe using a JINJA variable called ‘{{ results_df }}’. The ‘results_df’ variable name can be changed by specifying a different ‘results_df_name’ parameter. The Tabulate library is added to the JINJA environment as a filter to allow the dataframe to be rendered nicely. For example, set ‘slack_message’ to {{ results_df | tabulate(tablefmt=”pretty”, headers=”keys”) }} to send the results to Slack as an ascii rendered table.

See also

For more information on how to use this operator, take a look at the guide: SnowflakeToSlackOperator

Was this page helpful?