dbt hub

dbt test: at_least_one

USE CASE

Completeness

APPLIES TO

Model
Column

This page explains the at_least_one test from the dbt-utils package. This test is designed to ensure that a specified column in your database contains at least one non-null value. It's a fundamental check for data completeness and integrity, particularly useful in scenarios where certain data points are critical for business processes or reporting.

How it Works

The at_least_one test checks a specified column to confirm that it contains at least one non-null value. This is crucial for columns that are expected to have data for every record or at least one record in a dataset or within specific groupings of data.

Steps and Conditions:

  1. Column Selection: Identify the column you want to test for the presence of at least one non-null value.
  2. Execution: The test scans the specified column across all records (or within defined groupings if the group_by_columns parameter is used).
  3. Outcome:
    • Pass: If the column contains at least one non-null value, the test passes, indicating that the minimum data presence requirement is met.
    • Fail: If the column does not contain any non-null values, the test fails, highlighting a potential issue with data collection or processing that needs to be addressed.

Example Usage: Fintech Company

For a Fintech company, ensuring that transactional data is complete and accurate is essential for maintaining trust and compliance. The at_least_one test can be applied to various columns in the transactions table to ensure critical data points are present.

Consider a scenario where the transactions table records details of user transactions, including transaction IDs, amounts, and timestamps.


models:
  - name: transactions
    columns:
      - name: transaction_id
        tests:
          - dbt_utils.at_least_one

      - name: amount
        tests:
          - dbt_utils.at_least_one

      - name: transaction_timestamp
        tests:
          - dbt_utils.at_least_one

In this example, the at_least_one test is used to ensure that:

  • There is at least one recorded transaction ID, amount, and timestamp.
  • These tests help in verifying that the transactions table is not empty and contains essential data for each transaction.

The only data observability platform built into your dbt code

  • Get monitors on your production tables out-of-the-box with zero configuration
  • Add tests to your code in bulk with a simple UI
  • Track test results over time
  • Set owners and create meaningful alerts
  • Triage incidents faster using our end-to-end column-level lineage graph