|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.hadoop.zebra.pig.comparator.KeyGenerator
public class KeyGenerator
Generating binary keys for algorithmic comparators. A user may construct an algorithmic comparator by creating a ComparatorExpr object (through various static methods in this class). She could then create a KeyGenerator object and use it to create binary keys for tuple. The KeyGenerator object can be reused for different tuples that conform to the same schema. Sorting the tuples by the binary key yields the same ordering as sorting by the algorithmic comparator. Basic idea (without optimization):
escape(byte[] bytes) { for (byte b : bytes) { if (b == 0) emit(0x1, 0x0); else if (b == 1) emit(0x1, 0x2); else emit(b); } } complement(byte[] bytes) { for (byte b : bytes) { emit(˜b); } }
interface DatumExtractor { Object extract(Object o); }And user may do something like this:
class MyObject { int a; String b; } ComparatorExpr expr = KeyBuilder.createLeafExpr(new DatumExtractor { Object extract(Object o) { MyObject obj = (MyObject)o; return obj.b; } }, DataType.CHARARRAY);TODO Change BagExpr to IteratorExpr, so that it may be used in more general context (any Java collection). TODO Add an ArrayExpr (for Java []).
Constructor Summary | |
---|---|
KeyGenerator(ComparatorExpr expr)
Create a key builder that can generate binary keys for the input key expression. |
Method Summary | |
---|---|
org.apache.hadoop.io.BytesWritable |
generateKey(Tuple t)
Generate the binary key for the input tuple |
void |
illustrate(PrintStream ps)
Illustrate how the key would be generated from source. |
void |
reset(ComparatorExpr expr)
Reset the key builder for a new expression. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public KeyGenerator(ComparatorExpr expr)
expr
- comparator expressionMethod Detail |
---|
public void reset(ComparatorExpr expr)
expr
- comparator expressionpublic org.apache.hadoop.io.BytesWritable generateKey(Tuple t) throws ExecException
t
- input tuple
BytesWritable
containing the binary sorting key for the
input tuple.
ExecException
public void illustrate(PrintStream ps)
ps
- The output print stream.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |