luluorta commented on a change in pull request #30614:
URL: https://github.com/apache/spark/pull/30614#discussion_r540191133



##########
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:
       According to @cloud-fan 's advice, I refactor this patch by using 
`RaiseError` as constant. Now we don't need to bother with the foldable 
expressions which can throw exceptions, cause they are still foldable and will 
be folded to `RaiseError`s.




----------------------------------------------------------------
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