@VisibleForTesting
  static ExprNodeDesc compactExpr(ExprNodeDesc expr) {
    // If this is a constant boolean expression, return the value.
    if (expr == null) {
      return null;
    }
    if (expr instanceof ExprNodeConstantDesc) {
      if (((ExprNodeConstantDesc)expr).getValue() == null) {
        return null;
      }
      if (!isBooleanExpr(expr)) {
        throw new IllegalStateException("Unexpected non-boolean ExprNodeConstantDesc: "
            + expr.getExprString(true));
      }
      return expr;
    } else if (expr instanceof ExprNodeColumnDesc) {
      return expr;
    } else if (expr instanceof ExprNodeGenericFuncDesc) {
      GenericUDF udf = ((ExprNodeGenericFuncDesc)expr).getGenericUDF();
      boolean isAnd = udf instanceof GenericUDFOPAnd;
      boolean isOr = udf instanceof GenericUDFOPOr;
      List<ExprNodeDesc> children = expr.getChildren();

      if (isAnd) {
        // Non-partition expressions are converted to nulls.
        List<ExprNodeDesc> newChildren = new ArrayList<>();
        boolean allTrue = true;
        for (ExprNodeDesc child : children) {
          ExprNodeDesc compactChild = compactExpr(child);
          if (compactChild != null) {
            if (!isTrueExpr(compactChild)) {
              newChildren.add(compactChild);
              allTrue = false;
            }
            if (isFalseExpr(compactChild)) {
              return new ExprNodeConstantDesc(Boolean.FALSE);
            }
          } else {
            allTrue = false;
          }
        }

        if (allTrue) {
          return new ExprNodeConstantDesc(Boolean.TRUE);
        }
        if (newChildren.isEmpty()) {
          return null;
        }
        if (newChildren.size() == 1) {
          return newChildren.get(0);
        }

        // Nothing to compact, update expr with compacted children.
        ((ExprNodeGenericFuncDesc) expr).setChildren(newChildren);
      } else if (isOr) {
        // Non-partition expressions are converted to nulls.
        List<ExprNodeDesc> newChildren = new ArrayList<>();
        boolean allFalse = true;
        boolean isNull = false;
        for (ExprNodeDesc child : children) {
          ExprNodeDesc compactChild = compactExpr(child);
          if (compactChild != null) {
            if (isTrueExpr(compactChild)) {
              return new ExprNodeConstantDesc(Boolean.TRUE);
            }
            if (!isNull && !isFalseExpr(compactChild)) {
              newChildren.add(compactChild);
              allFalse = false;
            }
          } else {
            isNull = true;
          }
        }

        if (isNull) {
          return null;
        }
        if (allFalse) {
          return new ExprNodeConstantDesc(Boolean.FALSE);
        }
        if (newChildren.size() == 1) {
          return newChildren.get(0);
        }

        // Nothing to compact, update expr with compacted children.
        ((ExprNodeGenericFuncDesc) expr).setChildren(newChildren);
      }

      return expr;
    } else {
      throw new IllegalStateException("Unexpected type of ExprNodeDesc: " + expr.getExprString(true));
    }
  }
Taking a partition pruning expression, remove the null operands and non-partition columns.
The reason why there are null operands is ExprProcFactory classes, for example
PPRColumnExprProcessor.
@param expr original partition pruning expression.
@return partition pruning expression that only contains partition columns.
ql/src/java/org/apache/hadoop/hive/ql/optimizer/ppr/PartitionPruner.java