Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Route failed rows to your warehouse

Store the rows that fail your checks in your own PostgreSQL database with the Diagnostics Warehouse, so Soda Cloud receives the check results but not the rows.

When a check fails, the rows behind the failure show you what to fix. If the data is sensitive, you may want those rows to stay in your own infrastructure. With the Diagnostics Warehouse, Soda Core writes the failed rows to a database you control, and Soda Cloud receives only the check results.

In this guide, a contract checks the fact_internet_sales table in a PostgreSQL database, sales. The failed rows go to a second database on the same server, quality. You run the verification with Soda Core, then query the failed rows with SQL.

The Diagnostics Warehouse and the private PyPI are available on license plans. Need access? Contact us.

Prerequisites

  • Python 3.10 or later, and psql to query the results.

  • A Soda Cloud account and an API key. See Generate API keys.

  • To publish results for a new data source, the global permission Create new datasets and data sources with Core/Library. To turn on the Diagnostics Warehouse, the Manage datasource settings permission on the data source and Configure dataset on the dataset. See Global and dataset roles.

  • A PostgreSQL user that reads the sales database, and a user that can create schemas, tables, and views in the quality database and write to them. See Diagnostics Warehouse required permissions.

Install Soda

The Diagnostics Warehouse is part of the soda package on the private PyPI. Install it with the package for PostgreSQL. The index takes your Soda Cloud API key as the credentials, from the environment variables SODA_CLOUD_API_KEY_ID and SODA_CLOUD_API_KEY_SECRET. This example uses the US region; for the EU region, use enterprise.pypi.cloud.soda.io.

pip install "soda>=4" "soda-postgres>4" \
  -i "https://${SODA_CLOUD_API_KEY_ID}:${SODA_CLOUD_API_KEY_SECRET}@enterprise.pypi.us.soda.io" \
  --extra-index-url=https://pypi.cloud.soda.io/simple

For the index of your license and region, see Soda Python libraries.

Connect Soda Core

Create a data source configuration file for the data that the contract checks. The name becomes the name of the data source in Soda Cloud. The values in ${env.…} are read from environment variables.

Create a second configuration file for the Diagnostics Warehouse. It connects to the quality database.

Create a Soda Cloud configuration file. Use cloud.us.soda.io or cloud.soda.io, depending on your Soda region.

Test the three connections:

For every connection parameter, see PostgreSQL.

Write the contract

The contract checks that every sale has an order number, a product, and an amount above zero. The missing, duplicate, and failed_rows checks evaluate the table row by row, so their failed rows can be stored. Aggregate checks, such as row_count, have no failed rows.

Check that the contract is valid:

For the check types that store failed rows, see Which check types produce failed rows?

Publish the first results

Soda Core reads the Diagnostics Warehouse settings of the dataset from Soda Cloud, so the data source and the dataset must exist there first. Verify the contract and publish the results:

-dw points to the Diagnostics Warehouse configuration file. Soda Cloud creates the data source orders_postgres and the dataset fact_internet_sales. The Diagnostics Warehouse is not on yet, so the output ends with Skipping failed rows extraction: Diagnostics not enabled.

Turn on the Diagnostics Warehouse

The settings live in Soda Cloud: the data source decides where Soda writes and whether it collects failed rows, and the dataset decides how to store them. The following script sets both through the Soda Cloud API. It reads the API key from the same environment variables as sc_config.yml, and uses the requests package, which Soda installs. For the EU region, set API to https://cloud.soda.io/api/v1.

The script makes these settings:

Setting
Value
Effect

reuseDatasource

false

Soda writes to a different connection, the quality database, instead of the database it checks. Soda Cloud requires the connection in configurationFileContents.

scanAndResultsConfiguration.enabled

true

Soda stores the scans and check results.

failedRowsConfiguration.enabled

true

Soda collects failed rows for the datasets of the data source that have it on.

exposeQueries

true

The Failed Rows tab of a check in Soda Cloud offers the SQL queries that read its failed rows.

locationMessage

Text

The message the Failed Rows tab shows instead of the rows.

storageStrategy

fullFailedRows

Soda stores the keys of the failed rows and full copies of the rows. With uniqueKeys, Soda stores only the keys.

uniqueKeyColumnNames

["sales_order_number"]

The columns that identify a row. Without unique keys, Soda does not store failed rows.

The data source request replaces the stored configuration, so a field you leave out is cleared.

The script prints the configuration that applies to the dataset. failedRowSamples is off, so Soda sends no sample of the failed rows to Soda Cloud:

Failed row samples are an opt-in feature that copies a sample of the failed rows to Soda Cloud. When your organization has them, leave Allow sending failed row samples to Soda Cloud cleared in the Diagnostics Warehouse settings of the data source. See Failed row samples.

In Soda Cloud, the dataset's Settings tab shows the result under Diagnostics Warehouse Configuration: Collect failed rows is on, with the storage strategy Store full failed rows and the unique key sales_order_number. You can change these settings there and click Save diagnostics warehouse.

The Diagnostics Warehouse Configuration of fact_internet_sales, with Collect check results and scans and Collect failed rows on, the storage strategy Store full failed rows, and the unique key sales_order_number
Diagnostics Warehouse settings of the dataset

To make the same settings in the Soda Cloud interface, or to use the same connection as the data source, see Configure Diagnostics Warehouse.

Store failed rows

A sale with an amount of zero arrives in fact_internet_sales. Run the same command again:

The check All sales have a non-zero order amount fails, and the command exits with code 1. After it sends the results to Soda Cloud, Soda Core connects to the quality database, creates its default schema, soda_diagnostics, and stores the failed row:

Soda writes the Diagnostics Warehouse only when you publish the results with --publish.

Query the failed rows

Soda stores the failed rows of each dataset in two tables, named after the dataset ID without hyphens:

  • fk_<dataset_id>: the unique keys of the failed rows, one row per failed row and check.

  • fr_<dataset_id>: a full copy of each failed row, once per scan.

Each table has a view with the same name, without the version suffix _v0000. The check_results table lists the views of each check. List the checks that failed:

To read the rows, join the two views with the check results and the scans. Replace <dataset_id> with the ID from the view names.

Later scans add their failed rows to the same tables as long as the table's columns and the unique keys stay the same, so the query also shows when a row failed before.

For every table and column, see Diagnostics Warehouse data model.

Check results in Soda Cloud

In Soda Cloud, open the dataset's Checks tab and click the failed check. The Failed Rows tab shows Failed rows are stored externally with the location message instead of the rows. View Failed Rows Queries shows the SQL queries that read the rows from the quality database.

The Failed Rows tab of the check All sales have a non-zero order amount, with the message Failed rows are stored externally, the location message, and the button View Failed Rows Queries
The Failed Rows tab of the failed check

Next steps

Last updated

Was this helpful?