Github user eyalfa commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14444#discussion_r73103369
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
 ---
    @@ -2065,18 +2065,28 @@ object EliminateUnions extends Rule[LogicalPlan] {
      */
     object CleanupAliases extends Rule[LogicalPlan] {
       private def trimAliases(e: Expression): Expression = {
    -    var stop = false
         e.transformDown {
    -      // CreateStruct is a special case, we need to retain its top level 
Aliases as they decide the
    -      // name of StructField. We also need to stop transform down this 
expression, or the Aliases
    -      // under CreateStruct will be mistakenly trimmed.
    -      case c: CreateStruct if !stop =>
    -        stop = true
    -        c.copy(children = c.children.map(trimNonTopLevelAliases))
    -      case c: CreateStructUnsafe if !stop =>
    -        stop = true
    -        c.copy(children = c.children.map(trimNonTopLevelAliases))
    -      case Alias(child, _) if !stop => child
    +      /**
    +        *  [[CreateStruct]] is a special case as it uses its top level 
Aliases to decide the
    +        *  name of StructField.
    +        *  we tackle this by replacing [[CreateStruct]] with 
[[CreateNamedStruct]]
    +        *  which encodes the field names as child literals.
    +        */
    +      case c @ CreateStruct(children) =>
    --- End diff --
    
    this is basically what this PR does.
    since CreateStruct is public API it can't be removed, the next best thing 
to do is transform it as soon as possible.
    one thing I'm not sure about Spark's behavior, what happens when the 
optimizer adds expressions, are they supposed to be resolved OOTB or are they 
being put through the Analyzer for cleanup and canonization?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to