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

如何在dbt build时排除post_binary标签测试并分阶段执行测试?

分阶段执行dbt构建与外部二进制流程的实现方案

你可以通过拆分dbt命令和外部二进制执行步骤,实现预期的工作流:

  1. 构建目标模型并运行非post_binary测试
    用dbt build指定要处理的模型,同时排除标记为post_binary的测试:

    dbt build --select model1 model2 --exclude tag:post_binary
    
  2. 执行外部二进制文件更新字段
    直接运行你的二进制程序(替换成实际的二进制文件路径):

    ./your_update_binary
    
  3. 运行post_binary标签的测试
    单独调用dbt test,只筛选标记了post_binary的测试用例:

    dbt test --select tag:post_binary
    

测试标签配置说明

确保你的测试在dbt的配置文件(如schema.yml)里正确标记了post_binary标签,示例如下:

models:
  - name: model1
    columns:
      - name: updated_field
        tests:
          - not_null:
              tag: post_binary
          - accepted_values:
              values: ['active', 'inactive']
              tag: post_binary
  - name: model2
    tests:
      - unique:
          tag: post_binary

如果需要批量执行这些步骤,可以写一个shell脚本(适用于Linux/macOS):

#!/bin/bash

# 构建模型并运行非post_binary测试
dbt build --select model1 model2 --exclude tag:post_binary

# 检查dbt命令执行状态,失败则退出
if [ $? -ne 0 ]; then
    echo "dbt build failed, exiting..."
    exit 1
fi

# 执行外部二进制文件
./your_update_binary

# 检查二进制执行状态,失败则退出
if [ $? -ne 0 ]; then
    echo "Binary update failed, exiting..."
    exit 1
fi

# 运行post_binary测试
dbt test --select tag:post_binary

内容的提问来源于stack exchange,提问作者Ajmal Moideen

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 17:22:09