Implement DistinctBy

First part of the fix for #284. This is all the hard work, but leaves the most interesting test
pending because it will require a second sort to be introduced in the compiler. That PR will 
be coming soon.
I'm not sure we should try to put this information in the SQL AST. It's arguably a detail of how the compiler chooses to compile the AST. Ideally the AST should stay an accurate representation of user input, with a meaningful conversion back to SQL from the AST (a synthetic projection cannot be meaningfully translated into SQL because the distinction would be lost).