Skip to main content

Failed Rows Sample

When a test fails, you often need to see the rows that caused the failure. The failed rows sample is a small table of those rows. It appears on the test case page, so you can inspect bad data without leaving OpenMetadata. The failed rows sample is part of OpenMetadata. It is not limited to Collate.

Where You See It

OpenMetadata fills the sample on its own for tests that it runs itself, such as tests you create in the UI or in a data quality workflow. Open the test case page and stay on the Test Case Results tab. Scroll to the Sample Data section. It shows the failed rows, and it highlights the column that failed the test. Sample Data section on the test case page showing failed rows with the failing last_name column highlighted Only tests that find failed rows, such as Column Values To Be Unique or Column Values To Be Not Null, show this section. Tests that return a single measured value, such as Table Column Count To Equal, don’t. OpenMetadata keeps the sample when a test fails, and when a test passes within its failure threshold but still finds failed rows. For more information, see Failed Rows Samples.

dbt and Externally Run Tests

OpenMetadata doesn’t fill the sample for tests it only imports, such as dbt tests. The imported result tells OpenMetadata that a test failed, but not which rows. You can add those rows yourself through the API. Use this for any result that comes from outside OpenMetadata.

Before You Start

  • The test case must already exist in OpenMetadata. For dbt, run the dbt workflow so the tests are imported. dbt tests appear in OpenMetadata under the name of the dbt test.
  • The test case’s latest result must have failed rows. This means the result is Failed, or it’s Success with at least one failed row. If it isn’t, the API returns Failed rows can only be added to a test case whose latest result has failed rows.
  • Your user or bot needs the permission to edit tests. To read the sample, it needs the permission to view failed rows samples.

Add the Sample

Send a PUT request to the test case:
Send a request body like the following:
The API has no limit on the number of rows. Send a small sample, because OpenMetadata stores what you send and shows it in the UI. To get the test case id, look the test case up by its fully qualified name:
The id is in the response. To read or remove a sample, use GET or DELETE on the same /api/v1/dataQuality/testCases/{id}/failedRowsSample path.

Example: dbt Failed Rows

dbt can store the rows that fail a test in a table in your warehouse. Turn it on with store_failures in your dbt project. dbt then records that table’s name in run_results.json, in the relation_name field of each test result. A common setup adds one step after the dbt run and its import into OpenMetadata. For example, an Airflow task that:
  1. Reads run_results.json and picks the tests with the status fail.
  2. Reads a sample of rows from each failed test’s relation_name table.
  3. Finds the matching OpenMetadata test case and calls the API above.
The following Python script shows the idea. Replace the host, token, and the TEST_CASE_FQNS map with your own values, and swap read_failed_rows for a query against your warehouse.
Run this step only after the dbt workflow has imported the latest results. If the test case’s latest result in OpenMetadata is still an older passing result, the API rejects the sample.
Failed rows can contain sensitive data. The sample shows the values you send. Review who can open the test case before you send rows from tables that hold personal data.