Skip to content

Commit

Permalink
create tests & update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sjrusso8 committed Apr 19, 2024
1 parent e050d9f commit 5343ae3
Show file tree
Hide file tree
Showing 3 changed files with 246 additions and 18 deletions.
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ The following section outlines some of the larger functionality that are not yet

- ![done] TLS authentication & Databricks compatability via the feature flag `feature = 'tls'`
- ![open] StreamingQueryManager
- ![open] Window and ~~Pivot~~ functions
- ![open] UDFs or any type of functionality that takes a closure (foreach, foreachBatch, etc.)

### SparkSession
Expand Down Expand Up @@ -282,6 +281,7 @@ Spark [Column](https://spark.apache.org/docs/latest/api/python/reference/pyspark
| like | ![done] | |
| name | ![done] | |
| otherwise | ![open] | |
| over | ![done] | Refer to **Window** for creating window specifications |
| rlike | ![done] | |
| startswith | ![done] | |
| substr | ![open] | |
Expand Down Expand Up @@ -612,5 +612,24 @@ An array can be made like `lit([1_i16,2_i16,3_i16])` would result in an `ArrayTy
| Struct | | ![open] |


### Window & WindowSpec

For ease of use it's recommended to use `Window` to create the `WindowSpec`.

| Window | API | Comment |
|-------------------------|---------|---------|
| currentRow | ![done] | |
| orderBy | ![done] | |
| partitionBy | ![done] | |
| rangeBetween | ![done] | |
| rowsBetween | ![done] | |
| unboundedFollowing | ![done] | |
| unboundedPreceding | ![done] | |
| WindowSpec.orderBy | ![done] | |
| WindowSpec.partitionBy | ![done] | |
| WindowSpec.rangeBetween | ![done] | |
| WindowSpec.rowsBetween | ![done] | |


[open]: https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/IssueNeutral.svg
[done]: https://cdn.jsdelivr.net/gh/Readme-Workflows/Readme-Icons@main/icons/octicons/ApprovedChanges.svg
18 changes: 17 additions & 1 deletion src/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,28 @@ impl Column {
invoke_func("isNaN", self)
}

/// Defines a windowing column
/// # Arguments:
///
/// * `window`: a [WindowSpec]
///
/// # Example
///
/// ```
/// let window = Window::new()
/// .partitionBy(col("name"))
/// .orderBy([col("age")])
/// .rangeBetween(Window::unboundedPreceding(), Window::currentRow());
///
/// let df = df.withColumn("rank", rank().over(window.clone()))
/// .withColumn("min", min("age").over(window));
/// ```
pub fn over(self, window: WindowSpec) -> Column {
let window_expr = spark::expression::Window {
window_function: Some(Box::new(self.expression)),
partition_spec: window.partition_spec,
order_spec: window.order_spec,
frame_spec: window.frame,
frame_spec: window.frame_spec,
};

let expression = spark::Expression {
Expand Down
Loading

0 comments on commit 5343ae3

Please sign in to comment.