Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MINOR][PySpark][SQL][DOC] Fix rowsBetween doc in Window #24864

Closed
wants to merge 1 commit into from

Conversation

viirya
Copy link
Member

@viirya viirya commented Jun 13, 2019

What changes were proposed in this pull request?

I suspect that the doc of rowsBetween methods in Scala and PySpark looks wrong.
Because:

scala> val df = Seq((1, "a"), (2, "a"), (3, "a"), (4, "a"), (5, "a"), (6, "a")).toDF("id", "category")                                                 
df: org.apache.spark.sql.DataFrame = [id: int, category: string]                                                                                       
                                                                                                                                                       
scala> val byCategoryOrderedById = Window.partitionBy('category).orderBy('id).rowsBetween(-1, 2)                                                       
byCategoryOrderedById: org.apache.spark.sql.expressions.WindowSpec = org.apache.spark.sql.expressions.WindowSpec@7f04de97                              
                                                                                                                                                       
scala> df.withColumn("sum", sum('id) over byCategoryOrderedById).show()                                                                                
+---+--------+---+                                                                                                                                     
| id|category|sum|                                                                                                                                     
+---+--------+---+                                                                                                                                     
|  1|       a|  6|              # sum from index 0 to (0 + 2): 1 + 2 + 3 = 6                                                                                                                      
|  2|       a| 10|              # sum from index (1 - 1) to (1 + 2): 1 + 2 + 3 + 4 = 10                                                                                                                       
|  3|       a| 14|                                                                                                                             
|  4|       a| 18|                                                                                                                                     
|  5|       a| 15|
|  6|       a| 11|
+---+--------+---+

So the frame (-1, 2) for row with index 5, as described in the doc, should range from index 4 to index 7.

How was this patch tested?

N/A, just doc change.

@viirya
Copy link
Member Author

viirya commented Jun 13, 2019

cc @HyukjinKwon @dongjoon-hyun

@SparkQA
Copy link

SparkQA commented Jun 13, 2019

Test build #106474 has finished for PR 24864 at commit d072de5.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

Copy link
Member

@HyukjinKwon HyukjinKwon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@HyukjinKwon
Copy link
Member

Merged to master.

Had a conflict against branch-2.4 but I think we don't have to bother backport ..

@viirya
Copy link
Member Author

viirya commented Jun 14, 2019

Yea, I do think so. Thanks @HyukjinKwon

emanuelebardelli pushed a commit to emanuelebardelli/spark that referenced this pull request Jun 15, 2019
## What changes were proposed in this pull request?

I suspect that the doc of `rowsBetween` methods in Scala and PySpark looks wrong.
Because:

```scala
scala> val df = Seq((1, "a"), (2, "a"), (3, "a"), (4, "a"), (5, "a"), (6, "a")).toDF("id", "category")
df: org.apache.spark.sql.DataFrame = [id: int, category: string]

scala> val byCategoryOrderedById = Window.partitionBy('category).orderBy('id).rowsBetween(-1, 2)
byCategoryOrderedById: org.apache.spark.sql.expressions.WindowSpec = org.apache.spark.sql.expressions.WindowSpec7f04de97

scala> df.withColumn("sum", sum('id) over byCategoryOrderedById).show()
+---+--------+---+
| id|category|sum|
+---+--------+---+
|  1|       a|  6|              # sum from index 0 to (0 + 2): 1 + 2 + 3 = 6
|  2|       a| 10|              # sum from index (1 - 1) to (1 + 2): 1 + 2 + 3 + 4 = 10
|  3|       a| 14|
|  4|       a| 18|
|  5|       a| 15|
|  6|       a| 11|
+---+--------+---+
```

So the frame (-1, 2) for row with index 5, as described in the doc, should range from index 4 to index 7.

## How was this patch tested?

N/A, just doc change.

Closes apache#24864 from viirya/window-spec-doc.

Authored-by: Liang-Chi Hsieh <viirya@gmail.com>
Signed-off-by: HyukjinKwon <gurwls223@apache.org>
@viirya viirya deleted the window-spec-doc branch December 27, 2023 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants