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

 ##########
 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:
   @maropu Thanks. Will address two points.

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


With regards,
Apache Git Services

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

Reply via email to