Skip to main content
Validates referential integrity between two tables: every value in the tested table must exist in a target table. Use it for foreign keys, such as orders that reference customers, or events that reference users. This is a SQL data test: Elementary runs it against your warehouse on a schedule, with no SQL to write and no pull request.
SQL-based cloud tests read table data, so they need data access for the environment’s warehouse connection. Data access is enabled in one of two ways:
  • Elementary enables data access on the warehouse connection. Contact the Elementary team to turn it on.
  • You connect an Elementary Runtime to the warehouse connection.
Until data access is available, these tests are hidden from the test catalog.

How it works

On each run, Elementary returns every row of the tested table whose value has no equal value in the target table’s target field. Each failing row is one row of the tested table, and the row sample contains the full rows.
  • Null source values are ignored. A row with a null value in the tested field never fails. To require a value, add a completeness test.
  • The where clause applies to the tested table only. All rows of the target table are used as valid values.
  • Both tables must use the same warehouse connection, and the target table must be an asset in the Elementary Catalog.
Results count toward the Consistency data quality dimension.

Configuration

Relationship test configuration with the tested field, target table, and target field set to columns

Relationship test configuration

Severity, thresholds, sampled rows, and cadence work the same for all SQL data tests. See Configuration. The test is linked to the tested table: it appears on that table in the Catalog, and its incidents are grouped there.

Examples

If the target table is updated later than the tested table, new rows can fail until the target catches up. Schedule the test after both tables load, or use a where clause to skip the most recent rows, for example created_at < current_date.

dbt equivalent

The dbt relationships test checks the same rule from your dbt project. See Cloud tests or dbt tests to decide which to use.