<@U088WCP3B4P> dbt的新鲜度检测,哪些参数的必填项?
# ask-elementary-ai
l
@kapa.ai dbt的新鲜度检测,哪些参数的必填项?
k
A message from kapa.ai
dbt 的新鲜度检测(freshness anomalies)在 Elementary 中,必填参数是 `timestamp_column`。这个参数用于指定表中用于检测新鲜度的时间戳字段。配置示例如下:
Copy code
yaml models:   - name: <model name>     tests:       - elementary.freshness_anomalies:           timestamp_column: <timestamp column> # 必填
其他参数如 `where_expression`、`time_bucket`、`anomaly_sensitivity` 等都是可选项,可以根据实际需求进行配置,但不是必填项。默认情况下,时间分桶(time_bucket)为每日(daily),也可以自定义。 详细说明可参考官方文档:[freshness_anomalies](https://docs.elementary-data.com/data-tests/anomaly-detection-tests/freshness-anomalies)https://docs.elementary-data.com/data-tests/anomaly-detection-tests/freshness-anomalies
l
@kapa.ai 我是说dbt原生的新鲜度检测
k
A message from kapa.ai
关于 dbt 原生的新鲜度检测(source freshness),根据现有知识源,**必填参数**是在 source 的配置文件(如 `schema.yml`)中为每个 source table 配置
freshness
字段。具体来说,`freshness` 下需要指定
warn_after
或 `error_after`,用于定义新鲜度的阈值。例如:
Copy code
yaml sources:   - name: my_source     tables:       - name: my_table         freshness:           warn_after: {count: 12, period: hour}           error_after: {count: 24, period: hour}
其中,`warn_after` 和
error_after
至少需要配置一个,否则 dbt 不会对该表进行新鲜度检测。 总结: - 必填项:`freshness` 字段下的
warn_after
或 `error_after`(至少一个)。 - 这些参数需配置在 source 的 yml 文件中。 此结论来自于对相关 Elementary 社区问答的梳理,明确指出 source freshness 应该定义在 source 的 schema.yml 文件中,并参考了 dbt 官方文档说明参数配置方式[见此处](https://docs.getdbt.com/reference/resource-properties/freshness)https://slack.com/archives/C02CTC89LAX/p1669297028707749。