public class RowSequencer extends UDF { private final Map<String, LongWritable> counterMap; public RowSequencer() { counterMap = new HashMap<String,LongWritable>(); } public LongWritable evaluate(Text exp) { LongWritable result = counterMap.get(exp.toString()); if (result == null) { result = new LongWritable(0); counterMap.put(exp.toString(), result); } result.set(result.get() + 1); return result; } }