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

    https://github.com/apache/spark/pull/5604#discussion_r29616703
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
 ---
    @@ -529,6 +533,133 @@ class Analyzer(
               makeGeneratorOutput(p.generator, p.generatorOutput), p.child)
         }
       }
    +
    +  object ResolveWindowFunction extends Rule[LogicalPlan] {
    +    def hasWindowFunction(projectList: Seq[NamedExpression]): Boolean = {
    +      projectList.foreach ( _.foreach {
    +        case window: WindowExpression => return true
    +        case _ =>
    +      })
    +
    +      return false
    +    }
    +
    +    def hasWindowFunction(expr: NamedExpression): Boolean = {
    +      expr.foreach {
    +        case window: WindowExpression => return true
    +        case _ =>
    +      }
    +
    +      return false
    +    }
    +
    +    /**
    +     * From a Seq of [[NamedExpression]]s, extract window expressions and
    +     * other regular expressions.
    +     */
    +    def extract(
    +        expressions: Seq[NamedExpression]): (Seq[NamedExpression], 
Seq[NamedExpression]) = {
    +      val (windowExpressions, regularExpressions) = 
expressions.partition(hasWindowFunction)
    +      // Also need to extract all UnresolvedAttribute from 
windowExpressions.
    +      // For example, in the case of SUM(x) OVER (...), we need to extract 
x.
    +      val attributes = windowExpressions.flatMap(_.collect {
    +        case attribute: Attribute => attribute
    +      })
    +
    +      // Figure out which ones are missing from the regularExpressions,
    +      // so that we can add them.
    +      val requiredAttributes = AttributeSet(attributes)
    +      val missingInProject = requiredAttributes -- regularExpressions
    +
    +      (windowExpressions, regularExpressions ++ missingInProject)
    +    }
    +
    +    def addWindow(windowExpressions: Seq[NamedExpression], child: 
LogicalPlan): LogicalPlan = {
    +      val groupedWindowExpression = windowExpressions.groupBy { expr =>
    +        expr.collect {
    +          case window: WindowExpression => window.windowSpec
    +        }.head
    --- End diff --
    
    use find


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

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

Reply via email to