org.apache.pig.impl.util.avro
Class AvroTupleWrapper<T extends org.apache.avro.generic.IndexedRecord>

java.lang.Object
  extended by org.apache.pig.impl.util.avro.AvroTupleWrapper<T>
Type Parameters:
T - The type of the Avro object
All Implemented Interfaces:
Serializable, Comparable, Iterable<Object>, org.apache.hadoop.io.Writable, org.apache.hadoop.io.WritableComparable, Tuple

public final class AvroTupleWrapper<T extends org.apache.avro.generic.IndexedRecord>
extends Object
implements Tuple

Object that wraps an Avro object in a tuple.

See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.apache.pig.data.Tuple
NOTNULL, NULL
 
Constructor Summary
AvroTupleWrapper(T o)
          Creates a new AvroTupleWrapper object.
 
Method Summary
 void append(Object o)
          Append a field to a tuple.
 int compareTo(Object o)
           
 Object get(int pos)
          Get the value in a given field.
 List<Object> getAll()
          Get all of the fields in the tuple as a list.
 long getMemorySize()
          Determine the size of tuple in memory.
 byte getType(int arg0)
          Find the type of a given field.
 boolean isNull(int arg0)
          Find out if a given field is null.
 Iterator<Object> iterator()
           
 void readFields(DataInput d)
           
 void reference(Tuple arg0)
          Make this tuple reference the contents of another.
 void set(int arg0, Object arg1)
          Set the value in a given field.
 int size()
          Find the size of the tuple.
 String toDelimitedString(String arg0)
          Write a tuple of values into a string.
static Object unionResolver(Object o)
           
 void write(DataOutput o)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AvroTupleWrapper

public AvroTupleWrapper(T o)
Creates a new AvroTupleWrapper object.

Parameters:
o - The object to wrap
Method Detail

write

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

compareTo

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

append

public void append(Object o)
Description copied from interface: Tuple
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 TupleFactory.newTuple(int) and then fill in the values with Tuple.set(int, Object), rather than construct it with TupleFactory.newTuple() and append values.

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

get

public Object get(int pos)
           throws ExecException
Description copied from interface: Tuple
Get the value in a given field.

Specified by:
get in interface Tuple
Parameters:
pos - 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.

unionResolver

public static Object unionResolver(Object o)

getAll

public List<Object> getAll()
Description copied from interface: Tuple
Get all of the fields in the tuple as a list.

Specified by:
getAll in interface Tuple
Returns:
a list of objects containing the fields of the tuple in order.

getMemorySize

public long getMemorySize()
Description copied from interface: Tuple
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, in bytes.

getType

public byte getType(int arg0)
             throws ExecException
Description copied from interface: Tuple
Find the type of a given field.

Specified by:
getType in interface Tuple
Parameters:
arg0 - Number of field to get the type for.
Returns:
type, encoded as a byte value. The values are defined in 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.

isNull

public boolean isNull(int arg0)
               throws ExecException
Description copied from interface: Tuple
Find out if a given field is null.

Specified by:
isNull in interface Tuple
Parameters:
arg0 - 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.

reference

public void reference(Tuple arg0)
Description copied from interface: Tuple
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:
arg0 - Tuple to reference.

set

public void set(int arg0,
                Object arg1)
         throws ExecException
Description copied from interface: Tuple
Set the value in a given field. This should not be called unless the tuple was constructed by TupleFactory.newTuple(int) with an argument greater than the fieldNum being passed here. This call will not automatically expand the tuple size. That is if you called TupleFactory.newTuple(int) with a 2, it is okay to call this function with a 1, but not with a 2 or greater.

Specified by:
set in interface Tuple
Parameters:
arg0 - Number of the field to set the value for.
arg1 - 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.

size

public int size()
Description copied from interface: Tuple
Find the size of the tuple. Used to be called arity().

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

toDelimitedString

public String toDelimitedString(String arg0)
                         throws ExecException
Description copied from interface: Tuple
Write a tuple of values into a string. The output will be the result of calling toString on each of the values in the tuple.

Specified by:
toDelimitedString in interface Tuple
Parameters:
arg0 - Delimiter to use in the string.
Returns:
A string containing the tuple.
Throws:
ExecException - this is never thrown. This only exists for backwards compatability reasons.

readFields

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

iterator

public Iterator<Object> iterator()
Specified by:
iterator in interface Iterable<Object>


Copyright © 2007-2012 The Apache Software Foundation