我在雪花数据库中有两个表。一个是手动生成的(表 1),另一个是使用 DBT 模型生成的(表 2)。这两个表中的记录数应该相同。我正在尝试编写一个 DBT 测试来为我进行比较。
但是,我的测试一直返回编译错误:
“测试 record_count_prontoform_prod_lptr_grower_prontoform_prod_lptr_grower__LPTR_GROWER_RAW_SUBMISSIONS__RAW_SUBMISSIONS (models\marts\schema_prontoform_prod_lptr_plant.yml) 中的编译错误,宏‘dbt_macro__test_record_count’没有关键字参数‘model’”
我在 DBT 项目中写了以下测试:
SQL 文件名:test_record_count.sql
-- count_match_test.sql
{% test record_count(source_name, source_table, model_name) %}
WITH
table1_count AS (
SELECT COUNT(*) AS count FROM {{ source(source_name, source_table) }}
),
table2_count AS (
SELECT COUNT(*) AS count FROM {{ ref(model_name) }}
)
SELECT
CASE WHEN t1.count = t2.count THEN 'pass'
ELSE RAISE_ERROR('Record count mismatch between ' || source_name || ' and ' || model) END AS test_result
FROM table1_count t1
JOIN table2_count t2 ON t1.count = t2.count
{% endtest %}
Schema.yml
- name: prontoform_prod_lptr_grower
description: 'Mapping ids to question labels'
data_tests:
- record_count:
source_name: "LPTR_GROWER_RAW_SUBMISSIONS"
source_table: "RAW_SUBMISSIONS"
model_name: "prontoform_prod_lptr_grower"
columns:
- name: submission_id
description: 'submission_id of form'
data_tests:
- not_null
- unique
- name: question_id
description: 'Unique question ID used for mapping'
data_tests:
- not_null
- name: question_label
description: 'The label of the question'
data_tests:
- not_null
测试运行:
(dbt_venv) PS C:\prontoforms_dbt\dbt-snowflake> dbt test --select prontoform_prod_lptr_grower 23:37:52 使用 dbt=1.8.6 运行 23:37:52 注册适配器:snowflake=1.8.3 23:37:53 遇到错误:测试 record_count_prontoform_prod_lptr_grower_prontoform_prod_lptr_grower__LPTR_GROWER_RAW_SUBMISSIONS__RAW_SUBMISSIONS (models\marts\schema_prontoform_prod_lptr_plant.yml) 中的编译错误 宏'dbt_macro__test_record_count' 不需要关键字参数'model' (dbt_venv) PS C:\prontoforms_dbt\dbt-snowflake>