You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过标签过滤GCP Dataform Client API的工作流执行?

解决GCP Dataform Client API仅运行指定标签流水线的问题

你的代码只指定了编译结果,没有配置执行过滤规则,所以默认会运行所有流水线任务。要通过标签过滤执行范围,需要在WorkflowInvocation对象中添加invocation_config配置,明确指定要包含的标签。

修改后的代码如下:

from google.protobuf.field_mask_pb2 import FieldMask
from google.oauth2 import service_account
from google.cloud import storage, bigquery
from google.cloud import dataform

# 加载凭证并创建客户端
credentials_file = "P:/COMUM/FALCAO/30. EBB/09. Analistas ODC+CS+MS/br-apps-atendimentodva-qa-6ef8f7a85d97.json"
credentials = service_account.Credentials.from_service_account_file(credentials_file)
client = dataform.DataformClient(credentials=credentials)

project_id = "br-apps-atendimentodva-qa"
location = "us-central1"
repository_id = "Jasper"

# 创建WorkflowInvocation对象并配置过滤规则
workflow_invocation = dataform.WorkflowInvocation()
workflow_invocation.compilation_result = "projects/497423421340/locations/us-central1/repositories/Jasper/compilationResults/604852d3-665a-475a-9a39-fd5a247c1fbf"

# 配置执行过滤:仅运行带有指定标签的任务
invocation_config = dataform.WorkflowInvocationConfig()
# 替换成你要执行的标签,多个标签可以添加到列表中
invocation_config.included_tags.append("your-target-tag")
# 如果需要自动运行依赖任务,保持transitive_dependencies=True;若仅运行标签本身,设为False
invocation_config.transitive_dependencies = True

workflow_invocation.invocation_config = invocation_config

parent = f"projects/{project_id}/locations/{location}/repositories/{repository_id}"

request = dataform.CreateWorkflowInvocationRequest(
    parent=parent,
    workflow_invocation=workflow_invocation,
)

response = client.create_workflow_invocation(request=request,)

关键说明:

  • included_tags:指定要执行的任务标签,列表中可以添加多个标签,只有带这些标签的任务会被纳入执行范围。
  • transitive_dependencies:设为True时,会自动运行目标任务的依赖任务;设为False则仅运行带有指定标签的任务本身,不处理依赖。
  • 确保你的Dataform代码中,目标任务已经正确添加了对应的标签(比如在SQLX文件中用tags: ["your-target-tag"]声明)。

内容的提问来源于stack exchange,提问作者Guilherme FERREIRA

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 00:45:06