Github user scwf commented on a diff in the pull request:
https://github.com/apache/spark/pull/6104#discussion_r30566606
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/functions.scala ---
@@ -291,6 +291,269 @@ object functions {
def max(columnName: String): Column = max(Column(columnName))
//////////////////////////////////////////////////////////////////////////////////////////////
+ // Window functions
+
//////////////////////////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Window function: returns the lag value of current row of the
expression,
+ * null when the current row extends before the beginning of the window.
+ *
+ * @group window_funcs
+ */
+ def lag(columnName: String): Column = {
+ lag(columnName, 1)
+ }
+
+ /**
+ * Window function: returns the lag value of current row of the column,
+ * null when the current row extends before the beginning of the window.
+ *
+ * @group window_funcs
+ */
+ def lag(e: Column): Column = {
+ lag(e, 1)
+ }
+
+ /**
+ * Window function: returns the lag values of current row of the
expression,
+ * null when the current row extends before the beginning of the window.
+ *
+ * @group window_funcs
+ */
+ def lag(e: Column, count: Int): Column = {
+ lag(e, count, null)
+ }
+
+ /**
+ * Window function: returns the lag values of current row of the column,
+ * null when the current row extends before the beginning of the window.
+ *
+ * @group window_funcs
+ */
+ def lag(columnName: String, count: Int): Column = {
+ lag(columnName, count, null)
+ }
+
+ /**
+ * Window function: returns the lag values of current row of the column,
+ * given default value when the current row extends before the beginning
+ * of the window.
+ *
+ * @group window_funcs
+ */
+ def lag(columnName: String, count: Int, defaultValue: Any): Column = {
+ lag(Column(columnName), count, defaultValue)
+ }
+
+ /**
+ * Window function: returns the lag values of current row of the
expression,
+ * given default value when the current row extends before the beginning
+ * of the window.
+ *
+ * @group window_funcs
+ */
+ def lag(e: Column, count: Int, defaultValue: Any): Column = {
+ UnresolvedWindowFunction("lag", e.expr :: Literal(count) ::
Literal(defaultValue) :: Nil)
+ }
+
+ /**
+ * Window function: returns the lead value of current row of the column,
+ * null when the current row extends before the end of the window.
+ *
+ * @group window_funcs
+ */
+ def lead(columnName: String): Column = {
+ lead(columnName, 1)
+ }
+
+ /**
+ * Window function: returns the lead value of current row of the
expression,
+ * null when the current row extends before the end of the window.
+ *
+ * @group window_funcs
+ */
+ def lead(e: Column): Column = {
+ lead(e, 1)
+ }
+
+ /**
+ * Window function: returns the lead values of current row of the column,
+ * null when the current row extends before the end of the window.
+ *
+ * @group window_funcs
+ */
+ def lead(columnName: String, count: Int): Column = {
+ lead(columnName, count, null)
+ }
+
+ /**
+ * Window function: returns the lead values of current row of the
expression,
+ * null when the current row extends before the end of the window.
+ *
+ * @group window_funcs
+ */
+ def lead(e: Column, count: Int): Column = {
+ lead(e, count, null)
+ }
+
+ /**
+ * Window function: returns the lead values of current row of the column,
+ * given default value when the current row extends before the end of
the window.
+ *
+ * @group window_funcs
+ */
+ def lead(columnName: String, count: Int, defaultValue: Any): Column = {
+ lead(Column(columnName), count, defaultValue)
+ }
+
+ /**
+ * Window function: returns the lead values of current row of the
expression,
+ * given default value when the current row extends before the end of
the window.
+ *
+ * @group window_funcs
+ */
+ def lead(e: Column, count: Int, defaultValue: Any): Column = {
+ UnresolvedWindowFunction("lead", e.expr :: Literal(count) ::
Literal(defaultValue) :: Nil)
+ }
+
+ /**
+ * Returns a new [[WindowFunctionDefinition]] partitioned by the
specified column.
+ * For example:
+ * {{{
+ * // The following 2 are equivalent
+ * partitionBy("k1", "k2").orderBy("k3")
+ * partitionBy($"K1", $"k2").orderBy($"k3")
+ * }}}
+ * @group window_funcs
+ */
+ @scala.annotation.varargs
+ def partitionBy(colName: String, colNames: String*):
WindowFunctionDefinition = {
+ new WindowFunctionDefinition().partitionBy(colName, colNames: _*)
+ }
+
+ /**
+ * Returns a new [[WindowFunctionDefinition]] partitioned by the
specified column.
+ * For example:
+ * {{{
+ * partitionBy($"col1", $"col2").orderBy("value")
+ * }}}
+ * @group window_funcs
+ */
+ @scala.annotation.varargs
+ def partitionBy(cols: Column*): WindowFunctionDefinition = {
--- End diff --
i think we do not need add `withColumn`, `preceding`, `following` etc,
since WindowFunctionDefinition.partitionBy will return a instance of
WindowFunctionDefinition, then you can call any method of
`WindowFunctionDefinition` to update it.
Note: i mean you can add a companion object for WindowFunctionDefinition
---
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]