support sorting of data properly in couchagg and sqlagg reports