KeyFieldBasedComparator (Hadoop 1.2.1 API) (original) (raw)



org.apache.hadoop.mapred.lib

Class KeyFieldBasedComparator<K,V>

java.lang.Object extended by org.apache.hadoop.io.WritableComparator extended by org.apache.hadoop.mapred.lib.KeyFieldBasedComparator<K,V>

All Implemented Interfaces:

Comparator, RawComparator, JobConfigurable


public class KeyFieldBasedComparator<K,V>

extends WritableComparator

implements JobConfigurable

This comparator implementation provides a subset of the features provided by the Unix/GNU Sort. In particular, the supported features are: -n, (Sort numerically) -r, (Reverse the result of comparison) -k pos1[,pos2], where pos is of the form f[.c][opts], where f is the number of the field to use, and c is the number of the first character from the beginning of the field. Fields and character posns are numbered starting with 1; a character position of zero in pos2 indicates the field's last character. If '.c' is omitted from pos1, it defaults to 1 (the beginning of the field); if omitted from pos2, it defaults to 0 (the end of the field). opts are ordering options (any of 'nr' as described above). We assume that the fields in the key are separated by map.output.key.field.separator.


Constructor Summary
KeyFieldBasedComparator()
Method Summary
int [compare](../../../../../org/apache/hadoop/mapred/lib/KeyFieldBasedComparator.html#compare%28byte[], int, int, byte[], int, int%29)(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) Optimization hook.
void configure(JobConf job) Initializes a new instance from a JobConf.
Methods inherited from class org.apache.hadoop.io.WritableComparator
[compare](../../../../../org/apache/hadoop/io/WritableComparator.html#compare%28java.lang.Object, java.lang.Object%29), [compare](../../../../../org/apache/hadoop/io/WritableComparator.html#compare%28org.apache.hadoop.io.WritableComparable, org.apache.hadoop.io.WritableComparable%29), [compareBytes](../../../../../org/apache/hadoop/io/WritableComparator.html#compareBytes%28byte[], int, int, byte[], int, int%29), [define](../../../../../org/apache/hadoop/io/WritableComparator.html#define%28java.lang.Class, org.apache.hadoop.io.WritableComparator%29), get, getKeyClass, [hashBytes](../../../../../org/apache/hadoop/io/WritableComparator.html#hashBytes%28byte[], int%29), [hashBytes](../../../../../org/apache/hadoop/io/WritableComparator.html#hashBytes%28byte[], int, int%29), newKey, [readDouble](../../../../../org/apache/hadoop/io/WritableComparator.html#readDouble%28byte[], int%29), [readFloat](../../../../../org/apache/hadoop/io/WritableComparator.html#readFloat%28byte[], int%29), [readInt](../../../../../org/apache/hadoop/io/WritableComparator.html#readInt%28byte[], int%29), [readLong](../../../../../org/apache/hadoop/io/WritableComparator.html#readLong%28byte[], int%29), [readUnsignedShort](../../../../../org/apache/hadoop/io/WritableComparator.html#readUnsignedShort%28byte[], int%29), [readVInt](../../../../../org/apache/hadoop/io/WritableComparator.html#readVInt%28byte[], int%29), [readVLong](../../../../../org/apache/hadoop/io/WritableComparator.html#readVLong%28byte[], int%29)
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Comparator
equals
Constructor Detail

KeyFieldBasedComparator

public KeyFieldBasedComparator()

Method Detail

configure

public void configure(JobConf job)

Description copied from interface: [JobConfigurable](../../../../../org/apache/hadoop/mapred/JobConfigurable.html#configure%28org.apache.hadoop.mapred.JobConf%29)

Initializes a new instance from a JobConf.

Specified by:

[configure](../../../../../org/apache/hadoop/mapred/JobConfigurable.html#configure%28org.apache.hadoop.mapred.JobConf%29) in interface [JobConfigurable](../../../../../org/apache/hadoop/mapred/JobConfigurable.html "interface in org.apache.hadoop.mapred")

Parameters:

job - the configuration


compare

public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2)

Description copied from class: [WritableComparator](../../../../../org/apache/hadoop/io/WritableComparator.html#compare%28byte[], int, int, byte[], int, int%29)

Optimization hook. Override this to make SequenceFile.Sorter's scream.

The default implementation reads the data into two WritableComparables (using Writable.readFields(DataInput), then calls [WritableComparator.compare(WritableComparable,WritableComparable)](../../../../../org/apache/hadoop/io/WritableComparator.html#compare%28org.apache.hadoop.io.WritableComparable, org.apache.hadoop.io.WritableComparable%29).

Specified by:

[compare](../../../../../org/apache/hadoop/io/RawComparator.html#compare%28byte[], int, int, byte[], int, int%29) in interface [RawComparator](../../../../../org/apache/hadoop/io/RawComparator.html "interface in org.apache.hadoop.io")

Overrides:

[compare](../../../../../org/apache/hadoop/io/WritableComparator.html#compare%28byte[], int, int, byte[], int, int%29) in class [WritableComparator](../../../../../org/apache/hadoop/io/WritableComparator.html "class in org.apache.hadoop.io")



Copyright © 2009 The Apache Software Foundation