Initial query rewrite support.

Currently supports matching columns, literals and count(*) in the selection
and columns in grouping.


"`match`" doesn't take a partial function.  It's a purely syntactic construct which requires a literal series of `case`es.