Hi all:
  I am working on HIVE-17486<https://issues.apache.org/jira/browse/HIVE-17486> 
and met a problem about DefaultRuleDispatcher. It will apply rules to the 
operator tree. Here it first compute the minCost of a rule to node( like an 
operator in the operator tree). But how to deal with the case where  the 
minCost are same if two rules applied to node. I guess in current code, only 1 
rule will be applied to the node(May be you will say that 
DefaultRuleDispatcher<https://github.com/apache/hive/blob/master/ql/src/java/org/apache/hadoop/hive/ql/lib/DefaultRuleDispatcher.java#L48>
#rules<https://github.com/apache/hive/blob/master/ql/src/java/org/apache/hadoop/hive/ql/lib/DefaultRuleDispatcher.java#L48>
 is a HashMap and is designed to one key with one value, but in my code, I have 
changed rules to multiMap which is designed to one key with multiple values)

{code}

@Override
public Object dispatch(Node nd, Stack<Node> ndStack, Object... nodeOutputs)
    throws SemanticException {

  // find the firing rule
  // find the rule from the stack specified
  Rule rule = null;
  int minCost = Integer.MAX_VALUE;
  for (Rule r : procRules.keySet()) {
    int cost = r.cost(ndStack);
    if ((cost >= 0) && (cost <= minCost)) {  // In current code , only 1 rule 
will be applied
      minCost = cost;
      rule = r;
    }
  }

  NodeProcessor proc;

  if (rule == null) {
    proc = defaultProc;
  } else {
    proc = procRules.get(rule);
  }

  // Do nothing in case proc is null
  if (proc != null) {
    // Call the process function
    return proc.process(nd, ndStack, procCtx, nodeOutputs);
  } else {
    return null;
  }
}

{code}





Appreciate to get some suggestions from you.










Best Regards
Kelly Zhang/Zhang,Liyun

Reply via email to