-
- Downloads
[SPARK-17845] [SQL] More self-evident window function frame boundary API
## What changes were proposed in this pull request? This patch improves the window function frame boundary API to make it more obvious to read and to use. The two high level changes are: 1. Create Window.currentRow, Window.unboundedPreceding, Window.unboundedFollowing to indicate the special values in frame boundaries. These methods map to the special integral values so we are not breaking backward compatibility here. This change makes the frame boundaries more self-evident (instead of Long.MinValue, it becomes Window.unboundedPreceding). 2. In Python, for any value less than or equal to JVM's Long.MinValue, treat it as Window.unboundedPreceding. For any value larger than or equal to JVM's Long.MaxValue, treat it as Window.unboundedFollowing. Before this change, if the user specifies any value that is less than Long.MinValue but not -sys.maxsize (e.g. -sys.maxsize + 1), the number we pass over to the JVM would overflow, resulting in a frame that does not make sense. Code example required to specify a frame before this patch: ``` Window.rowsBetween(-Long.MinValue, 0) ``` While the above code should still work, the new way is more obvious to read: ``` Window.rowsBetween(Window.unboundedPreceding, Window.currentRow) ``` ## How was this patch tested? - Updated DataFrameWindowSuite (for Scala/Java) - Updated test_window_functions_cumulative_sum (for Python) - Renamed DataFrameWindowSuite DataFrameWindowFunctionsSuite to better reflect its purpose Author: Reynold Xin <rxin@databricks.com> Closes #15438 from rxin/SPARK-17845.
Showing
- python/pyspark/sql/tests.py 24 additions, 1 deletionpython/pyspark/sql/tests.py
- python/pyspark/sql/window.py 60 additions, 29 deletionspython/pyspark/sql/window.py
- sql/core/src/main/scala/org/apache/spark/sql/expressions/Window.scala 53 additions, 9 deletions.../main/scala/org/apache/spark/sql/expressions/Window.scala
- sql/core/src/main/scala/org/apache/spark/sql/expressions/WindowSpec.scala 16 additions, 8 deletions...n/scala/org/apache/spark/sql/expressions/WindowSpec.scala
- sql/core/src/test/scala/org/apache/spark/sql/DataFrameWindowFunctionsSuite.scala 7 additions, 4 deletions.../org/apache/spark/sql/DataFrameWindowFunctionsSuite.scala
Loading
Please register or sign in to comment