You are viewing documentation about an older version (0.1.3). View latest version

snowflake.core.task.TaskCollection

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

Bases: SchemaObjectCollectionParent[TaskResource]

Represents the collection operations of the Snowflake Task resource.

Example

>>> tasks: TaskCollection = root.databases["mydb"].schemas["myschema"].tasks
>>> mytask = tasks.create(Task("mytask", definition="select 1"))  # returns a TaskResource instance.
>>> task_iter = tasks.iter(like="my%")
Copy

Attributes

database
root

Methods

__init__(schema: SchemaResource) None
create(task: Task, *, mode: Literal['errorifexists'] | Literal['orreplace'] | Literal['ifnotexists'] = 'errorifexists') TaskResource

Create a task in the Snowflake database.

Parameters:
  • task – an instance of Task.

  • mode

    One of the following strings.

    ”errorifexists”: Throw an snowflake.core.exceptions.ConflictError if the task already exists in

    Snowflake. Equivalent to SQL create task <name> ....

    ”orreplace”: Replace if the task already exists in Snowflake. Equivalent to SQL ``create or replace task

    <name> …``.

    ”ifnotexists”: Do nothing if the task already exists in Snowflake. Equivalent to SQL ``create task

    <name> if not exists…``

    Default value is “errorifexists”.

create_or_update(task: Task) TaskResource

Create or update a task in the Snowflake database.

The Snowflake task’s properties will be updated to the properties of the input task if the task already exists. Note that the full picture of a task is expected. If a property isn’t set a value in the input task, the property will be set to NULL in Snowflake too because it’s regarded as the expected value.

Parameters:

task – an instance of Task.

Example

>>> from snowflake.core import Root
>>> root = Root(connection)
>>> tasks: TaskCollection = root.databases["mydb"].schemas["myschema"].tasks
>>> mytask = tasks.create(Task("mytask", definition="select 1"))
>>> mytask_entity = mytask.fetch()
>>> mytask_entity.definition = "select 2"
>>> tasks.create_or_update(mytask_entity)
Copy
items() ItemsView[str, T]
iter(*, like: str | None = None, startswith: str | None = None, limit: int | None = None, from_name: str | None = None, root_only: bool = False) PagedIter[Task]

Search for tasks in Snowflake.

Parameters:
  • like – The pattern of the Task name. Use % to represent any number of characters and ? for a single character.

  • startswith – The task name starts with this string.

  • root_only – Look for root tasks only.

keys() KeysView[str]
values() ValuesView[T]