cloud-fan commented on a change in pull request #30614:
URL: https://github.com/apache/spark/pull/30614#discussion_r537310235



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
##########
@@ -61,8 +62,18 @@ object ConstantFolding extends Rule[LogicalPlan] {
       case Size(c: CreateMap, _) if c.children.forall(hasNoSideEffect) =>
         Literal(c.children.length / 2)
 
-      // Fold expressions that are foldable.
-      case e if e.foldable => Literal.create(e.eval(EmptyRow), e.dataType)
+      // Fold expressions that are foldable. To avoid repeatedly evaluating 
expressions which throw
+      // exceptions, we also check whether the expression's children are all 
literals.
+      case e if e.childrenToEvaluate.forall(_.isInstanceOf[Literal]) && 
e.foldable =>
+        val constant = try {
+          Some(e.eval(EmptyRow))

Review comment:
       hmm, then it's a big perf regression for ANSI mode, as all math 
operations can't do constant folding.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to