Loading...
Loading...
Compare original and translation side by side
undefinedundefined
**Extract from existing tests:**
- YAML formatting style (indentation, spacing)
- Test coverage depth (all columns vs key columns only)
- Use of custom tests (dbt_utils, dbt_expectations, custom macros)
- Description style (brief vs detailed)
- Severity levels used (warn vs error)
**从现有测试中提取以下信息:**
- YAML格式风格(缩进、间距)
- 测试覆盖深度(所有列 vs 仅关键列)
- 自定义测试的使用情况(dbt_utils、dbt_expectations、自定义宏)
- 描述风格(简洁 vs 详细)
- 使用的严重级别(warn vs error)cat models/<path>/<model_name>.sqlcat models/<path>/<model_name>.sqlcat models/<path>/schema.yml | grep -A 50 "<model_name>"cat models/<path>/schema.yml | grep -A 50 "<model_name>"undefinedundefined| Column Type | Recommended Tests |
|---|---|
| Primary key | |
| Foreign key | |
| Categorical | |
| Required field | |
| Date/timestamp | |
| Boolean | |
| 列类型 | 推荐测试 |
|---|---|
| 主键 | |
| 外键 | |
| 分类列 | |
| 必填字段 | |
| 日期/时间戳 | |
| 布尔值 | |
version: 2
models:
- name: model_name
description: "Brief description of what this model contains"
columns:
- name: primary_key_column
description: "Unique identifier for this record"
tests:
- unique
- not_null
- name: foreign_key_column
description: "Reference to related_model"
tests:
- not_null
- relationships:
to: ref('related_model')
field: related_key_column
- name: status
description: "Current status of the record"
tests:
- not_null
- accepted_values:
values: ['pending', 'active', 'completed', 'cancelled']
- name: created_at
description: "Timestamp when record was created"
tests:
- not_nullversion: 2
models:
- name: model_name
description: "Brief description of what this model contains"
columns:
- name: primary_key_column
description: "Unique identifier for this record"
tests:
- unique
- not_null
- name: foreign_key_column
description: "Reference to related_model"
tests:
- not_null
- relationships:
to: ref('related_model')
field: related_key_column
- name: status
description: "Current status of the record"
tests:
- not_null
- accepted_values:
values: ['pending', 'active', 'completed', 'cancelled']
- name: created_at
description: "Timestamp when record was created"
tests:
- not_nullundefinedundefinedundefinedundefined| Failure | Likely Cause | Fix |
|---|---|---|
| Duplicate records | Add deduplication in model |
| NULL values in source | Add COALESCE or filter |
| Orphan records | Add WHERE clause or fix upstream |
| New/unexpected values | Update accepted values list |
| 失败类型 | 可能原因 | 修复方案 |
|---|---|---|
| 存在重复记录 | 在模型中添加去重逻辑 |
| 源数据中存在NULL值 | 添加COALESCE函数或过滤条件 |
| 存在孤立记录 | 添加WHERE子句或修复上游数据 |
| 出现新的/未预期的值 | 更新有效值列表 |
tests:
- unique
- not_null
- accepted_values:
values: ['a', 'b', 'c']
- relationships:
to: ref('other_model')
field: idtests:
- unique
- not_null
- accepted_values:
values: ['a', 'b', 'c']
- relationships:
to: ref('other_model')
field: idtests:
- dbt_utils.expression_is_true:
expression: "amount >= 0"
- dbt_utils.recency:
datepart: day
field: created_at
interval: 1tests:
- dbt_utils.expression_is_true:
expression: "amount >= 0"
- dbt_utils.recency:
datepart: day
field: created_at
interval: 1tests/<test_name>.sql-- tests/assert_positive_revenue.sql
select *
from {{ ref('orders') }}
where revenue < 0tests/<test_name>.sql-- tests/assert_positive_revenue.sql
select *
from {{ ref('orders') }}
where revenue < 0