You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "alamb (via GitHub)" <gi...@apache.org> on 2023/06/22 17:12:10 UTC

[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #6746: RFC: Make it easier to call window functions via expression API (and add example)

alamb commented on code in PR #6746:
URL: https://github.com/apache/arrow-datafusion/pull/6746#discussion_r1238815288


##########
datafusion/core/src/dataframe.rs:
##########
@@ -219,6 +219,23 @@ impl DataFrame {
     }
 
     /// Apply one or more window functions ([`Expr::WindowFunction`]) to extend the schema
+    ///
+    /// ```
+    /// # use datafusion::prelude::*;
+    /// # use datafusion::error::Result;
+    /// # #[tokio::main]
+    /// # async fn main() -> Result<()> {
+    /// let ctx = SessionContext::new();
+    /// let df = ctx.read_csv("tests/data/example.csv", CsvReadOptions::new()).await?;
+    ///
+    /// // The following is the equivalent of "SELECT FIRST_VALUE(b) OVER(PARTITION BY a)"
+    /// let first_value = first_value(col("b"))

Review Comment:
   The rest of the PR is motivated by trying to write this example. It turned out to be quite a pain to create the right `Expr`.



##########
datafusion/expr/src/expr.rs:
##########
@@ -459,22 +482,40 @@ pub struct WindowFunction {
 }
 
 impl WindowFunction {
-    /// Create a new Window expression
-    pub fn new(
-        fun: window_function::WindowFunction,
-        args: Vec<Expr>,
-        partition_by: Vec<Expr>,
-        order_by: Vec<Expr>,
-        window_frame: window_frame::WindowFrame,
-    ) -> Self {
+    /// Create a new Window expression with the specified argument an
+    /// empty `OVER` clause
+    pub fn new(fun: impl Into<window_function::WindowFunction>, args: Vec<Expr>) -> Self {

Review Comment:
   This is the major change -- so that WindowFunction acts like a `Builder` which can be used to set `partition by`, `order by` and `window_frame` with a more self documenting style



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org