A hive UDF function to store a rank for a given ordered rows of key