snowflake.core.task.TaskCollection

class snowflake.core.task.TaskCollection(schema: SchemaResource)

Bases: SchemaObjectCollectionParent[TaskResource]

Represents the collection operations of the Snowflake Task resource.

With this collection, you can create, iterate through, and search for task that you have access to in the current context.

Examples

>>> task_collection = root.databases["mydb"].schemas["myschema"].tasks
>>> task = Task(
...     name="mytask",
...     definition="select 1"
... )
>>> task_collection.create(task)
Copy

Attributes

database
root

Methods

create(task: Task, *, mode: CreateMode = CreateMode.error_if_exists) TaskResource

Create a task in Snowflake.

Parameters:
  • task (an instance of Task.)

  • mode (CreateMode, optional) –

    One of the following strings.

    CreateMode.error_if_exists: Throw an snowflake.core.exceptions.ConflictError if the task already exists in Snowflake. Equivalent to SQL create task <name> ....

    CreateMode.or_replace: Replace if the task already exists in Snowflake. Equivalent to SQL create or replace task <name> ....

    CreateMode.if_not_exists: Do nothing if the task already exists in Snowflake. Equivalent to SQL create task <name> if not exists...

    Default value is CreateMode.error_if_exists.

Examples

Creating a task in Snowflake and getting a reference to it:

>>> task_parameters = Task(
...     name="mytask",
...     definition="select 1"
... )
>>> # Use the task collection created before to create a referece to the task resource
>>> # in Snowflake.
>>> task_reference = task_collection.create(task_parameters)
Copy
items() ItemsView[str, T]
iter(*, like: str | None = None, starts_with: str | None = None, limit: int | None = None, from_name: str | None = None, root_only: bool = False) Iterator[Task]

Iterate through Task objects in Snowflake, filtering on any optional like pattern.

Parameters:
  • like (str, optional) – A case-insensitive string functioning as a filter, with support for SQL wildcard characters (% and _).

  • starts_with (str, optional) – String used to filter the command output based on the string of characters t

  • limit (int, optional) – Limit of the maximum number of rows returned by iter(). The default is None, which behaves equivalently to show_limit=10000. This value must be between 1 and 10000.

  • from_name (str, optional) – Fetch rows only following the first row whose object name matches the specified string. This is case-sensitive and does not have to be the full name.

  • root_only (bool, optional) – Look for root tasks only. Default is False.

Examples

Showing all tasks that you have access to see:

>>> tasks = task_collection.iter()
Copy

Showing information of the exact task you want to see:

>>> tasks = task_collection.iter(like="your-task-name")
Copy

Showing tasks starting with ‘your-task-name-‘:

>>> tasks = task_collection.iter(like="your-task-name-%")
Copy

Using a for loop to retrieve information from iterator:

>>> for task in tasks:
...     print(task.name, task.comment)
Copy
keys() KeysView[str]
values() ValuesView[T]
Language: English