private static ExprNodeDesc foldExprShortcut(ExprNodeDesc desc, Map<ColumnInfo, ExprNodeDesc> constants,
      ConstantPropagateProcCtx cppCtx, Operator<? extends Serializable> op, int tag,
      boolean propagate) throws UDFArgumentException {
    // Combine NOT operator with the child operator. Otherwise, the following optimization
    // from bottom up could lead to incorrect result, such as not(x > 3 and x is not null),
    // should not be optimized to not(x > 3), but (x <=3 or x is null).
    desc = foldNegative(desc);

    if (desc instanceof ExprNodeGenericFuncDesc) {
      ExprNodeGenericFuncDesc funcDesc = (ExprNodeGenericFuncDesc) desc;

      GenericUDF udf = funcDesc.getGenericUDF();

      boolean propagateNext = propagate && propagatableUdfs.contains(udf.getClass());
      List<ExprNodeDesc> newExprs = new ArrayList<ExprNodeDesc>();
      for (ExprNodeDesc childExpr : desc.getChildren()) {
        newExprs.add(foldExpr(childExpr, constants, cppCtx, op, tag, propagateNext));
      }

      // Don't evaluate nondeterministic function since the value can only calculate during runtime.
      if (!isConstantFoldableUdf(udf, newExprs)) {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Function " + udf.getClass() + " is not deterministic. Don't evaluate immediately.");
        }
        ((ExprNodeGenericFuncDesc) desc).setChildren(newExprs);
        return desc;
      }

      // Check if the function can be short cut.
      ExprNodeDesc shortcut = shortcutFunction(udf, newExprs, op);
      if (shortcut != null) {
        LOG.debug("Folding expression:{} -> {}", desc, shortcut);
        return shortcut;
      }
      ((ExprNodeGenericFuncDesc) desc).setChildren(newExprs);
    }
    return desc;
  }
Fold input expression desc, only performing short-cutting.

Unnecessary AND/OR operations involving a constant true/false value will be eliminated.

@param desc folding expression
@param constants current propagated constant map
@param cppCtx
@param op processing operator
@param propagate if true, assignment expressions will be added to constants.
@return fold expression
@throws UDFArgumentException
ql/src/java/org/apache/hadoop/hive/ql/optimizer/ConstantPropagateProcFactory.java