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_r315461919
 
 

 ##########
 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:
   Thanks for the check! Ur, one more comment: can we avoid the loop of 
`length(nestedFields)^2`? in: 
https://github.com/apache/spark/pull/24525/files#diff-43334bab9616cc53e8797b9afa9fc7aaR129

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


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to