Added UDAF and UDF to rank records per group and return mode value