单数/数据测试缺少DBT中的test_metadata
我正在尝试在DBT中设置一个单数测试(这是一个特定表的测试 - tablea
),所以我写了一个SQL查询,我将其放置在tests tests
文件夹中。它返回失败的行。 但是,当我运行dbt测试时 - 选择tablea
,如果测试通过(没有失败记录),我会收到以下错误:
14:20:57 Running dbt Constraints
14:20:58 Database error while running on-run-end
14:20:59 Encountered an error:
Compilation Error in operation dbt_constraints-on-run-end-0 (./dbt_project.yml)
'dbt.tableA.graph.compiled.CompiledSingularTestNode object' has no attribute 'test_metadata’
如果测试失败,它将返回失败的行,正确的行为。
我正在使用dbt_constraints
软件包(v0.3.0),它似乎正在引起此问题,特别是该脚本在运行式挂钩 https://github.com/snowflake-labs/snowflake-labs/dbt_constraints/dbt_constraints/blob/main/main/mmain/main/main/main/createconts.ssssssssssssssssssss.ssssss.sssss.ssssss.sql
我猜我需要在单数测试中添加一些测试元数据,但不确定如何做。
这是测试的外观
tests/table_a_test.sql
SELECT *
FROM {{ ref('TableA') }}
WHERE param_1 NOT IN
(SELECT TableB_id
FROM {{ ref('TableB') }}
UNION
SELECT TableC_id
FROM {{ ref('TableC') }}
UNION
SELECT TableD_id
FROM {{ ref('TableD') }}
UNION
SELECT TableE_id
FROM {{ ref ('TableE') }} )
and param_2 is null
谢谢!
I am trying to setup a singular test in dbt (it’s a test for one specific table - TableA
), so I wrote an SQL query which I placed in tests
folder. It returns failing rows.
However, when I run dbt test —-select tableA
, in case the test passes (no failing records), I get the following error:
14:20:57 Running dbt Constraints
14:20:58 Database error while running on-run-end
14:20:59 Encountered an error:
Compilation Error in operation dbt_constraints-on-run-end-0 (./dbt_project.yml)
'dbt.tableA.graph.compiled.CompiledSingularTestNode object' has no attribute 'test_metadata’
In case the test fails, it returns the failing rows, which is correct behaviour.
I am using dbt_constraints
package (v0.3.0), which seems to be causing this problem, specifically this script which runs in the on-run-end hook https://github.com/Snowflake-Labs/dbt_constraints/blob/main/macros/create_constraints.sql
I am guessing I need to add some test metadata to the singular test, but not sure how to do it.
Here is what the test looks like
tests/table_a_test.sql
SELECT *
FROM {{ ref('TableA') }}
WHERE param_1 NOT IN
(SELECT TableB_id
FROM {{ ref('TableB') }}
UNION
SELECT TableC_id
FROM {{ ref('TableC') }}
UNION
SELECT TableD_id
FROM {{ ref('TableD') }}
UNION
SELECT TableE_id
FROM {{ ref ('TableE') }} )
and param_2 is null
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这似乎是该软件包的错误。我将在
dbt-constraints
repo中打开一个问题。没有记录的方法可以将元数据添加到单数测试中,但是该代码假定所有测试都具有test_metadata.name
。我怀疑这会起作用,但是如果您将
schema.yml
文件添加到tests
目录以及您的单数测试以及您的单数测试以及您的单数测试时会发生什么?内容看起来像:This seems to be a bug in that package; I would open an issue in the
dbt-constraints
repo. There is no documented way to add metadata to a Singular test, but that code assumes that all tests will havetest_metadata.name
.I doubt this would work, but what happens if you add a
schema.yml
file to thetests
directory, alongside your singular test? The contents would look like:听起来您的呼叫应该是
DBT测试 - 选择table_a_test
而不是dbt Test-select tablea
。我认为,您需要调用测试名称,而不是表名,该名称已在(单数)测试中已经进行了硬编码。那起作用吗?sounds like your call should be
dbt test —-select table_a_test
instead ofdbt test —-select tableA
. I think, you need to call the test name not the table name, which is already hard coded in the (singular) test. does that work?您是否尝试在其前面使用 +标志进行测试?由于您在测试中使用
ref
,因此您可能需要在测试前构建所有内容。Have you tried to run the test with a + sign in front of it? Since you are using
ref
in the test, you might need to build everything before test.