Fix the result diff for a query rewrite
Your task
An AI agent rewrote three reporting queries around a new window function and says the results are the same, only faster. Before a multi-hour migration on the warehouse, you run the old and new queries on a sample and diff the two result sets.
An assistant wrote diff_result_sets(baseline_rows, candidate_rows). It is in the editor. It has a bug. Find it and fix it.
Input and output:
baseline_rows: the old query's rows.candidate_rows: the new query's rows. Each row iskey|value.- Return the findings, sorted. An empty list means the results match.
Rules the tests check:
- The key is the text before the first
|, and the value is everything after it, so a value may contain|. Either one may be empty. - A row with no
|givesmalformed:<row>, on either side, once for each such row. - Row order does not matter. Rows are compared by key.
- A key that appears more than once in
baseline_rowsgivesduplicate_baseline:<key>, once per key. Incandidate_rowsit givesduplicate_candidate:<key>. - For each key in
baseline_rows, take the value of its first row there and the value of its first row incandidate_rows:- no row in
candidate_rowshas that key:missing:<key> - the values differ:
value:<key>:<baseline value>:<candidate value>
- no row in
- A key in
candidate_rowswith no row inbaseline_rowsgivesextra:<key>, once per key. - Sort all findings by plain string comparison before returning them.
Examples
diff_result_sets(baseline_rows: list[str], candidate_rows: list[str]) -> list[str]Example 1
Input
diff_result_sets(["2026-01-01|100", "2026-01-02|250", "2026-01-03|75"], ["2026-01-01|100", "2026-01-02|250", "2026-01-03|75"])Output
[]Example 2
Input
diff_result_sets(["a|1", "b|2", "c|3"], ["a|1", "b|9", "d|3"])Output
["extra:d", "missing:c", "value:b:2:9"]