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)
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 ansnowflake.core.exceptions.ConflictError
if the task already exists in Snowflake. Equivalent to SQLcreate task <name> ...
.CreateMode.or_replace
: Replace if the task already exists in Snowflake. Equivalent to SQLcreate or replace task <name> ...
.CreateMode.if_not_exists
: Do nothing if the task already exists in Snowflake. Equivalent to SQLcreate 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)
- 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 optionallike
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 between1
and10000
.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()
Showing information of the exact task you want to see:
>>> tasks = task_collection.iter(like="your-task-name")
Showing tasks starting with βyour-task-name-β:
>>> tasks = task_collection.iter(like="your-task-name-%")
Using a for loop to retrieve information from iterator:
>>> for task in tasks: ... print(task.name, task.comment)
- keys() KeysView[str] ΒΆ
- values() ValuesView[T] ΒΆ