|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.umd.cloud9.io.Tuple
public class Tuple
Writable representing an arbitrary tuple. Tuples are instantiated from a
Schema. The Tuple class implements WritableComparable, so it can be
directly used as MapReduce keys and values. The natural sort order of tuples
is defined by an internally-generated byte representation and is not based on
field values. This class, combined with ArrayListWritable and
HashMapWritable, allows the user to define arbitrarily complex data
structures.
All fields can either be indexed via its integer position or its field name.
Each field is typed, which can be determined via getFieldType(int).
Fields can either contain an object of the specified type or a special symbol
String. The method containsSymbol(int) can be used to check if a
field contains a special symbol. If the field contains a special symbol,
get(int) will return null. If the field does not
contain a special symbol, getSymbol(int) will return
null.
Here is a typical usage scenario for special symbols: say you had tuples that
represented count(a, b), where a and
b are tokens you observe. There is often a need to compute
count(a, *), for example, to derive conditional
probabilities. In this case, you can use a special symbol to represent the
*, and distinguish it from the lexical token '*'.
The natural sort order of the Tuple is defined by Comparable.compareTo(Object).
Tuples are sorted by field, with special symbols always appearing first
within each field.
ArrayListWritable,
HashMapWritable,
Schema| Constructor Summary | |
|---|---|
Tuple()
Creates an empty Tuple. |
|
| Method Summary | |
|---|---|
int |
compareTo(Tuple that)
Defines a natural sort order for the Tuple class. |
boolean |
containsSymbol(int i)
Determines if a particular field (by position) contains a special symbol. |
boolean |
containsSymbol(String field)
Determines if a particular field (by name) contains a special symbol. |
static Tuple |
createFrom(DataInput in)
Factory method for deserializing a Tuple object. |
Object |
get(int i)
Returns object at a particular field (by position) in this Tuple. |
Object |
get(String field)
Returns object at a particular field (by name) in this Tuple. |
int |
getFieldCount()
|
Class<?> |
getFieldType(int i)
Returns the type of a particular field (by position). |
Class<?> |
getFieldType(String field)
Returns the type of a particular field (by name). |
String |
getSymbol(int i)
Returns special symbol at a particular field (by position). |
String |
getSymbol(String field)
Returns special symbol at a particular field (by name). |
int |
hashCode()
Returns a hash code for this Tuple. |
void |
readFields(DataInput in)
Deserializes the Tuple. |
void |
set(int i,
Object o)
Sets the object at a particular field (by position) in this Tuple. |
void |
set(String field,
Object o)
Sets the object at a particular field (by name) in this Tuple. |
void |
setSymbol(int i,
String s)
Sets a special symbol at a particular field (by position) in this Tuple. |
void |
setSymbol(String field,
String s)
Sets a special symbol at a particular field (by name) in this Tuple. |
String |
toString()
Generates human-readable String representation of this Tuple. |
void |
write(DataOutput out)
Serializes this Tuple. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Tuple()
Schema.instantiate(Object...).
| Method Detail |
|---|
public static Tuple createFrom(DataInput in)
throws IOException
in - raw byte source of the Tuple
IOException
public void set(int i,
Object o)
i - field positiono - object to set at the specified field
public void set(String field,
Object o)
field - field nameo - object to set at the specified field
public void setSymbol(int i,
String s)
i - field positions - special symbol to set at specified field
public void setSymbol(String field,
String s)
field - field names - special symbol to set at specified fieldpublic Object get(int i)
null if the field contains a special symbol.
i - field position
null if the field contains a
special symbolpublic Object get(String field)
null if the field contains a special symbol.
field - field name
null if the field contains a
special symbolpublic String getSymbol(int i)
null if the field does not contain a special symbol.
i - field position
null if the field does
not contain a special symbol.public String getSymbol(String field)
null if the field does not contain a special symbol.
field - field name
null if the field does
not contain a special symbol.public boolean containsSymbol(int i)
i - field position
true if the field contains a special symbol, or
false otherwisepublic boolean containsSymbol(String field)
field - field name
true if the field contains a special symbol, or
false otherwisepublic Class<?> getFieldType(int i)
i - field position
public Class<?> getFieldType(String field)
field - field name
public int getFieldCount()
public void readFields(DataInput in)
throws IOException
readFields in interface Writablein - source for raw byte representation
IOException
public void write(DataOutput out)
throws IOException
write in interface Writableout - where to write the raw byte representation
IOExceptionpublic String toString()
toString in class Objectpublic int compareTo(Tuple that)
Defines a natural sort order for the Tuple class. Following standard
convention, this method returns a value less than zero, a value greater
than zero, or zero if this Tuple should be sorted before, sorted after,
or is equal to obj. The sort order is defined as follows:
compareTo in interface Comparable<Tuple>obj.public int hashCode()
hashCode in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||