org.htuple
Class Tuple

java.lang.Object
  extended by org.htuple.Tuple
All Implemented Interfaces:
Comparable<Tuple>, org.apache.hadoop.io.Writable, org.apache.hadoop.io.WritableComparable<Tuple>

public class Tuple
extends Object
implements org.apache.hadoop.io.WritableComparable<Tuple>

A tuple for use as intermediary map outputs. Not designed for use beyond the scope of intermediary map outputs (i.e. don't use this for general-purpose persistence).

Null values are supported. If an element is retrieved using an index value that's out of bounds (and not a negative number), then a null value is be returned.

See ShuffleUtils for examples of how custom partitioning, sorting and grouping can be configured for tuples.

Example usage:


 // Create a 3-element tuple, where "alex" is located at index 0, "1" at index 1 and "3" at index 2
 Tuple t = new Tuple();
 t.add("alex").add(1).add(3);
 // extract the third element (the number "3")
 t.getInt(2);
 

You can also use enum's to get and set data for increased comprehension. The enum ordinal value (see http://docs.oracle.com/javase/7/docs/api/java/lang/Enum.html#ordinal()) is used as the index.


 enum MyTupleFields { ID, NAME }
 ...
 Tuple t = new Tuple();
 t.set(MyTupleFields.ID, 123);
 t.set(MyTupleFields.NAME, "alex");
 t.getString(MyTupleFields.NAME);
 


Constructor Summary
Tuple()
           
 
Method Summary
 Tuple add(Boolean val)
          Appends a new element to the tuple.
 Tuple add(org.apache.hadoop.io.BytesWritable val)
          Appends a new element to the tuple.
 Tuple add(Double val)
          Appends a new element to the tuple.
 Tuple add(Float val)
          Appends a new element to the tuple.
 Tuple add(Integer val)
          Appends a new element to the tuple.
 Tuple add(Long val)
          Appends a new element to the tuple.
 Tuple add(Short val)
          Appends a new element to the tuple.
 Tuple add(String val)
          Appends a new element to the tuple.
 Tuple addBoolean(Boolean val)
          Appends a new element to the tuple.
 Tuple addBytes(org.apache.hadoop.io.BytesWritable val)
          Appends a new element to the tuple.
 Tuple addDouble(Double val)
          Appends a new element to the tuple.
 Tuple addFloat(Float val)
          Appends a new element to the tuple.
 Tuple addInt(Integer val)
          Appends a new element to the tuple.
 Tuple addLong(Long val)
          Appends a new element to the tuple.
 Tuple addShort(Short val)
          Appends a new element to the tuple.
 Tuple addString(String val)
          Appends a new element to the tuple.
 Tuple clear()
          Remove all the elements from this tuple.
 int compareTo(Tuple other)
           
 boolean equals(Object object)
           
 Boolean getBoolean(Enum<?> eval)
          Read an element from the supplied position in the tuple.
 Boolean getBoolean(int idx)
          Read an element from the supplied position in the tuple.
 org.apache.hadoop.io.BytesWritable getBytes(Enum<?> eval)
          Read an element from the supplied position in the tuple.
 org.apache.hadoop.io.BytesWritable getBytes(int idx)
          Read an element from the supplied position in the tuple.
 Double getDouble(Enum<?> eval)
          Read an element from the supplied position in the tuple.
 Double getDouble(int idx)
          Read an element from the supplied position in the tuple.
 Float getFloat(Enum<?> eval)
          Read an element from the supplied position in the tuple.
 Float getFloat(int idx)
          Read an element from the supplied position in the tuple.
 Integer getInt(Enum<?> eval)
          Read an element from the supplied position in the tuple.
 Integer getInt(int idx)
          Read an element from the supplied position in the tuple.
 Long getLong(Enum<?> eval)
          Read an element from the supplied position in the tuple.
 Long getLong(int idx)
          Read an element from the supplied position in the tuple.
 Object getObject(Enum<?> eval)
          Retrieves an element at a specific position.
 Object getObject(int idx)
          Retrieves an element at a specific position.
 Short getShort(Enum<?> eval)
          Read an element from the supplied position in the tuple.
 Short getShort(int idx)
          Read an element from the supplied position in the tuple.
 String getString(Enum<?> eval)
          Read an element from the supplied position in the tuple.
 String getString(int idx)
          Read an element from the supplied position in the tuple.
 int hashCode()
           
 void readFields(DataInput in)
           
 Tuple set(Enum<?> eval, org.apache.hadoop.io.BytesWritable val)
          Deprecated. use setBytes(Enum, org.apache.hadoop.io.BytesWritable) instead
 Tuple set(Enum<?> eval, Double val)
          Deprecated. use setDouble(Enum, Double) instead
 Tuple set(Enum<?> eval, Float val)
          Deprecated. use setFloat(Enum, Float) instead
 Tuple set(Enum<?> eval, Integer val)
          Deprecated. use setInt(Enum, Integer) instead
 Tuple set(Enum<?> eval, Long val)
          Deprecated. use setLong(Enum, Long) instead
 Tuple set(Enum<?> eval, Object val)
          Sets a value at a specific position in the tuple.
 Tuple set(Enum<?> eval, Short val)
          Deprecated. use setShort(Enum, Short) instead
 Tuple set(Enum<?> eval, String val)
          Deprecated. use setString(Enum, String) instead
 Tuple set(int idx, Boolean val)
          Deprecated. use setBoolean(int, Boolean) instead
 Tuple set(int idx, org.apache.hadoop.io.BytesWritable val)
          Deprecated. use setBytes(int, org.apache.hadoop.io.BytesWritable) instead
 Tuple set(int idx, Double val)
          Deprecated. use setDouble(int, Double) instead
 Tuple set(int idx, Float val)
          Deprecated. use setFloat(int, Float) instead
 Tuple set(int idx, Integer val)
          Deprecated. use setInt(int, Integer) instead
 Tuple set(int idx, Object val)
          Sets a value at a specific position in the tuple.
 Tuple set(int idx, Short val)
          Deprecated. use setShort(int, Short) instead
 Tuple set(int idx, String val)
          Deprecated. use setString(int, String) instead
 Tuple setBoolean(int idx, Boolean val)
          Sets a value at a specific position in the tuple.
 Tuple setBytes(Enum<?> eval, org.apache.hadoop.io.BytesWritable val)
          Sets a value at a specific position in the tuple.
 Tuple setBytes(int idx, org.apache.hadoop.io.BytesWritable val)
          Sets a value at a specific position in the tuple.
 Tuple setDouble(Enum<?> eval, Double val)
          Sets a value at a specific position in the tuple.
 Tuple setDouble(int idx, Double val)
          Sets a value at a specific position in the tuple.
 Tuple setFloat(Enum<?> eval, Float val)
          Sets a value at a specific position in the tuple.
 Tuple setFloat(int idx, Float val)
          Sets a value at a specific position in the tuple.
 Tuple setInt(Enum<?> eval, Integer val)
          Sets a value at a specific position in the tuple.
 Tuple setInt(int idx, Integer val)
          Sets a value at a specific position in the tuple.
 Tuple setLong(Enum<?> eval, Long val)
          Sets a value at a specific position in the tuple.
 Tuple setLong(int idx, Integer val)
          Sets a value at a specific position in the tuple.
 Tuple setShort(Enum<?> eval, Short val)
          Sets a value at a specific position in the tuple.
 Tuple setShort(int idx, Short val)
          Sets a value at a specific position in the tuple.
 Tuple setString(Enum<?> eval, String val)
          Sets a value at a specific position in the tuple.
 Tuple setString(int idx, String val)
          Sets a value at a specific position in the tuple.
 int size()
          Returns the number of elements in this tuple.
 String toString()
           
 void write(DataOutput out)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Tuple

public Tuple()
Method Detail

clear

public Tuple clear()
Remove all the elements from this tuple.

Returns:
a handle to this object to enable builder operations

size

public int size()
Returns the number of elements in this tuple.

Returns:
the number of elements

set

public Tuple set(int idx,
                 Object val)
Sets a value at a specific position in the tuple.

If this tuple has fewer elements than the index being set, then the tuple will grow to idx elements.

Parameters:
idx - the index to set
val - the value to set
Returns:
a handle to this object to enable builder operations

set

public Tuple set(Enum<?> eval,
                 Object val)
Sets a value at a specific position in the tuple.

The position is determined by executing Enum.ordinal() on the supplied enum.

If this tuple has fewer elements than the index being set, then the tuple will grow to idx elements.

Parameters:
eval - the enum which is used to determine the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations

set

public Tuple set(Enum<?> eval,
                 Short val)
Deprecated. use setShort(Enum, Short) instead

Sets a value at a specific position in the tuple.

Parameters:
eval - the enum which is used to determine the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations
See Also:
for more info

setShort

public Tuple setShort(Enum<?> eval,
                      Short val)
Sets a value at a specific position in the tuple.

Parameters:
eval - the enum which is used to determine the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations
See Also:
for more info

set

public Tuple set(int idx,
                 Short val)
Deprecated. use setShort(int, Short) instead

Sets a value at a specific position in the tuple.

Parameters:
idx - the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations
See Also:
set(int, Object)

setShort

public Tuple setShort(int idx,
                      Short val)
Sets a value at a specific position in the tuple.

Parameters:
idx - the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations
See Also:
set(int, Object)

set

public Tuple set(Enum<?> eval,
                 Integer val)
Deprecated. use setInt(Enum, Integer) instead

Sets a value at a specific position in the tuple.

Parameters:
eval - the enum which is used to determine the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations
See Also:
for more info

setInt

public Tuple setInt(Enum<?> eval,
                    Integer val)
Sets a value at a specific position in the tuple.

Parameters:
eval - the enum which is used to determine the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations
See Also:
for more info

set

public Tuple set(int idx,
                 Integer val)
Deprecated. use setInt(int, Integer) instead

Sets a value at a specific position in the tuple.

Parameters:
idx - the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations
See Also:
set(int, Object)

setInt

public Tuple setInt(int idx,
                    Integer val)
Sets a value at a specific position in the tuple.

Parameters:
idx - the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations
See Also:
set(int, Object)

set

public Tuple set(Enum<?> eval,
                 Long val)
Deprecated. use setLong(Enum, Long) instead

Sets a value at a specific position in the tuple.

Parameters:
eval - the enum which is used to determine the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations
See Also:
for more info

setLong

public Tuple setLong(Enum<?> eval,
                     Long val)
Sets a value at a specific position in the tuple.

Parameters:
eval - the enum which is used to determine the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations
See Also:
for more info

setLong

public Tuple setLong(int idx,
                     Integer val)
Sets a value at a specific position in the tuple.

Parameters:
idx - the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations
See Also:
set(int, Object)

set

public Tuple set(int idx,
                 String val)
Deprecated. use setString(int, String) instead

Sets a value at a specific position in the tuple.

Parameters:
idx - the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations
See Also:
set(int, Object)

setString

public Tuple setString(int idx,
                       String val)
Sets a value at a specific position in the tuple.

Parameters:
idx - the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations
See Also:
set(int, Object)

set

public Tuple set(Enum<?> eval,
                 String val)
Deprecated. use setString(Enum, String) instead

Sets a value at a specific position in the tuple.

Parameters:
eval - the enum which is used to determine the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations
See Also:
for more info

setString

public Tuple setString(Enum<?> eval,
                       String val)
Sets a value at a specific position in the tuple.

Parameters:
eval - the enum which is used to determine the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations
See Also:
for more info

set

public Tuple set(int idx,
                 Boolean val)
Deprecated. use setBoolean(int, Boolean) instead

Sets a value at a specific position in the tuple.

Parameters:
idx - the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations
See Also:
set(int, Object)

setBoolean

public Tuple setBoolean(int idx,
                        Boolean val)
Sets a value at a specific position in the tuple.

Parameters:
idx - the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations
See Also:
set(int, Object)

set

public Tuple set(Enum<?> eval,
                 Double val)
Deprecated. use setDouble(Enum, Double) instead

Sets a value at a specific position in the tuple.

Parameters:
eval - the enum which is used to determine the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations
See Also:
for more info

setDouble

public Tuple setDouble(Enum<?> eval,
                       Double val)
Sets a value at a specific position in the tuple.

Parameters:
eval - the enum which is used to determine the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations
See Also:
for more info

set

public Tuple set(int idx,
                 Double val)
Deprecated. use setDouble(int, Double) instead

Sets a value at a specific position in the tuple.

Parameters:
idx - the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations
See Also:
set(int, Object)

setDouble

public Tuple setDouble(int idx,
                       Double val)
Sets a value at a specific position in the tuple.

Parameters:
idx - the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations
See Also:
set(int, Object)

set

public Tuple set(Enum<?> eval,
                 Float val)
Deprecated. use setFloat(Enum, Float) instead

Sets a value at a specific position in the tuple.

Parameters:
eval - the enum which is used to determine the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations
See Also:
for more info

set

public Tuple set(int idx,
                 Float val)
Deprecated. use setFloat(int, Float) instead

Sets a value at a specific position in the tuple.

Parameters:
idx - the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations
See Also:
set(int, Object)

setFloat

public Tuple setFloat(Enum<?> eval,
                      Float val)
Sets a value at a specific position in the tuple.

Parameters:
eval - the enum which is used to determine the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations
See Also:
for more info

setFloat

public Tuple setFloat(int idx,
                      Float val)
Sets a value at a specific position in the tuple.

Parameters:
idx - the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations
See Also:
set(int, Object)

set

public Tuple set(Enum<?> eval,
                 org.apache.hadoop.io.BytesWritable val)
Deprecated. use setBytes(Enum, org.apache.hadoop.io.BytesWritable) instead

Sets a value at a specific position in the tuple.

Parameters:
eval - the enum which is used to determine the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations
See Also:
for more info

set

public Tuple set(int idx,
                 org.apache.hadoop.io.BytesWritable val)
Deprecated. use setBytes(int, org.apache.hadoop.io.BytesWritable) instead

Sets a value at a specific position in the tuple.

Parameters:
idx - the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations
See Also:
set(int, Object)

setBytes

public Tuple setBytes(Enum<?> eval,
                      org.apache.hadoop.io.BytesWritable val)
Sets a value at a specific position in the tuple.

Parameters:
eval - the enum which is used to determine the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations
See Also:
for more info

setBytes

public Tuple setBytes(int idx,
                      org.apache.hadoop.io.BytesWritable val)
Sets a value at a specific position in the tuple.

Parameters:
idx - the index for the set operation
val - the value to set
Returns:
a handle to this object to enable builder operations
See Also:
set(int, Object)

add

public Tuple add(Short val)
Appends a new element to the tuple.

Parameters:
val - the value to add
Returns:
a handle to this object to enable builder operations

addShort

public Tuple addShort(Short val)
Appends a new element to the tuple.

Parameters:
val - the value to add
Returns:
a handle to this object to enable builder operations

add

public Tuple add(Integer val)
Appends a new element to the tuple.

Parameters:
val - the value to add
Returns:
a handle to this object to enable builder operations

addInt

public Tuple addInt(Integer val)
Appends a new element to the tuple.

Parameters:
val - the value to add
Returns:
a handle to this object to enable builder operations

add

public Tuple add(Long val)
Appends a new element to the tuple.

Parameters:
val - the value to add
Returns:
a handle to this object to enable builder operations

addLong

public Tuple addLong(Long val)
Appends a new element to the tuple.

Parameters:
val - the value to add
Returns:
a handle to this object to enable builder operations

add

public Tuple add(String val)
Appends a new element to the tuple.

Parameters:
val - the value to add
Returns:
a handle to this object to enable builder operations

addString

public Tuple addString(String val)
Appends a new element to the tuple.

Parameters:
val - the value to add
Returns:
a handle to this object to enable builder operations

add

public Tuple add(Boolean val)
Appends a new element to the tuple.

Parameters:
val - the value to add
Returns:
a handle to this object to enable builder operations

addBoolean

public Tuple addBoolean(Boolean val)
Appends a new element to the tuple.

Parameters:
val - the value to add
Returns:
a handle to this object to enable builder operations

add

public Tuple add(Double val)
Appends a new element to the tuple.

Parameters:
val - the value to add
Returns:
a handle to this object to enable builder operations

addDouble

public Tuple addDouble(Double val)
Appends a new element to the tuple.

Parameters:
val - the value to add
Returns:
a handle to this object to enable builder operations

add

public Tuple add(Float val)
Appends a new element to the tuple.

Parameters:
val - the value to add
Returns:
a handle to this object to enable builder operations

addFloat

public Tuple addFloat(Float val)
Appends a new element to the tuple.

Parameters:
val - the value to add
Returns:
a handle to this object to enable builder operations

add

public Tuple add(org.apache.hadoop.io.BytesWritable val)
Appends a new element to the tuple.

Parameters:
val - the value to add
Returns:
a handle to this object to enable builder operations

addBytes

public Tuple addBytes(org.apache.hadoop.io.BytesWritable val)
Appends a new element to the tuple.

Parameters:
val - the value to add
Returns:
a handle to this object to enable builder operations

getObject

public Object getObject(int idx)
Retrieves an element at a specific position.

Note that the behavior of this method is different than compared to the List.get(int). In our case, if the supplied index is greater than the number of elements in this tuple, we'll return a null.

However we do throw a IllegalArgumentException in the case that the index is less than 0.

Parameters:
idx - the index into the fields
Returns:
the object at the specified position, or null if element is empty or the supplied position is greater than the size of this tuple.

getObject

public Object getObject(Enum<?> eval)
Retrieves an element at a specific position. The position is determined by extracting the ordinal value of the supplied enum.

Parameters:
eval - the enum used to extract the ordinal value
Returns:
the object at the specified position, or null if element is empty, or the supplied position is greater than the size of this tuple.
See Also:
getObject(int)

getShort

public Short getShort(Enum<?> eval)
Read an element from the supplied position in the tuple.

See Also:
getObject(Enum)

getShort

public Short getShort(int idx)
Read an element from the supplied position in the tuple.

See Also:
getObject(int)

getInt

public Integer getInt(Enum<?> eval)
Read an element from the supplied position in the tuple.

See Also:
getObject(Enum)

getInt

public Integer getInt(int idx)
Read an element from the supplied position in the tuple.

See Also:
getObject(int)

getLong

public Long getLong(Enum<?> eval)
Read an element from the supplied position in the tuple.

See Also:
getObject(Enum)

getLong

public Long getLong(int idx)
Read an element from the supplied position in the tuple.

See Also:
getObject(int)

getString

public String getString(Enum<?> eval)
Read an element from the supplied position in the tuple.

See Also:
getObject(Enum)

getString

public String getString(int idx)
Read an element from the supplied position in the tuple.

See Also:
getObject(int)

getBoolean

public Boolean getBoolean(Enum<?> eval)
Read an element from the supplied position in the tuple.

See Also:
getObject(Enum)

getBoolean

public Boolean getBoolean(int idx)
Read an element from the supplied position in the tuple.

See Also:
getObject(int)

getDouble

public Double getDouble(Enum<?> eval)
Read an element from the supplied position in the tuple.

See Also:
getObject(Enum)

getDouble

public Double getDouble(int idx)
Read an element from the supplied position in the tuple.

See Also:
getObject(int)

getFloat

public Float getFloat(Enum<?> eval)
Read an element from the supplied position in the tuple.

See Also:
getObject(Enum)

getFloat

public Float getFloat(int idx)
Read an element from the supplied position in the tuple.

See Also:
getObject(int)

getBytes

public org.apache.hadoop.io.BytesWritable getBytes(Enum<?> eval)
Read an element from the supplied position in the tuple.

See Also:
getObject(Enum)

getBytes

public org.apache.hadoop.io.BytesWritable getBytes(int idx)
Read an element from the supplied position in the tuple.

See Also:
getObject(int)

write

public void write(DataOutput out)
           throws IOException
Specified by:
write in interface org.apache.hadoop.io.Writable
Throws:
IOException

readFields

public void readFields(DataInput in)
                throws IOException
Specified by:
readFields in interface org.apache.hadoop.io.Writable
Throws:
IOException

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object object)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object

compareTo

public int compareTo(Tuple other)
Specified by:
compareTo in interface Comparable<Tuple>


Copyright © 2013. All Rights Reserved.