英文:
How validate one column which values depend on another one for DBT
问题
我想在我的模型中添加测试以验证依赖于"TYPE"列的"subtype"值。
version: 2
models:
- name: my_table
description: my_table
columns:
- name: TYPE
description: "-"
tests:
- accepted_values:
values: ["1", "2", "3", "4"]
severity: error
现在的想法是验证"subtype",例如,如果"TYPE"是1,那么"subtype"只能是3或4,如果"TYPE"是2,那么"subtype"的允许值是1、5等等。
在此提前表示感谢。
英文:
I want to add test in my model to validate the values of subtype which depends on values of type column.
version: 2
models:
- name: my_table
description: my_table
columns:
- name: TYPE
description: "-"
tests:
- accepted_values:
values: ["1", "2", "3", "4"]
severity: error
Now, the idea is validate subtype , where ,for example, if the type is 1, the subtype only could be 3 or 4, if the type is 2, the allowed values for subtype are 1, 5, etc.
It is possible, thanks in advance.
答案1
得分: 2
你应该能够向 subtype
添加不同的测试,以便当 type
等于某个值时,subtype
的 accepted_values
应该是另一个值数组。
因此,例如:
version: 2
models:
- name: my_table
description: my_table
columns:
- name: TYPE
description: "-"
tests:
- accepted_values:
values: ["1", "2", "3", "4"]
severity: error
- name: SUBTYPE
description: ""
tests:
- accepted_values:
name: subtype_accepted_values_when_type_equals_1
values: ["3", "4"]
config:
where: "type = 1"
- accepted_values:
name: subtype_accepted_values_when_type_equals_2
values: ["1", "5"]
config:
where: "type = 2"
英文:
You should be able to add different tests to subtype
, so that when type
is equal to a value, the accepted_values
of subtype
should be another array of values.
So, for instance:
version: 2
models:
- name: my_table
description: my_table
columns:
- name: TYPE
description: "-"
tests:
- accepted_values:
values: ["1", "2", "3", "4"]
severity: error
- name: SUBTYPE
description: ""
tests:
- accepted_values:
name: subtype_accepted_values_when_type_equals_1
values: ["3", "4"]
config:
where: "type = 1"
- accepted_values:
name: subtype_accepted_values_when_type_equals_2
values: ["1", "5"]
config:
where: "type = 2"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论