public static ExprNodeEvaluator toCachedEval(ExprNodeEvaluator eval) {
    if (eval instanceof ExprNodeGenericFuncEvaluator) {
      EvaluatorContext context = new EvaluatorContext();
      iterate(eval, context);
      if (context.hasReference) {
        return new ExprNodeEvaluatorHead(eval);
      }
    }
    // has nothing to be cached
    return eval;
  }
Should be called before eval is initialized
ql/src/java/org/apache/hadoop/hive/ql/exec/ExprNodeEvaluatorFactory.java