org.apache.pig.impl.builtin
Class RandomSampleLoader

java.lang.Object
  extended by org.apache.pig.LoadFunc
      extended by org.apache.pig.impl.builtin.SampleLoader
          extended by org.apache.pig.impl.builtin.RandomSampleLoader

public class RandomSampleLoader
extends SampleLoader

A loader that samples the data. It randomly samples tuples from input. The number of tuples to be sampled has to be set before the first call to getNext(). see documentation of getNext() call.


Field Summary
protected  int nextSampleIdx
           
 
Fields inherited from class org.apache.pig.impl.builtin.SampleLoader
loader, numSamples
 
Constructor Summary
RandomSampleLoader(String funcSpec, String ns)
          Construct with a class of loader to use.
 
Method Summary
 Tuple getNext()
          Allocate a buffer for numSamples elements, populate it with the first numSamples tuples, and continue scanning rest of the input.
 
Methods inherited from class org.apache.pig.impl.builtin.SampleLoader
computeSamples, getInputFormat, getLoadCaster, getNumSamples, prepareToRead, relativeToAbsolutePath, setLocation, setNumSamples, setUDFContextSignature, skipNext
 
Methods inherited from class org.apache.pig.LoadFunc
getAbsolutePath, getPathStrings, join
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nextSampleIdx

protected int nextSampleIdx
Constructor Detail

RandomSampleLoader

public RandomSampleLoader(String funcSpec,
                          String ns)
Construct with a class of loader to use.

Parameters:
funcSpec - func spec of the loader to use.
ns - Number of samples per map to collect. Arguments are passed as strings instead of actual types (FuncSpec, int) because FuncSpec only supports string arguments to UDF constructors.
Method Detail

getNext

public Tuple getNext()
              throws IOException
Allocate a buffer for numSamples elements, populate it with the first numSamples tuples, and continue scanning rest of the input. For every ith next() call, we generate a random number r s.t. 0<=r
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


Copyright © ${year} The Apache Software Foundation