You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2020/10/01 08:04:26 UTC

[GitHub] [spark] maropu commented on a change in pull request #29900: [SPARK-32958][SQL] Prune unnecessary columns from JsonToStructs

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



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/OptimizeJsonExprs.scala
##########
@@ -38,6 +43,15 @@ object OptimizeJsonExprs extends Rule[LogicalPlan] {
         // so `JsonToStructs` might throw error in runtime. Thus we cannot optimize
         // this case similarly.
         child
+
+      case g @ GetStructField(jsonToStructs: JsonToStructs, ordinal, _) =>
+        val prunedSchema = StructType(Seq(jsonToStructs.schema.asInstanceOf[StructType](ordinal)))

Review comment:
       nit: we might be able to filter out a schema.length=1 case:
   ```
         case g @ GetStructField(jts @ JsonToStructs(schema: StructType, _, _, _), ordinal, _)
             if schema.length > 1 =>
           val prunedSchema = StructType(Seq(schema(ordinal)))
   ```

##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/OptimizeJsonExprs.scala
##########
@@ -38,6 +43,15 @@ object OptimizeJsonExprs extends Rule[LogicalPlan] {
         // so `JsonToStructs` might throw error in runtime. Thus we cannot optimize
         // this case similarly.
         child
+
+      case g @ GetStructField(jsonToStructs: JsonToStructs, ordinal, _) =>
+        val prunedSchema = StructType(Seq(jsonToStructs.schema.asInstanceOf[StructType](ordinal)))
+        g.copy(child = jsonToStructs.copy(schema = prunedSchema), ordinal = 0)
+
+      case g @ GetArrayStructFields(jsonToStructs: JsonToStructs, _, _, _, _) =>

Review comment:
       ditto




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org