CORE-4032: added aggregate functions, first() and last()