HyukjinKwon commented on a change in pull request #30504:
URL: https://github.com/apache/spark/pull/30504#discussion_r533123592



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
##########
@@ -48,6 +48,9 @@ object ConstantFolding extends Rule[LogicalPlan] {
       // object and running eval unnecessarily.
       case l: Literal => l
 
+      case Size(c: CreateArray, _) => Literal(c.children.length)
+      case Size(c: CreateMap, _) => Literal(c.children.length / 2)

Review comment:
       Hm .. one case I can imagine is the case when the children of 
`CreateArray` or `CreateMap` throw an exception e.g.) from a UDF or when ANSI 
mode is enabled. After this change, looks it's going to suppress such 
exceptions. For example:
   
   ```scala
   spark.range(1).selectExpr("size(array(assert_true(false)))").show()
   ```
   
   As an alternative, we could maybe only allow this when the children of 
`CreateArray` or `CreateMap` are safe and don't throw an exception? e.g.) only 
when they are `AttributeReference`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