Details
-
Umbrella
-
Status: Resolved
-
Major
-
Resolution: Incomplete
-
2.3.2, 2.4.0
-
None
Description
As I was reviewing the Spark API changes for 2.4, I found that through organic, ad-hoc evolution the current API for window functions in Scala is pretty bad.
To illustrate the problem, we have two rangeBetween functions in Window class:
class Window { def unboundedPreceding: Long ... def rangeBetween(start: Long, end: Long): WindowSpec def rangeBetween(start: Column, end: Column): WindowSpec }
The Column version of rangeBetween was added in Spark 2.3 because the previous version (Long) could only support integral values and not time intervals. Now in order to support specifying unboundedPreceding in the rangeBetween(Column, Column) API, we added an unboundedPreceding that returns a Column in functions.scala.
There are a few issues I have with the API:
1. To the end user, this can be just super confusing. Why are there two unboundedPreceding functions, in different classes, that are named the same but return different types?
2. Using Column as the parameter signature implies this can be an actual Column, but in practice rangeBetween can only accept literal values.
3. We added the new APIs to support intervals, but they don't actually work, because in the implementation we try to validate the start is less than the end, but calendar interval types are not comparable, and as a result we throw a type mismatch exception at runtime: scala.MatchError: CalendarIntervalType (of class org.apache.spark.sql.types.CalendarIntervalType$)
4. In order to make interval work, users need to create an interval using CalendarInterval, which is an internal class that has no documentation and no stable API.
Attachments
Issue Links
- relates to
-
SPARK-9221 Support IntervalType in Range Frame
- Resolved
-
SPARK-21608 Window rangeBetween() API should allow literal boundary
- Resolved
1.
|
Fix MatchError for calendar interval type in rangeBetween | Resolved | Unassigned | |
2.
|
Deprecate APIs introduced in SPARK-21608 | Resolved | Reynold Xin | |
3.
|
Remove rangeBetween APIs introduced in SPARK-21608 | Resolved | Reynold Xin | |
4.
|
Redesign rangeBetween API | Resolved | Reynold Xin | |
5.
|
Implement Python API once we have a new API | Open | Unassigned |