A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.snowflake.com/en/developer-guide/python-connector/../../sql-reference/sql/alter-task below:

Website Navigation


ALTER TASK | Snowflake Documentation

ALTER TASK

Modifies the properties for an existing task.

For information about tasks, see Introduction to tasks.

See also:

CREATE TASK , DROP TASK , SHOW TASKS , DESCRIBE TASK

Syntax
ALTER TASK [ IF EXISTS ] <name> RESUME | SUSPEND

ALTER TASK [ IF EXISTS ] <name> REMOVE AFTER <string> [ , <string> , ... ]
  | ADD AFTER <string> [ , <string> , ... ]

ALTER TASK [ IF EXISTS ] <name> SET
  [ { WAREHOUSE = <string> }
    | { USER_TASK_MANAGED_INITIAL_WAREHOUSE_SIZE = <string> } ]
  [ SCHEDULE = { '<num> { HOURS | MINUTES | SECONDS }'
               | 'USING CRON <expr> <time_zone>' } ]
  [ CONFIG = <configuration_string> ]
  [ ALLOW_OVERLAPPING_EXECUTION = TRUE | FALSE ]
  [ USER_TASK_TIMEOUT_MS = <num> ]
  [ SUSPEND_TASK_AFTER_NUM_FAILURES = <num> ]
  [ ERROR_INTEGRATION = <integration_name> ]
  [ SUCCESS_INTEGRATION = <integration_name> ]
  [ LOG_LEVEL = '<log_level>' ]
  [ COMMENT = <string> ]
  [ <session_parameter> = <value>
    [ , <session_parameter> = <value> ... ] ]
  [ TASK_AUTO_RETRY_ATTEMPTS = <num> ]
  [ USER_TASK_MINIMUM_TRIGGER_INTERVAL_IN_SECONDS = <num> ]
  [ TARGET_COMPLETION_INTERVAL = '<num> { HOURS | MINUTES | SECONDS }' ]
  [ SERVERLESS_TASK_MIN_STATEMENT_SIZE= 'XSMALL | SMALL
    | MEDIUM | LARGE | XLARGE | XXLARGE' ]
  [ SERVERLESS_TASK_MAX_STATEMENT_SIZE= 'XSMALL | SMALL
    | MEDIUM | LARGE | XLARGE | XXLARGE' ]
  [ CONTACT ( <purpose> = <contact_name> [ , <purpose> = <contact_name> ... ] ) ]


ALTER TASK [ IF EXISTS ] <name> UNSET
  [ WAREHOUSE ]
  [ SCHEDULE ]
  [ CONFIG ]
  [ ALLOW_OVERLAPPING_EXECUTION ]
  [ USER_TASK_TIMEOUT_MS ]
  [ SUSPEND_TASK_AFTER_NUM_FAILURES ]
  [ LOG_LEVEL ]
  [ COMMENT ]
  [ <session_parameter> [ , <session_parameter> ... ] ]
  [ TARGET_COMPLETION_INTERVAL ]
  [ SERVERLESS_TASK_MIN_STATEMENT_SIZE ]
  [ SERVERLESS_TASK_MAX_STATEMENT_SIZE ]
  [ CONTACT <purpose> ]
  [ , ... ]

ALTER TASK [ IF EXISTS ] <name> SET TAG <tag_name> = '<tag_value>'
  [ , <tag_name> = '<tag_value>' ... ]

ALTER TASK [ IF EXISTS ] <name> UNSET TAG <tag_name> [ , <tag_name> ... ]

ALTER TASK [ IF EXISTS ] <name> SET FINALIZE = <string>

ALTER TASK [ IF EXISTS ] <name> UNSET FINALIZE

ALTER TASK [ IF EXISTS ] <name> MODIFY AS <sql>

ALTER TASK [ IF EXISTS ] <name> MODIFY WHEN <boolean_expr>

ALTER TASK [ IF EXISTS ] <name> REMOVE WHEN

Copy

Parameters
name

Identifier for the task to alter. If the identifier contains spaces or special characters, the entire string must be enclosed in double quotes. Identifiers enclosed in double quotes are also case-sensitive.

RESUME | SUSPEND

Specifies the action to perform on the task:

If the task schedule is set to an interval of (number { HOURS | MINUTES | SECONDS }), the base interval time for the schedule is reset to the current time the task is resumed.

The base interval time starts the interval counter from the current clock time. For example, if an INTERVAL value of 10 MINUTES is set and the task is resumed at 9:03 AM, then the task runs at 9:13 AM, 9:23 AM, and so on. Note that we only guarantee that tasks don’t execute before their set interval occurs. In the current example, the task could first run at 9:14 AM, but won’t run at 9:12 AM.

REMOVE AFTER string [ , string , ... ]

Specifies the names of one or more current predecessor tasks for this child task in a task graph.

When all predecessors for a child task are removed, then the former child task becomes either a standalone task or a root task, depending on whether other tasks identify this former child task as their predecessor. If the former child task becomes a root task, this task is suspended by default and must be resumed manually.

ADD AFTER string [ , string , ... ]

Specifies the names of one or more existing tasks to add as predecessors for this child task in a task graph. Each child task in a task graph runs when all predecessor tasks finish their runs successfully. For more information, see the description of the AFTER parameter in CREATE TASK.

Each child task is limited to 100 predecessor tasks.

SET ...

Specifies either or both of the following:

UNSET ...

Specifies one (or more) properties and/or session parameters to unset for the task, which resets them to the defaults.

You can reset multiple properties/parameters with a single ALTER statement; however, each property/parameter must be separated by a comma. When resetting a property/parameter, specify only the name; specifying a value for the property/parameter will return an error.

To detach a contact from the task, specify UNSET CONTACT purpose.

sql

Specifies the SQL code to execute when the task runs:

Note

Verify that the SQL code you reference in a task executes as expected before you create the task. Tasks are intended to automate SQL code that has already been tested thoroughly.

WHEN boolean_expr

Specifies a Boolean SQL expression. When a task is triggered, it validates the conditions of the expression to determine whether to execute. If the conditions of the expression are not met, then the task skips the current run. Any tasks that identify this task as a predecessor also do not run.

Validating the conditions of the WHEN expression does not require a virtual warehouse. The validation is instead processed in the cloud services layer. A nominal charge accrues each time a task evaluates its WHEN condition and does not run. The charges accumulate each time the task is triggered until it runs. At that time, the charge is converted to Snowflake credits and added to the compute resource usage for the task run.

Generally the compute time to validate the condition is insignificant compared to task execution time. As a best practice, align scheduled and actual task runs as closely as possible. Avoid task schedules that are wildly out of synch with actual task runs. For example, if data is inserted into a table with a stream roughly every 24 hours, don’t schedule a task that checks for stream data every minute. The charge to validate the WHEN expression with each run is generally insignificant, but the charges are cumulative.

Note that daily consumption of cloud services that falls below the 10% quota of the daily usage of the compute resources accumulates no cloud services charges.

Currently, the following functions are supported for evaluation in the SQL expression:

SYSTEM$STREAM_HAS_DATA

Indicates whether a specified stream contains change tracking data. Used to run a triggered task if no schedule is defined for the task. You can also use this to skip the current task run if the stream contains no change data.

If the result is FALSE, then the task does not run.

SYSTEM$GET_PREDECESSOR_RETURN_VALUE

Retrieves the return value for the predecessor task in a task graph. Used to decide whether the task should run based on the returned result.

REMOVE WHEN

Remove the WHEN condition that you have specified.

Rename a task

Renaming a task isn’t supported. Instead, you can clone the task, and then drop the old task; for example:

  1. Suspend the task (ALTER TASK task_old_name SUSPEND).

  2. Clone the task, giving it a new name (CREATE TASK new_task_name CLONE old_task_name).

  3. For task graphs, find dependent tasks that refer to the old task name, and update them to use the new name:

  1. Find immediately dependent tasks (that is, child tasks and finalizer tasks, but not children-of-children tasks) using the TASK_DEPENDENTS … RECURSIVE function; for example:

    SELECT * FROM TABLE(INFORMATION_SCHEMA.TASK_DEPENDENTS('old_task_name', RECURSIVE => false));
    

    Copy

  2. Update each dependent task to use the new task name (ALTER TASK child_task_1 ADD AFTER new_task_name).

  1. Drop the old version of the task (DROP TASK old_task_name).

  2. Resume the new version of the task (ALTER TASK new_task_name RESUME).

Usage notes Examples

The following example initiates operation of a task:

ALTER TASK mytask RESUME;

Copy

The following example converts a task to the serverless compute model and sets xsmall as the amount of compute resources to provision for the first serverless runs of the task:

ALTER TASK mytask UNSET WAREHOUSE;

ALTER TASK mytask SET USER_TASK_MANAGED_INITIAL_WAREHOUSE_SIZE = 'XSMALL';

Copy

The following example sets the TIMEZONE and CLIENT_TIMESTAMP_TYPE_MAPPING session parameters for the session in which the task runs:

ALTER TASK mytask SET TIMEZONE = 'America/Los_Angeles', CLIENT_TIMESTAMP_TYPE_MAPPING = TIMESTAMP_LTZ;

Copy

The following example sets a different schedule for a task:

ALTER TASK mytask SET SCHEDULE = 'USING CRON */3 * * * * UTC';

Copy

The following example removes the current predecessor tasks for the mytask child task (pred_task1, pred_task2) and replace them with a different predecessor task (pred_task3):

ALTER TASK mytask REMOVE AFTER pred_task1, pred_task2;

ALTER TASK mytask ADD AFTER pred_task3;

Copy

The following example changes the SQL statement associated with a task. The task now queries the CURRENT_VERSION function when it runs:

ALTER TASK mytask MODIFY AS SELECT CURRENT_VERSION();

Copy

The following example modifies the WHEN condition associated with a task. When triggered (on a schedule or after the predecessor task runs successfully), the task now runs only when the mystream stream contains data:

ALTER TASK mytask MODIFY WHEN SYSTEM$STREAM_HAS_DATA('MYSTREAM');

Copy

Update an existing task with new or replacement configuration.

ALTER TASK task_with_config SET
      CONFIG=$${"output_directory": "/temp/prod_directory/", "environment": "prod"}$$;

Copy

Remove configuration from an existing task.

ALTER TASK task_with_config UNSET CONFIG;

Copy


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4