下面列出了org.apache.hadoop.io.IntWritable#compareTo ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void reduce(IntWritable key,
Iterator<IntWritable> values,
OutputCollector<IntWritable, Text> out,
Reporter reporter) throws IOException {
// check key order
int currentKey = key.get();
if (currentKey < lastKey) {
fail("Keys not in sorted ascending order");
}
lastKey = currentKey;
// check order of values
IntWritable previous = new IntWritable(Integer.MIN_VALUE);
int valueCount = 0;
while (values.hasNext()) {
IntWritable current = values.next();
// Check that the values are sorted
if (current.compareTo(previous) < 0)
fail("Values generated by Mapper not in order");
previous = current;
++valueCount;
}
if (valueCount != 5) {
fail("Values not grouped by primary key");
}
out.collect(key, new Text("success"));
}
public void reduce(IntWritable key,
Iterator<IntWritable> values,
OutputCollector<IntWritable, Text> out,
Reporter reporter) throws IOException {
// check key order
int currentKey = key.get();
if (currentKey > lastKey) {
fail("Keys not in sorted descending order");
}
lastKey = currentKey;
// check order of values
IntWritable previous = new IntWritable(Integer.MAX_VALUE);
int valueCount = 0;
while (values.hasNext()) {
IntWritable current = values.next();
// Check that the values are sorted
if (current.compareTo(previous) > 0)
fail("Values generated by Mapper not in order");
previous = current;
++valueCount;
}
if (valueCount != 5) {
fail("Values not grouped by primary key");
}
out.collect(key, new Text("success"));
}
public void reduce(IntWritable key,
Iterator<IntWritable> values,
OutputCollector<IntWritable, Text> out,
Reporter reporter) throws IOException {
// check key order
int currentKey = key.get();
if (currentKey < lastKey) {
fail("Keys not in sorted ascending order");
}
lastKey = currentKey;
// check order of values
IntWritable previous = new IntWritable(Integer.MIN_VALUE);
int valueCount = 0;
while (values.hasNext()) {
IntWritable current = values.next();
// Check that the values are sorted
if (current.compareTo(previous) < 0)
fail("Values generated by Mapper not in order");
previous = current;
++valueCount;
}
if (valueCount != 5) {
fail("Values not grouped by primary key");
}
out.collect(key, new Text("success"));
}
public void reduce(IntWritable key,
Iterator<IntWritable> values,
OutputCollector<IntWritable, Text> out,
Reporter reporter) throws IOException {
// check key order
int currentKey = key.get();
if (currentKey > lastKey) {
fail("Keys not in sorted descending order");
}
lastKey = currentKey;
// check order of values
IntWritable previous = new IntWritable(Integer.MAX_VALUE);
int valueCount = 0;
while (values.hasNext()) {
IntWritable current = values.next();
// Check that the values are sorted
if (current.compareTo(previous) > 0)
fail("Values generated by Mapper not in order");
previous = current;
++valueCount;
}
if (valueCount != 5) {
fail("Values not grouped by primary key");
}
out.collect(key, new Text("success"));
}