GitHub

Custom SQL Queries

Execute custom analytical queries against historical SQLite and DuckDB datasets.

The zr history query command allows data engineers and QA leads to run arbitrary SQL queries directly against historical test execution data using DuckDB.


Usage

Terminal window
npx zr history query "<SQL_QUERY>"

Interactive Output

By default, query results are formatted into an aligned ASCII terminal table:

Terminal window
npx zr history query "SELECT project_name, COUNT(*) as total_runs, AVG(duration_ms)/1000 as avg_sec FROM runs GROUP BY project_name"
+---------------------+------------+---------+
| project_name | total_runs | avg_sec |
+---------------------+------------+---------+
| Web App E2E | 142 | 18.4 |
| API Integration | 89 | 4.2 |
+---------------------+------------+---------+

Exporting Query Results to CSV

Append --export [filename] to write query results directly to a CSV spreadsheet:

Terminal window
npx zr history query "SELECT test_id, title, file_path, retry_count FROM tests WHERE status = 'flaky'" --export flaky-audit.csv

Common Analytical SQL Recipes

1. Top 10 Most Frequent Failure Signatures

SELECT
error_message,
COUNT(*) as occurrences
FROM test_results
WHERE status = 'failed'
GROUP BY error_message
ORDER BY occurrences DESC
LIMIT 10;

2. Slowest Test Specs by P95 Duration

SELECT
file_path,
COUNT(*) as executions,
ROUND(PERCENTILE_CONT(0.95) WITHIN GROUP (ORDER BY duration_ms) / 1000, 2) as p95_seconds
FROM test_results
GROUP BY file_path
ORDER BY p95_seconds DESC
LIMIT 15;