-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document group by example for Soda Core with failed rows check (#1984)
* Added group by example for Soda Core with failed rows check * Adjusted SQL per suggestion * Corrected SQL
- Loading branch information
Showing
5 changed files
with
42 additions
and
9 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Group check results by category with Soda Core | ||
|
||
You can use a SQL query in a failed row check to group failed check results by one or more categories using Soda Core. | ||
|
||
Use a SQL editor to build and test a SQL query with your data source, then add the query to a failed rows check to execute it during a Soda scan. | ||
|
||
The following example illustrates how to build a query that identifies the countries where the average age of people is less than 25. | ||
|
||
1. Begining with a basic query, the output shows the data this example works with. | ||
```sql | ||
SELECT * FROM Customers; | ||
``` | ||
{:height="600px" width="600px"} | ||
2. Build a query to select groups with the relevant aggregations. | ||
```sql | ||
SELECT country, AVG(age) as avg_age | ||
FROM Customers | ||
GROUP BY country | ||
``` | ||
{:height="600px" width="600px"} | ||
3. Identify the "bad" group (where the average age is less than 25) from among the grouped results. | ||
```sql | ||
SELECT country, AVG(age) as avg_age | ||
FROM Customers | ||
GROUP BY country | ||
HAVING AVG(age) < 25 | ||
``` | ||
{:height="600px" width="600px"} | ||
4. Now that the query yields the expected results, add the query to a failed row check, as per the following example. | ||
```yaml | ||
checks for dim_customers: | ||
- failed rows: | ||
name: Average age of citizens is less than 25 | ||
fail query: | | ||
SELECT country, AVG(age) as avg_age | ||
FROM Customers | ||
GROUP BY country | ||
HAVING AVG(age) < 25 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c3c9521
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be great to have one check result for each failed group having the fields of the group by clause informed as attributes or similar.