maropu commented on a change in pull request #29942:
URL: https://github.com/apache/spark/pull/29942#discussion_r499363266



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/OptimizeJsonExprs.scala
##########
@@ -28,10 +28,36 @@ import org.apache.spark.sql.types.{ArrayType, StructType}
  * The optimization includes:
  * 1. JsonToStructs(StructsToJson(child)) => child.
  * 2. Prune unnecessary columns from GetStructField/GetArrayStructFields + 
JsonToStructs.
+ * 3  struct(from_json.col1, from_json.col2, from_json.col3...) => 
struct(from_json)
  */
 object OptimizeJsonExprs extends Rule[LogicalPlan] {
   override def apply(plan: LogicalPlan): LogicalPlan = plan transform {
     case p => p.transformExpressions {
+
+      case c: CreateNamedStruct
+        if c.valExprs.forall(v => v.isInstanceOf[GetStructField] &&
+          v.asInstanceOf[GetStructField].child.isInstanceOf[JsonToStructs]) =>
+        val jsonToStructs = c.valExprs.map(_.children(0))
+        val semanticEqual = 
jsonToStructs.tail.forall(jsonToStructs.head.semanticEquals(_))

Review comment:
       hm I see. I noticed that it looped `c.valExprs` `{3 x len(c.valExprs)}` 
times to check the condition. Minor optimization though, I thought it would be 
nice if it could stop early if the condition not met.




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