# Snowflake Tasks

Verified by Prefect

These tasks have been tested and verified by Prefect.

This module contains a collection of tasks for interacting with snowflake databases via the snowflake-connector-python library.

# SnowflakeQuery

class

prefect.tasks.snowflake.snowflake.SnowflakeQuery

(account=None, user=None, password=None, private_key=None, database=None, schema=None, role=None, warehouse=None, query=None, data=None, autocommit=None, cursor_type=snowflake.connector.cursor.SnowflakeCursor, authenticator=None, token=None, **kwargs)[source]

Task for executing a query against a Snowflake database.

Args:

  • account (str): Snowflake account name, see Snowflake connector package documentation for details.
  • user (str): User name used to authenticate.
  • password (str, optional): Password used to authenticate. password or private_key must be present, unless authenticator is provided.
  • private_key (bytes, optional): PEM to authenticate. password or private_key must be present, unless authenticator is provided.
  • database (str, optional): Name of the default database to use.
  • schema (int, optional): Name of the default schema to use.
  • role (str, optional): Name of the default role to use.
  • warehouse (str, optional): Name of the default warehouse to use.
  • query (str, optional): Query to execute against database.
  • data (tuple, optional): Values to use in query, must be specified using placeholder in query string.
  • autocommit (bool, optional): Set to True to autocommit, defaults to None, which takes Snowflake AUTOCOMMIT parameter.
  • cursor_type (SnowflakeCursor, optional): Specify the type of database cursor to use for the query, defaults to SnowflakeCursor.
  • authenticator (str, optional): Type of authenticator to use for initiating connection (oauth, externalbrowser...), refer to Snowflake Python Connector API documentation for details. Note that externalbrowser will only work in an environment where a browser is available, default to None.
  • token (str, optional): OAuth or JWT Token to provide when authenticator is set to oauth, default to None.
  • **kwargs (dict, optional): Additional keyword arguments to pass to the Task constructor.

methods:                                                                                                                                                       

prefect.tasks.snowflake.snowflake.SnowflakeQuery.run

(account=None, user=None, password=None, private_key=None, database=None, schema=None, role=None, warehouse=None, query=None, data=None, autocommit=None, cursor_type=snowflake.connector.cursor.SnowflakeCursor, authenticator=None, token=None)[source]

Task run method. Executes a query against Snowflake database.

Args:

  • account (str, optional): Snowflake account name, see Snowflake connector package documentation for details.
  • user (str, optional): User name used to authenticate.
  • password (str, optional): Password used to authenticate. password or private_key must be present, unless authenticator is provided
  • private_key (bytes, optional): PEM to authenticate. password or private_key must be present, unless authenticator is provided
  • database (str, optional): Name of the default database to use.
  • schema (int, optional): Name of the default schema to use.
  • role (str, optional): Name of the default role to use.
  • warehouse (str, optional): Name of the default warehouse to use.
  • query (str, optional): Query to execute against database.
  • data (tuple, optional): Values to use in query, must be specified using placeholder in query string.
  • autocommit (bool, optional): Set to True to autocommit, defaults to None, which takes Snowflake AUTOCOMMIT parameter.
  • cursor_type (SnowflakeCursor, optional): Specify the type of database cursor to use for the query, defaults to SnowflakeCursor.
  • authenticator (str, optional): Type of authenticator to use for initiating connection (oauth, externalbrowser...), refer to Snowflake Python Connector API documentation for details. Note that externalbrowser will only work in an environment where a browser is available, default to None.
  • token (str, optional): OAuth or JWT Token to provide when authenticator is set to oauth, default to None.
Returns:
  • List[List]: Output of cursor.fetchall().
Raises:
  • ValueError: If a required parameter is not supplied.
  • DatabaseError: If exception occurs when executing the query.



# SnowflakeQueriesFromFile

class

prefect.tasks.snowflake.snowflake.SnowflakeQueriesFromFile

(account=None, user=None, password=None, private_key=None, database=None, schema=None, role=None, warehouse=None, file_path=None, autocommit=None, cursor_type=snowflake.connector.cursor.SnowflakeCursor, authenticator=None, token=None, **kwargs)[source]

Task for executing queries loaded from a file against a Snowflake database. Return a list containings the results of the queries.

Note that using execute_string() is vulnerable to SQL injection.

Args:

  • account (str, optional): Snowflake account name, see Snowflake connector package documentation for details.
  • user (str, optional): User name used to authenticate.
  • password (str, optional): Password used to authenticate. password or private_key must be present, unless authenticator is provided.
  • private_key (bytes, optional): PEM to authenticate. password or private_key must be present, unless authenticator is provided.
  • database (str, optional): Name of the default database to use.
  • schema (int, optional): Name of the default schema to use.
  • role (str, optional): Name of the default role to use.
  • warehouse (str, optional): Name of the default warehouse to use.
  • file_path (str, optional): File path to load query from.
  • autocommit (bool, optional): Set to True to autocommit, defaults to None, which takes Snowflake AUTOCOMMIT parameter.
  • cursor_type (SnowflakeCursor, optional): Specify the type of database cursor to use for the query, defaults to SnowflakeCursor.
  • authenticator (str, optional): Type of authenticator to use for initiating connection (oauth, externalbrowser...), refer to Snowflake Python Connector API documentation for details. Note that externalbrowser will only work in an environment where a browser is available, default to None.
  • token (str, optional): OAuth or JWT Token to provide when authenticator is set to oauth, default to None.
  • **kwargs (dict, optional): Additional keyword arguments to pass to the Task constructor.

methods:                                                                                                                                                       

prefect.tasks.snowflake.snowflake.SnowflakeQueriesFromFile.run

(account=None, user=None, password=None, private_key=None, database=None, schema=None, role=None, warehouse=None, file_path=None, autocommit=None, cursor_type=snowflake.connector.cursor.SnowflakeCursor, authenticator=None, token=None)[source]

Task run method. Executes a query against Snowflake database.

Args:

  • account (str): Snowflake account name, see Snowflake connector package documentation for details.
  • user (str): User name used to authenticate.
  • password (str, optional): Password used to authenticate. password or private_key must be present, unless authenticator is provided.
  • private_key (bytes, optional): PEM to authenticate. password or private_key must be present, unless authenticator is provided.
  • database (str, optional): Name of the default database to use.
  • schema (int, optional): Name of the default schema to use.
  • role (str, optional): Name of the default role to use.
  • warehouse (str, optional): Name of the default warehouse to use.
  • file_path (str, optional): File path to load query from.
  • autocommit (bool, optional): Set to True to autocommit, defaults to None, which takes Snowflake AUTOCOMMIT parameter.
  • cursor_type (SnowflakeCursor, optional): Specify the type of database cursor to use for the query, defaults to SnowflakeCursor.
  • authenticator (str, optional): Type of authenticator to use for initiating connection (oauth, externalbrowser...), refer to Snowflake Python Connector API documentation for details. Note that externalbrowser will only work in an environment where a browser is available, default to None.
  • token (str, optional): OAuth or JWT Token to provide when authenticator is set to oauth, default to None.
Returns:
  • List[List]: Containing the results of the different queries executed.
Raises:
  • ValueError: If query parameter is None or a blank string.
  • DatabaseError: If exception occurs when executing the query.
  • FileNotFoundError: If File does not exist.



This documentation was auto-generated from commit e6bd04a
on September 7, 2022 at 21:06 UTC