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

    https://github.com/apache/spark/pull/5604#discussion_r29638526
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
 ---
    @@ -529,6 +534,164 @@ class Analyzer(
               makeGeneratorOutput(p.generator, p.generatorOutput), p.child)
         }
       }
    +
    +  object ResolveWindowFunction extends Rule[LogicalPlan] {
    +    def hasWindowFunction(projectList: Seq[NamedExpression]): Boolean =
    +      projectList.exists(hasWindowFunction)
    +
    +    def hasWindowFunction(expr: NamedExpression): Boolean = {
    +      expr.find {
    +        case window: WindowExpression => true
    +        case _ => false
    +      }.isDefined
    +    }
    +
    +    /**
    +     * 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)
    +      // Extract expressions which in windowExpressions but not in 
regularExpressions.
    +      val extractedExprBuffer = new ArrayBuffer[NamedExpression]()
    +      def extractExpr(
    +          expr: Expression): Expression = expr match {
    +        case ne: NamedExpression =>
    +          // If a named expression is not in regularExpressions, add iut
    +          val missingExpr =
    +            AttributeSet(Seq(expr)) -- (regularExpressions ++ 
extractedExprBuffer)
    +          if (missingExpr.nonEmpty) {
    +            extractedExprBuffer += ne
    +          }
    +          ne.toAttribute
    +        case l: Literal => l // Do not use Alias to wrap a Literal.
    --- End diff --
    
    maybe case e: Expression if e.foldable => e


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