Where-clause predicate tree

Write codeHard30 minSnowflake and Databricks style

Your task

Evaluate a WHERE-clause predicate tree against rows. A predicate node is either a comparison ['cmp', col, op, value] with op in '=','!=','>','<','>=','<=', or a boolean ['and', child1, child2, ...] / ['or', child1, child2, ...] / ['not', child]. Given rows (list of dicts) and one predicate, return the list of rows (in input order) for which the predicate evaluates to true. Comparisons use Python's natural ordering on the stored values. 'and' of zero children is true; 'or' of zero children is false.

Examples

filter_rows(rows: list[dict], pred: list) -> list[dict]
Example 1
Inputfilter_rows([{"a": 1, "b": 10}, {"a": 2, "b": 5}, {"a": 3, "b": 20}], ["and", ["cmp", "a", ">", 1], ["cmp", "b", ">=", 10]])
Output
ab
320