Find the distinct set of tuples in a bag. This is a blocking operator. All the input is put in the hashset implemented in DistinctDataBag which also provides the other DataBag interfaces.
| 38 | * in DistinctDataBag which also provides the other DataBag interfaces. |
| 39 | */ |
| 40 | public class Distinct extends EvalFunc<DataBag> implements Algebraic { |
| 41 | |
| 42 | private static TupleFactory tupleFactory = TupleFactory.getInstance(); |
| 43 | private static boolean initialized = false; |
| 44 | private static boolean useDefaultBag = false; |
| 45 | |
| 46 | @Override |
| 47 | public DataBag exec(Tuple input) throws IOException { |
| 48 | return getDistinct(input); |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public String getFinal() { |
| 53 | return Final.class.getName(); |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public String getInitial() { |
| 58 | return Initial.class.getName(); |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public String getIntermed() { |
| 63 | return Intermediate.class.getName(); |
| 64 | } |
| 65 | |
| 66 | static public class Initial extends EvalFunc<Tuple> { |
| 67 | |
| 68 | @Override |
| 69 | public Tuple exec(Tuple input) throws IOException { |
| 70 | // the input has a single field which is a tuple |
| 71 | // representing the data we want to distinct. |
| 72 | // unwrap, put in a bag and send down |
| 73 | try { |
| 74 | Tuple single = (Tuple)input.get(0); |
| 75 | DataBag bag = single == null ? createDataBag() : new SingleTupleBag(single); |
| 76 | return tupleFactory.newTuple(bag); |
| 77 | } catch (ExecException e) { |
| 78 | throw e; |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | static public class Intermediate extends EvalFunc<Tuple> { |
| 84 | |
| 85 | @Override |
| 86 | public Tuple exec(Tuple input) throws IOException { |
| 87 | return tupleFactory.newTuple(getDistinctFromNestedBags(input, this)); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | static public class Final extends EvalFunc<DataBag> { |
| 92 | |
| 93 | @Override |
| 94 | public DataBag exec(Tuple input) throws IOException { |
| 95 | return getDistinctFromNestedBags(input, this); |
| 96 | } |
| 97 | } |
nothing calls this directly
no test coverage detected