将 Snowpark Container Services 作业作为 Snowflake 任务运行

You can run a Snowpark Container Services job service as a Snowflake task. When you run a job service as a Snowflake task, the integration enables scenarios that leverage the robust containerization and scalability of Snowpark Container Services. This process occurs directly within your scheduled or event-triggered data pipelines that are managed by Snowflake Tasks.

例如,以下 CREATE TASK 命令会创建一个任务,每小时运行一次作业服务。该命令通过使用 EXECUTE JOB SERVICE SQL 命令,提供作业详细信息:

CREATE TASK job_task
SCHEDULE = '60 MINUTE'
AS
  EXECUTE JOB SERVICE
    IN COMPUTE POOL my_compute_pool
    FROM SPECIFICATION $$
    spec:
      containers:
      - name: main
        image: /my_db/my_schema/my_repository/my_job_image:latest
        args:
          - "--process_data"
    $$;
Copy

备注

  • Snowflake 作业任务支持 无服务器模型,因此您无需在 CREATE TASK 语句中指定仓库。

  • 将作业服务作为任务运行时,应同步运行作业服务,否则任务将在作业服务完成前报告完成。

将数据传入和传出作为任务运行的作业

Task graphs enable you to create and manage complex, multi-step data pipelines that seamlessly integrate job services running as tasks. You can use the supported system functions in your job service code to access the task context and use it to fetch task graph configuration, and runtime information of the executing task.

将作业服务作为任务运行时,可以在任务图中的任务之间使用以下数据共享选项:

  • 前置返回值机制: 在任务图中,您可以将某个任务的输出作为输入传递给后续的相关任务。 当您传递小型元数据(例如文件路径、状态字符串或一些其他的 ID 值)时,Snowflake 建议使用此选项。有关更多信息,请参阅 在任务之间传递返回值

    就像 SQL 任务,作为任务运行的作业可以检索先前任务的返回值。同样,作业也可以为后续任务提供返回值。

  • Common persistent storage mechanism: When you transfer large datasets, such as files, Snowflake recommends that you persist the data in persistent storage, such as a Snowflake stage or table, and ensure that the tasks in your task graph can access the storage.

备注

作业服务之间不共享会话。因此,不能使用临时表或会话变量作为共享数据的方式,因为它们都是会话范围的对象。

示例

有关示例,请参阅 教程:将 Snowflake Container Services 作业作为 Snowflake 任务运行

语言: 中文