[ 
https://issues.apache.org/jira/browse/SPARK-7322?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Reynold Xin updated SPARK-7322:
-------------------------------
    Description: 
Here's a proposal for supporting window functions in the DataFrame DSL:

1. Add an over function to Column:
{code}
class Column {
  ...
  def over(): WindowFunctionSpec
  ...
}
{code}

2. WindowFunctionSpec:
{code}
// By default frame = full partition
class WindowFunctionSpec {
  def partitionBy(cols: Column*): WindowFunctionSpec
  def orderBy(cols: Column*): WindowFunctionSpec

  // restrict frame beginning from current row - n position
  def rowsPreceding(n: Int): WindowFunctionSpec

  // restrict frame ending from current row - n position
  def rowsFollowing(n: Int): WindowFunctionSpec

  def rangePreceding(n: Int): WindowFunctionSpec
  def rowsFollowing(n: Int): WindowFunctionSpec
}
{code}

Here's an example to use it:
{code}
df.select(
  df.store,
  df.date,
  df.sales,
  avg(df.sales).over.partitionBy(df.store)
                    .orderBy(df.store) 
                    .rowsFollowing(0)    // this means from unbounded preceding 
to current row
)
{code}

  was:


class Column {
  ...
  def over(): WindowFunctionSpec
  ...
}

// By default frame = full partition
class WindowFunctionSpec {
  def partitionBy(cols: Column*): WindowFunctionSpec
  def orderBy(cols: Column*): WindowFunctionSpec

  // restrict frame beginning from current row - n position
  def rowsPreceding(n: Int): WindowFunctionSpec

  // restrict frame ending from current row - n position
  def rowsFollowing(n: Int): WindowFunctionSpec

  def rangePreceding(n: Int): WindowFunctionSpec
  def rowsFollowing(n: Int): WindowFunctionSpec
}


df.select(
  df.store,
  df.date,
  df.sales,
  avg(df.sales).over.partitionBy(df.store)
                    .orderBy(df.store) 
                    .rowsFollowing(0)    // this means from unbounded preceding 
to current row
)


> Add DataFrame DSL for window function support
> ---------------------------------------------
>
>                 Key: SPARK-7322
>                 URL: https://issues.apache.org/jira/browse/SPARK-7322
>             Project: Spark
>          Issue Type: Sub-task
>          Components: SQL
>            Reporter: Reynold Xin
>
> Here's a proposal for supporting window functions in the DataFrame DSL:
> 1. Add an over function to Column:
> {code}
> class Column {
>   ...
>   def over(): WindowFunctionSpec
>   ...
> }
> {code}
> 2. WindowFunctionSpec:
> {code}
> // By default frame = full partition
> class WindowFunctionSpec {
>   def partitionBy(cols: Column*): WindowFunctionSpec
>   def orderBy(cols: Column*): WindowFunctionSpec
>   // restrict frame beginning from current row - n position
>   def rowsPreceding(n: Int): WindowFunctionSpec
>   // restrict frame ending from current row - n position
>   def rowsFollowing(n: Int): WindowFunctionSpec
>   def rangePreceding(n: Int): WindowFunctionSpec
>   def rowsFollowing(n: Int): WindowFunctionSpec
> }
> {code}
> Here's an example to use it:
> {code}
> df.select(
>   df.store,
>   df.date,
>   df.sales,
>   avg(df.sales).over.partitionBy(df.store)
>                     .orderBy(df.store) 
>                     .rowsFollowing(0)    // this means from unbounded 
> preceding to current row
> )
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

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

Reply via email to