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 2019/08/19 06:12:16 UTC

[GitHub] [spark] maropu commented on a change in pull request #24525: [SPARK-27633][SQL] Remove redundant aliases in NestedColumnAliasing

maropu commented on a change in pull request #24525: [SPARK-27633][SQL] Remove redundant aliases in NestedColumnAliasing
URL: https://github.com/apache/spark/pull/24525#discussion_r315050169
 
 

 ##########
 File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/NestedColumnAliasing.scala
 ##########
 @@ -119,9 +119,21 @@ object NestedColumnAliasing {
       .filter(!_.references.subsetOf(AttributeSet(otherRootReferences)))
       .groupBy(_.references.head)
       .flatMap { case (attr, nestedFields: Seq[ExtractValue]) =>
+        // Remove redundant `ExtractValue`s if they share the same parent nest field.
+        // For example, when `a.b` and `a.b.c` are in project list, we only need to alias `a.b`.
+        // We only need to deal with two `ExtractValue`: `GetArrayStructFields` and
+        // `GetStructField`. Please refer to the method `collectRootReferenceAndExtractValue`.
+        val dedupNestedFields = nestedFields.filter {
+          case a @ GetArrayStructFields(child, _, _, _, _) =>
+            nestedFields.forall(f => f == a || child.find(_.semanticEquals(f)).isEmpty)
+          case n @ GetStructField(child, _, _) =>
+            nestedFields.forall(f => f == n || child.find(_.semanticEquals(f)).isEmpty)
 
 Review comment:
   Can we merge the two entry into one? e.g.,
   ```
             case e @ (_: GetStructField | _: GetArrayStructFields) =>
               nestedFields.forall(f => f == e || e.children.head.find(_.semanticEquals(f)).isEmpty)
   ```

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


With regards,
Apache Git Services

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