单数/数据测试缺少DBT中的test_metadata

发布于 2025-02-04 18:14:12 字数 1417 浏览 3 评论 0原文

我正在尝试在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

凉城凉梦凉人心 2025-02-11 18:14:12

这似乎是该软件包的错误。我将在dbt-constraints repo中打开一个问题。没有记录的方法可以将元数据添加到单数测试中,但是该代码假定所有测试都具有test_metadata.name

我怀疑这会起作用,但是如果您将schema.yml文件添加到tests目录以及您的单数测试以及您的单数测试以及您的单数测试时会发生什么?内容看起来像:

version: 2
tests:
  - name: table_a_test

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 have test_metadata.name.

I doubt this would work, but what happens if you add a schema.yml file to the tests directory, alongside your singular test? The contents would look like:

version: 2
tests:
  - name: table_a_test
随梦而飞# 2025-02-11 18:14:12

听起来您的呼叫应该是DBT测试 - 选择table_a_test而不是dbt Test-select tablea。我认为,您需要调用测试名称,而不是表名,该名称已在(单数)测试中已经进行了硬编码。那起作用吗?

sounds like your call should be dbt test —-select table_a_test instead of dbt 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?

江南月 2025-02-11 18:14:12

您是否尝试在其前面使用 +标志进行测试?由于您在测试中使用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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文