public class KeyGenerator
extends java.lang.Object
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 and Description |
---|
KeyGenerator(ComparatorExpr expr)
Create a key builder that can generate binary keys for the input key
expression.
|
Modifier and Type | Method and Description |
---|---|
org.apache.hadoop.io.BytesWritable |
generateKey(Tuple t)
Generate the binary key for the input tuple
|
void |
illustrate(java.io.PrintStream ps)
Illustrate how the key would be generated from source.
|
void |
reset(ComparatorExpr expr)
Reset the key builder for a new expression.
|
public KeyGenerator(ComparatorExpr expr)
expr
- comparator expressionpublic void reset(ComparatorExpr expr)
expr
- comparator expressionpublic org.apache.hadoop.io.BytesWritable generateKey(Tuple t) throws ExecException
t
- input tupleBytesWritable
containing the binary sorting key for the
input tuple.ExecException
public void illustrate(java.io.PrintStream ps)
ps
- The output print stream.Copyright © 2007-2012 The Apache Software Foundation