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

    https://github.com/apache/spark/pull/14106#discussion_r70584787
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
 ---
    @@ -165,36 +165,48 @@ object PushProjectThroughSample extends 
Rule[LogicalPlan] {
      * but can also benefit other operators.
      */
     object RemoveAliasOnlyProject extends Rule[LogicalPlan] {
    -  // Check if projectList in the Project node has the same attribute names 
and ordering
    -  // as its child node.
    +  /**
    +   * Returns true if the project list is semantically same with child 
output, after strip alias on
    +   * attribute.
    +   */
       private def isAliasOnly(
           projectList: Seq[NamedExpression],
           childOutput: Seq[Attribute]): Boolean = {
    -    if (!projectList.forall(_.isInstanceOf[Alias]) || projectList.length 
!= childOutput.length) {
    +    if (projectList.length != childOutput.length) {
           false
         } else {
    -      projectList.map(_.asInstanceOf[Alias]).zip(childOutput).forall { 
case (a, o) =>
    -        a.child match {
    -          case attr: Attribute if a.name == attr.name && 
attr.semanticEquals(o) => true
    -          case _ => false
    -        }
    +      stripAliasOnAttribute(projectList).zip(childOutput).forall {
    +        case (a: Attribute, o) if a semanticEquals o => true
    +        case _ => false
           }
         }
       }
     
    +  private def stripAliasOnAttribute(projectList: Seq[NamedExpression]) = {
    +    projectList.map {
    +      // Alias with metadata can not be striped, or the metadata will be 
lost.
    --- End diff --
    
    Nit: striped => stripped


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