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

It is needed to avoid matching on a count(null).  Adding a unit test to actually test that.