Custom functions, aggregates, and collations

This is a relatively large pull request. It introduces support for defining custom SQL functions, aggregates, and collations. I tried to break it into as many commits as possible to make it easier to examine.