:py:mod:`astronomer.providers.snowflake.operators.snowflake` ============================================================ .. py:module:: astronomer.providers.snowflake.operators.snowflake Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: astronomer.providers.snowflake.operators.snowflake.SnowflakeOperatorAsync astronomer.providers.snowflake.operators.snowflake.SnowflakeSqlApiOperatorAsync .. py:class:: SnowflakeOperatorAsync(*, snowflake_conn_id = 'snowflake_default', warehouse = None, database = None, role = None, schema = None, authenticator = None, session_parameters = None, poll_interval = 5, handler = fetch_all_snowflake_handler, return_last = True, **kwargs) Bases: :py:obj:`airflow.providers.snowflake.operators.snowflake.SnowflakeOperator` - SnowflakeOperatorAsync uses the snowflake python connector ``execute_async`` method to submit a database command for asynchronous execution. - Submit multiple queries in parallel without waiting for each query to complete. - Accepts list of queries or multiple queries with ‘;’ semicolon separated string and params. It loops through the queries and execute them in sequence. Uses execute_async method to run the query - Once a query is submitted, it executes the query from one connection and gets the query IDs from the response and passes it to the Triggerer and closes the connection (so that the worker slots can be freed up). - The trigger gets the list of query IDs as input and polls every few seconds to snowflake and checks for the query status based on the query ID from different connection. Where can this operator fit in? - Execute time taking queries which can be executed in parallel - For batch based operation like copy or inserting the data in parallel. Best practices: - Ensure that you know which queries are dependent upon other queries before you run any queries in parallel. Some queries are interdependent and order sensitive, and therefore not suitable for parallelizing. For example, obviously an INSERT statement should not start until after the corresponding to CREATE TABLE statement has finished. - Ensure that you do not run too many queries for the memory that you have available. Running multiple queries in parallel typically consumes more memory, especially if more than one set of results is stored in memory at the same time. - Ensure that transaction control statements (BEGIN, COMMIT, and ROLLBACK) do not execute in parallel with other statements. .. seealso:: - `Snowflake Async Python connector `_ - `Best Practices `_ :param snowflake_conn_id: Reference to Snowflake connection id :param sql: the sql code to be executed. (templated) :param autocommit: if True, each command is automatically committed. (default value: True) :param parameters: (optional) the parameters to render the SQL query with. :param warehouse: name of warehouse (will overwrite any warehouse defined in the connection's extra JSON) :param database: name of database (will overwrite database defined in connection) :param schema: name of schema (will overwrite schema defined in connection) :param role: name of role (will overwrite any role defined in connection's extra JSON) :param authenticator: authenticator 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. :param session_parameters: You can set session-level parameters at the time you connect to Snowflake :param handler: (optional) the function that will be applied to the cursor (default: fetch_all_handler). :param return_last: (optional) if return the result of only last statement (default: True). :param poll_interval: the interval in seconds to poll the query .. py:method:: get_db_hook() Get the Snowflake Hook .. py:method:: execute(context) Make a sync connection to snowflake and run query in execute_async function in snowflake and close the connection and with the query ids, fetch the status of the query. By deferring the SnowflakeTrigger class pass along with query ids. .. py:method:: execute_complete(context, event = None) Callback for when the trigger fires - returns immediately. Relies on trigger to throw an exception, otherwise it assumes execution was successful. .. py:class:: SnowflakeSqlApiOperatorAsync(*args, **kwargs) Bases: :py:obj:`airflow.providers.snowflake.operators.snowflake.SnowflakeSqlApiOperator` This class is deprecated. Use :class: `~airflow.providers.snowflake.operators.snowflake.SnowflakeSqlApiOperator` instead and set `deferrable` param to `True` instead.