Skip to content

Instantly share code, notes, and snippets.

@ketralnis
Created February 3, 2012 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ketralnis/1732911 to your computer and use it in GitHub Desktop.
Save ketralnis/1732911 to your computer and use it in GitHub Desktop.
package com.hipmunk.pig.udfs;
import org.apache.pig.EvalFunc;
import org.apache.pig.backend.executionengine.ExecException;
import org.apache.pig.data.BagFactory;
import org.apache.pig.data.DataBag;
import org.apache.pig.data.DefaultBagFactory;
import org.apache.pig.data.Tuple;
import org.apache.pig.data.TupleFactory;
public class TupleToBag extends EvalFunc<DataBag> {
private static final BagFactory bagFactory_ = DefaultBagFactory.getInstance();
private static final TupleFactory tupleFactory_ = TupleFactory.getInstance();
public DataBag exec(Tuple args) throws ExecException {
assert args.size() == 1;
DataBag db = bagFactory_.newDefaultBag();
Tuple t = (Tuple)args.get(0);
for(Object i: t.getAll()) {
db.add(tupleFactory_.newTuple(i));
}
return db;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment