org.apache.pig.data
Class DefaultTuple

java.lang.Object
  extended by org.apache.pig.data.DefaultTuple
All Implemented Interfaces:
Serializable, Comparable, org.apache.hadoop.io.Writable, org.apache.hadoop.io.WritableComparable, Tuple
Direct Known Subclasses:
AmendableTuple, BinSedesTuple, DefaultAbstractBag.BagDelimiterTuple, TimestampedTuple, ZebraTuple

public class DefaultTuple
extends Object
implements Tuple

A default implementation of Tuple. This class will be created by the DefaultTupleFactory.

See Also:
Serialized Form

Nested Class Summary
static class DefaultTuple.DefaultTupleRawComparator
           
 
Field Summary
protected  boolean isNull
           
protected  List<Object> mFields
           
 
Fields inherited from interface org.apache.pig.data.Tuple
NOTNULL, NULL
 
Constructor Summary
DefaultTuple()
          Default constructor.
 
Method Summary
 void append(Object val)
          Append a field to a tuple.
 int compareTo(Object other)
           
 boolean equals(Object other)
           
 Object get(int fieldNum)
          Get the value in a given field.
 List<Object> getAll()
          Get all of the fields in the tuple as a list.
static Class<? extends TupleRawComparator> getComparatorClass()
           
 long getMemorySize()
          Determine the size of tuple in memory.
 byte getType(int fieldNum)
          Find the type of a given field.
 int hashCode()
           
 boolean isNull()
          Determine if this entire tuple (not any particular field) is null.
 boolean isNull(int fieldNum)
          Find out if a given field is null.
 void readFields(DataInput in)
           
 void reference(Tuple t)
          Make this tuple reference the contents of another.
 void set(int fieldNum, Object val)
          Set the value in a given field.
 void setNull(boolean isNull)
          Mark this entire tuple as null or not null.
 int size()
          Find the size of the tuple.
 String toDelimitedString(String delim)
          Write a tuple of atomic values into a string.
 String toString()
           
 void write(DataOutput out)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

isNull

protected boolean isNull

mFields

protected List<Object> mFields
Constructor Detail

DefaultTuple

public DefaultTuple()
Default constructor. This constructor is public so that hadoop can call it directly. However, inside pig you should never be calling this function. Use TupleFactory instead.

Method Detail

reference

public void reference(Tuple t)
Make this tuple reference the contents of another. This method does not copy the underlying data. It maintains references to the data from the original tuple (and possibly even to the data structure holding the data).

Specified by:
reference in interface Tuple
Parameters:
t - Tuple to reference.

size

public int size()
Find the size of the tuple. Used to be called arity().

Specified by:
size in interface Tuple
Returns:
number of fields in the tuple.

isNull

public boolean isNull(int fieldNum)
               throws ExecException
Find out if a given field is null.

Specified by:
isNull in interface Tuple
Parameters:
fieldNum - Number of field to check for null.
Returns:
true if the field is null, false otherwise.
Throws:
ExecException - if the field number given is greater than or equal to the number of fields in the tuple.

getType

public byte getType(int fieldNum)
             throws ExecException
Find the type of a given field.

Specified by:
getType in interface Tuple
Parameters:
fieldNum - Number of field to get the type for.
Returns:
type, encoded as a byte value. The values are taken from the class DataType. If the field is null, then DataType.UNKNOWN will be returned.
Throws:
ExecException - if the field number is greater than or equal to the number of fields in the tuple.

get

public Object get(int fieldNum)
           throws ExecException
Get the value in a given field.

Specified by:
get in interface Tuple
Parameters:
fieldNum - Number of the field to get the value for.
Returns:
value, as an Object.
Throws:
ExecException - if the field number is greater than or equal to the number of fields in the tuple.

getAll

public List<Object> getAll()
Get all of the fields in the tuple as a list.

Specified by:
getAll in interface Tuple
Returns:
List<Object> containing the fields of the tuple in order.

set

public void set(int fieldNum,
                Object val)
         throws ExecException
Set the value in a given field.

Specified by:
set in interface Tuple
Parameters:
fieldNum - Number of the field to set the value for.
val - Object to put in the indicated field.
Throws:
ExecException - if the field number is greater than or equal to the number of fields in the tuple.

append

public void append(Object val)
Append a field to a tuple. This method is not efficient as it may force copying of existing data in order to grow the data structure. Whenever possible you should construct your Tuple with the newTuple(int) method and then fill in the values with set(), rather than construct it with newTuple() and append values.

Specified by:
append in interface Tuple
Parameters:
val - Object to append to the tuple.

getMemorySize

public long getMemorySize()
Determine the size of tuple in memory. This is used by data bags to determine their memory size. This need not be exact, but it should be a decent estimation.

Specified by:
getMemorySize in interface Tuple
Returns:
estimated memory size.

toDelimitedString

public String toDelimitedString(String delim)
                         throws ExecException
Write a tuple of atomic values into a string. All values in the tuple must be atomic (no bags, tuples, or maps).

Specified by:
toDelimitedString in interface Tuple
Parameters:
delim - Delimiter to use in the string.
Returns:
A string containing the tuple.
Throws:
ExecException - if a non-atomic value is found.

toString

public String toString()
Overrides:
toString in class Object

compareTo

public int compareTo(Object other)
Specified by:
compareTo in interface Comparable

equals

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

hashCode

public int hashCode()
Overrides:
hashCode in class Object

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

isNull

public boolean isNull()
Description copied from interface: Tuple
Determine if this entire tuple (not any particular field) is null.

Specified by:
isNull in interface Tuple
Returns:
true if this Tuple is null

setNull

public void setNull(boolean isNull)
Description copied from interface: Tuple
Mark this entire tuple as null or not null.

Specified by:
setNull in interface Tuple
Parameters:
isNull - boolean indicating whether this tuple is null

getComparatorClass

public static Class<? extends TupleRawComparator> getComparatorClass()


Copyright © ${year} The Apache Software Foundation