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

    https://github.com/apache/spark/pull/9819#discussion_r47450842
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/windowExpressions.scala
 ---
    @@ -246,85 +260,238 @@ object SpecifiedWindowFrame {
       }
     }
     
    +case class UnresolvedWindowExpression(
    +    child: Expression,
    +    windowSpec: WindowSpecReference) extends UnaryExpression with 
Unevaluable {
    +
    +  override def dataType: DataType = throw new UnresolvedException(this, 
"dataType")
    +  override def foldable: Boolean = throw new UnresolvedException(this, 
"foldable")
    +  override def nullable: Boolean = throw new UnresolvedException(this, 
"nullable")
    +  override lazy val resolved = false
    +}
    +
    +case class WindowExpression(
    +    windowFunction: Expression,
    +    windowSpec: WindowSpecDefinition) extends Expression with Unevaluable {
    +
    +  override def children: Seq[Expression] = windowFunction :: windowSpec :: 
Nil
    +
    +  override def dataType: DataType = windowFunction.dataType
    +  override def foldable: Boolean = windowFunction.foldable
    +  override def nullable: Boolean = windowFunction.nullable
    +
    +  override def toString: String = s"$windowFunction $windowSpec"
    +}
    +
     /**
    - * Every window function needs to maintain a output buffer for its output.
    - * It should expect that for a n-row window frame, it will be called n 
times
    - * to retrieve value corresponding with these n rows.
    + * A window function is a function that can only be evaluated in the 
context of a window operator.
      */
     trait WindowFunction extends Expression {
    -  def init(): Unit
    +  /** Frame in which the window operator must be executed. */
    +  def frame: WindowFrame = UnspecifiedFrame
    +}
     
    -  def reset(): Unit
    +/**
    + * An offset window function is a window function that returns the value 
of the input column offset
    + * by a number of rows within the partition. For instance: an 
OffsetWindowfunction for value x with
    + * offset -2, will get the value of x 2 rows back in the partition.
    + */
    +abstract class OffsetWindowFunction
    +  extends Expression with WindowFunction with Unevaluable with 
ImplicitCastInputTypes {
    +  val input: Expression
    +  val default: Expression
    +  val offset: Expression
    +  val offsetSign: Int
    +
    +  override def children: Seq[Expression] = Seq(input, offset, default)
     
    -  def prepareInputParameters(input: InternalRow): AnyRef
    +  override def foldable: Boolean = input.foldable && (default == null || 
default.foldable)
    --- End diff --
    
    I guess the results still depend on the number of rows of that partition. I 
tried a few queries in postgres
    ```
    yhuai=# select lead(1, 2) over();
     lead 
    ------
         
    (1 row)
    
    yhuai=# select lead(1, 2) over() from (select 100 as k union all select 99 
as k) tmp;
     lead 
    ------
         
         
    (2 rows)
    
    yhuai=# select lead(1, 2) over() from (select 100 as k union all select 99 
as k union all select 98 as k) tmp;
     lead 
    ------
        1
         
         
    (3 rows)
    ```


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