MCPcopy Create free account
hub / github.com/apache/pig / computeDiff

Method computeDiff

src/org/apache/pig/builtin/DIFF.java:82–100  ·  view source on GitHub ↗
(
            DataBag bag1,
            DataBag bag2,
            DataBag emitTo)

Source from the content-addressed store, hash-verified

80 }
81
82 private void computeDiff(
83 DataBag bag1,
84 DataBag bag2,
85 DataBag emitTo) {
86 // Build two hash tables and probe with first one, then the other.
87 // This does make the assumption that the distinct set of keys from
88 // each bag will fit in memory.
89 Set<Tuple> s1 = new HashSet<Tuple>();
90 Iterator<Tuple> i1 = bag1.iterator();
91 while (i1.hasNext()) s1.add(i1.next());
92
93 Set<Tuple> s2 = new HashSet<Tuple>();
94 Iterator<Tuple> i2 = bag2.iterator();
95 while (i2.hasNext()) s2.add(i2.next());
96
97 for (Tuple t : s1) if (!s2.contains(t)) emitTo.add(t);
98 for (Tuple t : s2) if (!s1.contains(t)) emitTo.add(t);
99
100 }
101
102 @Override
103 public boolean allowCompileTimeCalculation() {

Callers 1

execMethod · 0.95

Calls 5

iteratorMethod · 0.65
addMethod · 0.65
hasNextMethod · 0.45
nextMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected