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

    https://github.com/apache/flink/pull/4070#discussion_r120078093
  
    --- Diff: 
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/plan/ProjectionTranslator.scala
 ---
    @@ -226,30 +226,69 @@ object ProjectionTranslator {
           overWindows: Array[OverWindow],
           tEnv: TableEnvironment): Seq[Expression] = {
     
    -    def resolveOverWindow(unresolvedCall: UnresolvedOverCall): Expression 
= {
    -
    -      val overWindow = 
overWindows.find(_.alias.equals(unresolvedCall.alias))
    -      if (overWindow.isDefined) {
    -        OverCall(
    -          unresolvedCall.agg,
    -          overWindow.get.partitionBy,
    -          overWindow.get.orderBy,
    -          overWindow.get.preceding,
    -          overWindow.get.following)
    -      } else {
    -        unresolvedCall
    -      }
    -    }
    +    exprs.map(e => replaceOverCall(e, overWindows, tEnv))
    +  }
     
    -    val projectList = new ListBuffer[Expression]
    -    exprs.foreach {
    -      case Alias(u: UnresolvedOverCall, name, _) =>
    -        projectList += Alias(resolveOverWindow(u), name)
    +  /**
    +    * Find and replace UnresolvedOverCall with OverCall
    +    *
    +    * @param expr    the expression to check
    +    * @return an expression with correct resolved OverCall
    +    */
    +  private def replaceOverCall(
    +    expr: Expression,
    +    overWindows: Array[OverWindow],
    +    tableEnv: TableEnvironment): Expression = {
    +
    +    expr match {
           case u: UnresolvedOverCall =>
    -        projectList += resolveOverWindow(u)
    -      case e: Expression => projectList += e
    +        val overWindow = overWindows.find(_.alias.equals(u.alias))
    +        if (overWindow.isDefined) {
    +          OverCall(
    +            u.agg,
    +            overWindow.get.partitionBy,
    +            overWindow.get.orderBy,
    +            overWindow.get.preceding,
    +            overWindow.get.following)
    +        } else {
    +          u
    +        }
    +
    +      case u: UnaryExpression =>
    +        val c = replaceOverCall(u.child, overWindows, tableEnv)
    --- End diff --
    
    Can we add a projection for cover this condition? Such as add 
`Abs((countFun('b) over 'w))`.
    What do you think?


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

Reply via email to