如何在dbt build时排除post_binary标签测试并分阶段执行测试?
分阶段执行dbt构建与外部二进制流程的实现方案
你可以通过拆分dbt命令和外部二进制执行步骤,实现预期的工作流:
构建目标模型并运行非
post_binary测试
用dbt build指定要处理的模型,同时排除标记为post_binary的测试:dbt build --select model1 model2 --exclude tag:post_binary执行外部二进制文件更新字段
直接运行你的二进制程序(替换成实际的二进制文件路径):./your_update_binary运行
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
相关产品推荐
相关产品推荐

