Java Code Examples for org.apache.pig.data.DataBag#spill()

The following examples show how to use org.apache.pig.data.DataBag#spill() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReverseEnumerate.java    From datafu with Apache License 2.0 6 votes vote down vote up
public DataBag call(DataBag inputBag) throws IOException
{
  DataBag outputBag = BagFactory.getInstance().newDefaultBag();
  long i = start, count = 0;
  i = inputBag.size() - 1 + start;

  for (Tuple t : inputBag) {
    Tuple t1 = TupleFactory.getInstance().newTuple(t.getAll());
    t1.append(i);
    outputBag.add(t1);

    if (count % 1000000 == 0) {
      outputBag.spill();
      count = 0;
    }
    i--;
    count++;
  }

  return outputBag;
}
 
Example 2
Source File: MarkovPairs.java    From datafu with Apache License 2.0 6 votes vote down vote up
private void generatePairs(ArrayList<Tuple> input, int start, int end, DataBag outputBag)
    throws ExecException
{
  int count = 0;
  for (int i = start; (i + 1)<= end; i++) {
    Tuple elem1 = input.get(i);
    
    lookahead:
    for (int j = i+1; j <= i + lookahead_steps; j++)
    {
      if (j > end) break lookahead;
      Tuple elem2 = input.get(j);        
      if (count >= SPILL_THRESHOLD) {
        outputBag.spill();
        count = 0;
      }
      outputBag.add(tupleFactory.newTuple(Arrays.asList(elem1, elem2)));
      count ++;
    }
  }
}
 
Example 3
Source File: UnorderedPairs.java    From datafu with Apache License 2.0 5 votes vote down vote up
@Override
public DataBag exec(Tuple input) throws IOException
{
  PigStatusReporter reporter = PigStatusReporter.getInstance();

  try {
    DataBag inputBag = (DataBag) input.get(0);
    DataBag outputBag = bagFactory.newDefaultBag();
    long i=0, j, cnt=0;

    if (inputBag != null)
    {
      for (Tuple elem1 : inputBag) {
        j = 0; 
        for (Tuple elem2 : inputBag) {
          if (j > i) {
            outputBag.add(tupleFactory.newTuple(Arrays.asList(elem1, elem2)));
            cnt++;
          }
          j++;

          if (reporter != null)
            reporter.progress();

          if (cnt % 1000000 == 0) {
            outputBag.spill();
            cnt = 0;
          }
        }
        i++;
      }
    }
    
    return outputBag;
  }
  catch (Exception e) {
    throw new RuntimeException("Caught exception processing input of " + this.getClass().getName(), e);
  }
}