public int getPartition(PairOfIntString key, IntWritable value, int numReduceTasks) { return Math.abs(key.getLeftElement() % numReduceTasks); } }
/** * Checks two pairs for equality. * * @param obj object for comparison * @return <code>true</code> if <code>obj</code> is equal to this object, <code>false</code> * otherwise */ public boolean equals(Object obj) { PairOfIntString pair = (PairOfIntString) obj; return leftElement == pair.getLeftElement() && rightElement.equals(pair.getRightElement()); }
/** * Defines a natural sort order for pairs. Pairs are sorted first by the left element, and then by * the right element. * * @return a value less than zero, a value greater than zero, or zero if this pair should be * sorted before, sorted after, or is equal to <code>obj</code>. */ public int compareTo(PairOfIntString pair) { int pl = pair.getLeftElement(); String pr = pair.getRightElement(); if (leftElement == pl) { return rightElement.compareTo(pr); } return leftElement < pl ? -1 : 1; }
public void map(IntWritable key, PairOfIntString t, OutputCollector<IntWritable, Text> output, Reporter reporter) throws IOException { KEY.set(t.getLeftElement()); VALUE.set(t.getRightElement()); output.collect(KEY, VALUE); } }
firstTime = false; arrayList.clear(); currentDocument = key.getLeftElement(); } else if(currentDocument != key.getLeftElement()) { Collections.sort(arrayList); keyWord.set(currentDocument); output.collect(keyWord, arrayList); currentDocument = key.getLeftElement(); arrayList.clear();