Add query rewrite support for where, group by and nested expressions.

Why not indeed!  Done.