SnowflakeCheckOperator

Snowflake

Performs a check against Snowflake. The SnowflakeCheckOperator expects a sql query that will return a single row. Each value on that first row is evaluated using python bool casting. If any of the values return False the check is failed and errors out.

View on GitHub

Last Updated: Sep. 9, 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

sqlRequiredCan receive a str representing a sql statement, a list of str (sql statements), or reference to a template file. Template reference are recognized by str ending in ‘.sql’the sql code to be executed. (templated)
snowflake_conn_idstrReference to Snowflake connection id
autocommitboolif True, each command is automatically committed. (default value: True)
parametersdict or iterable(optional) the parameters to render the SQL query with.
warehousestrname of warehouse (will overwrite any warehouse defined in the connection’s extra JSON)
databasestrname of database (will overwrite database defined in connection)
schemastrname of schema (will overwrite schema defined in connection)
rolestrname of role (will overwrite any role defined in connection’s extra JSON)
authenticatorstrauthenticator for Snowflake. ‘snowflake’ (default) to use the internal Snowflake authenticator ‘externalbrowser’ to authenticate using your web browser and Okta, ADFS or any other SAML 2.0-compliant identify provider (IdP) that has been defined for your account ‘https://.okta.com’ to authenticate through native Okta.
session_parametersdictYou can set session-level parameters at the time you connect to Snowflake

Documentation

Performs a check against Snowflake. The SnowflakeCheckOperator expects a sql query that will return a single row. Each value on that first row is evaluated using python bool casting. If any of the values return False the check is failed and errors out.

Note that Python bool casting evals the following as False:

  • False

  • 0

  • Empty string ("")

  • Empty list ([])

  • Empty dictionary or set ({})

Given a query like SELECT COUNT(*) FROM foo, it will fail only if the count == 0. You can craft much more complex query that could, for instance, check that the table has the same number of rows as the source table upstream, or that the count of today’s partition is greater than yesterday’s partition, or that a set of metrics are less than 3 standard deviation for the 7 day average.

This operator can be used as a data quality check in your pipeline, and depending on where you put it in your DAG, you have the choice to stop the critical path, preventing from publishing dubious data, or on the side and receive email alerts without stopping the progress of the DAG.

Was this page helpful?