Fix the result diff for a query rewrite

Review the AI's codeEasy12 minDatabricks and Anthropic style

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 is key|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 | gives malformed:<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_rows gives duplicate_baseline:<key>, once per key. In candidate_rows it gives duplicate_candidate:<key>.
  • For each key in baseline_rows, take the value of its first row there and the value of its first row in candidate_rows:
    • no row in candidate_rows has that key: missing:<key>
    • the values differ: value:<key>:<baseline value>:<candidate value>
  • A key in candidate_rows with no row in baseline_rows gives extra:<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
Inputdiff_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
Inputdiff_result_sets(["a|1", "b|2", "c|3"], ["a|1", "b|9", "d|3"])
Output["extra:d", "missing:c", "value:b:2:9"]