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

Class ExactKeyMatcher

test/org/apache/pig/test/utils/dotGraph/ExactKeyMatcher.java:32–116  ·  view source on GitHub ↗

This matcher only does exact key matching

Source from the content-addressed store, hash-verified

30 * This matcher only does exact key matching
31 */
32public class ExactKeyMatcher implements NodeMatcher<Operator,
33 OperatorPlan<Operator>> {
34
35 public Map<OperatorKey, OperatorKey> match(OperatorPlan<Operator> plan1,
36 OperatorPlan<Operator> plan2,
37 StringBuilder messages) {
38 // Find plan1.OperatorSet - plan2.OperatorSet
39 int diff1 = diffKeys(plan1, plan2, messages, "plan2") ;
40
41 // Find plan2.OperatorSet - plan1.OperatorSet
42 int diff2 = diffKeys(plan2, plan1, messages, "plan1") ;
43
44 // If there is a problem, just finish here
45 if ( (diff1 != 0) || (diff2 != 0) ) {
46 return null ;
47 }
48
49 // if no problem, we just return exact matching
50 Iterator<Operator> iter = plan1.getKeys().values().iterator() ;
51 Map<OperatorKey, OperatorKey> outputMap
52 = new HashMap<OperatorKey, OperatorKey>() ;
53 while(iter.hasNext()) {
54 Operator op = iter.next() ;
55 outputMap.put(op.getOperatorKey(), op.getOperatorKey()) ;
56 }
57
58 return outputMap;
59 }
60
61 /***
62 * Report plan1.OperatorSet - plan2.OperatorSet
63 *
64 * @param plan1
65 * @param plan2
66 * @param messages where the report messages go. null if no messages needed
67 * @param plan2Name the name that is used to refer to plan2 in messages
68 * @return
69 */
70
71 private int diffKeys(OperatorPlan<Operator> plan1,
72 OperatorPlan<Operator> plan2,
73 StringBuilder messages,
74 String plan2Name) {
75 int count = 0 ;
76
77 // prepare
78 Map<OperatorKey, Operator> keyList = plan1.getKeys() ;
79 Iterator<OperatorKey> iter = keyList.keySet().iterator() ;
80
81 // go through the list of vertices of the first plan
82 while(iter.hasNext()) {
83
84 OperatorKey key = iter.next() ;
85
86 // if the same key doesn't exist in the second plan
87 // we've got a problem
88 if (plan2.getOperator(key) == null) {
89 Operator op1 = plan1.getOperator(key) ;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected