org.apache.pig.impl.builtin
Class DefaultIndexableLoader

java.lang.Object
  extended by org.apache.pig.LoadFunc
      extended by org.apache.pig.impl.builtin.DefaultIndexableLoader
All Implemented Interfaces:
IndexableLoadFunc

public class DefaultIndexableLoader
extends LoadFunc
implements IndexableLoadFunc

Used by MergeJoin . Takes an index on sorted data consisting of sorted tuples of the form (key1,key2..., position,splitIndex) as input. For key given in seekNear(Tuple) finds the splitIndex that can contain the key and initializes ReadToEndLoader to read from that splitIndex onwards , in the sequence of splits in the index


Constructor Summary
DefaultIndexableLoader(String loaderFuncSpec, String indexFile, String indexFileLoadFuncSpec, String scope, String inputLocation)
           
 
Method Summary
 void close()
          A method called by the Pig runtime to give an opportunity for implementations to perform cleanup actions like closing the underlying input stream.
 org.apache.hadoop.mapreduce.InputFormat getInputFormat()
          This will be called during planning on the front end.
 LoadCaster getLoadCaster()
          This will be called on the front end during planning and not on the back end during execution.
 Tuple getNext()
          Retrieves the next tuple to be processed.
 void initialize(org.apache.hadoop.conf.Configuration conf)
          This method is called by Pig run time to allow the IndexableLoadFunc to perform any initialization actions
 void prepareToRead(org.apache.hadoop.mapreduce.RecordReader reader, PigSplit split)
          Initializes LoadFunc for reading data.
 void seekNear(Tuple keys)
          This method is called by the Pig runtime to indicate to the LoadFunc to position its underlying input stream near the keys supplied as the argument.
 void setIndexFile(String indexFile)
           
 void setLocation(String location, org.apache.hadoop.mapreduce.Job job)
          Communicate to the loader the location of the object(s) being loaded.
 
Methods inherited from class org.apache.pig.LoadFunc
getAbsolutePath, getPathStrings, join, relativeToAbsolutePath, setUDFContextSignature, warn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultIndexableLoader

public DefaultIndexableLoader(String loaderFuncSpec,
                              String indexFile,
                              String indexFileLoadFuncSpec,
                              String scope,
                              String inputLocation)
Method Detail

seekNear

public void seekNear(Tuple keys)
              throws IOException
Description copied from interface: IndexableLoadFunc
This method is called by the Pig runtime to indicate to the LoadFunc to position its underlying input stream near the keys supplied as the argument. Specifically: 1) if the keys are present in the input stream, the loadfunc implementation should position its read position to a record where the key(s) is/are the biggest key(s) less than the key(s) supplied in the argument OR to the record with the first occurrence of the keys(s) supplied. 2) if the key(s) are absent in the input stream, the implementation should position its read position to a record where the key(s) is/are the biggest key(s) less than the key(s) supplied OR to the first record where the key(s) is/are the smallest key(s) greater than the keys(s) supplied. The description above holds for descending order data in a similar manner with "biggest" and "less than" replaced with "smallest" and "greater than" and vice versa.

Specified by:
seekNear in interface IndexableLoadFunc
Parameters:
keys - Tuple with join keys (which are a prefix of the sort keys of the input data). For example if the data is sorted on columns in position 2,4,5 any of the following Tuples are valid as an argument value: (fieldAt(2)) (fieldAt(2), fieldAt(4)) (fieldAt(2), fieldAt(4), fieldAt(5)) The following are some invalid cases: (fieldAt(4)) (fieldAt(2), fieldAt(5)) (fieldAt(4), fieldAt(5))
Throws:
IOException - When the loadFunc is unable to position to the required point in its input stream

getNext

public Tuple getNext()
              throws IOException
Description copied from class: LoadFunc
Retrieves the next tuple to be processed. Implementations should NOT reuse tuple objects (or inner member objects) they return across calls and should return a different tuple object in each call.

Specified by:
getNext in class LoadFunc
Returns:
the next tuple to be processed or null if there are no more tuples to be processed.
Throws:
IOException - if there is an exception while retrieving the next tuple

close

public void close()
           throws IOException
Description copied from interface: IndexableLoadFunc
A method called by the Pig runtime to give an opportunity for implementations to perform cleanup actions like closing the underlying input stream. This is necessary since while performing a join the Pig run time may determine than no further join is possible with remaining records and may indicate to the IndexableLoader to cleanup by calling this method.

Specified by:
close in interface IndexableLoadFunc
Throws:
IOException - if the loadfunc is unable to perform its close actions.

initialize

public void initialize(org.apache.hadoop.conf.Configuration conf)
                throws IOException
Description copied from interface: IndexableLoadFunc
This method is called by Pig run time to allow the IndexableLoadFunc to perform any initialization actions

Specified by:
initialize in interface IndexableLoadFunc
Parameters:
conf - The job configuration object
Throws:
IOException

getInputFormat

public org.apache.hadoop.mapreduce.InputFormat getInputFormat()
                                                       throws IOException
Description copied from class: LoadFunc
This will be called during planning on the front end. This is the instance of InputFormat (rather than the class name) because the load function may need to instantiate the InputFormat in order to control how it is constructed.

Specified by:
getInputFormat in class LoadFunc
Returns:
the InputFormat associated with this loader.
Throws:
IOException - if there is an exception during InputFormat construction

getLoadCaster

public LoadCaster getLoadCaster()
                         throws IOException
Description copied from class: LoadFunc
This will be called on the front end during planning and not on the back end during execution.

Overrides:
getLoadCaster in class LoadFunc
Returns:
the LoadCaster associated with this loader. Returning null indicates that casts from byte array are not supported for this loader. construction
Throws:
IOException - if there is an exception during LoadCaster

prepareToRead

public void prepareToRead(org.apache.hadoop.mapreduce.RecordReader reader,
                          PigSplit split)
Description copied from class: LoadFunc
Initializes LoadFunc for reading data. This will be called during execution before any calls to getNext. The RecordReader needs to be passed here because it has been instantiated for a particular InputSplit.

Specified by:
prepareToRead in class LoadFunc
Parameters:
reader - RecordReader to be used by this instance of the LoadFunc
split - The input PigSplit to process

setLocation

public void setLocation(String location,
                        org.apache.hadoop.mapreduce.Job job)
                 throws IOException
Description copied from class: LoadFunc
Communicate to the loader the location of the object(s) being loaded. The location string passed to the LoadFunc here is the return value of LoadFunc.relativeToAbsolutePath(String, Path). Implementations should use this method to communicate the location (and any other information) to its underlying InputFormat through the Job object. This method will be called in the frontend and backend multiple times. Implementations should bear in mind that this method is called multiple times and should ensure there are no inconsistent side effects due to the multiple calls.

Specified by:
setLocation in class LoadFunc
Parameters:
location - Location as returned by LoadFunc.relativeToAbsolutePath(String, Path)
job - the Job object store or retrieve earlier stored information from the UDFContext
Throws:
IOException - if the location is not valid.

setIndexFile

public void setIndexFile(String indexFile)


Copyright © 2007-2012 The Apache Software Foundation