-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-14353] Dataset Time Window window API for R
#12141
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2131,6 +2131,69 @@ setMethod("from_unixtime", signature(x = "Column"), | |
| column(jc) | ||
| }) | ||
|
|
||
| #' window | ||
| #' | ||
| #' Bucketize rows into one or more time windows given a timestamp specifying column. Window | ||
| #' starts are inclusive but the window ends are exclusive, e.g. 12:05 will be in the window | ||
| #' [12:05,12:10) but not in [12:00,12:05). Windows can support microsecond precision. Windows in | ||
| #' the order of months are not supported. | ||
| #' | ||
| #' The time column must be of TimestampType. | ||
| #' | ||
| #' Durations are provided as strings, e.g. '1 second', '1 day 12 hours', '2 minutes'. Valid | ||
| #' interval strings are 'week', 'day', 'hour', 'minute', 'second', 'millisecond', 'microsecond'. | ||
| #' If the `slideDuration` is not provided, the windows will be tumbling windows. | ||
| #' | ||
| #' The startTime is the offset with respect to 1970-01-01 00:00:00 UTC with which to start | ||
| #' window intervals. For example, in order to have hourly tumbling windows that start 15 minutes | ||
| #' past the hour, e.g. 12:15-13:15, 13:15-14:15... provide `startTime` as `15 minutes`. | ||
| #' | ||
| #' The output column will be a struct called 'window' by default with the nested columns 'start' | ||
| #' and 'end'. | ||
| #' | ||
| #' @family datetime_funcs | ||
| #' @rdname window | ||
| #' @name window | ||
| #' @export | ||
| #' @examples | ||
| #'\dontrun{ | ||
| #' # One minute windows every 15 seconds 10 seconds after the minute, e.g. 09:00:10-09:01:10, | ||
| #' # 09:00:25-09:01:25, 09:00:40-09:01:40, ... | ||
| #' window(df$time, "1 minute", "15 seconds", "10 seconds") | ||
| #' | ||
| #' # One minute tumbling windows 15 seconds after the minute, e.g. 09:00:15-09:01:15, | ||
| #' # 09:01:15-09:02:15... | ||
| #' window(df$time, "1 minute", startTime = "15 seconds") | ||
| #' | ||
| #' # Thirty second windows every 10 seconds, e.g. 09:00:00-09:00:30, 09:00:10-09:00:40, ... | ||
| #' window(df$time, "30 seconds", "10 seconds") | ||
| #'} | ||
| setMethod("window", signature(x = "Column"), | ||
| function(x, windowDuration, slideDuration = NULL, startTime = NULL) { | ||
| stopifnot(is.character(windowDuration)) | ||
| if (!is.null(slideDuration) && !is.null(startTime)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check we check the type of windowDuration, slideDuration and startTime? |
||
| stopifnot(is.character(slideDuration) && is.character(startTime)) | ||
| jc <- callJStatic("org.apache.spark.sql.functions", | ||
| "window", | ||
| x@jc, windowDuration, slideDuration, startTime) | ||
| } else if (!is.null(slideDuration)) { | ||
| stopifnot(is.character(slideDuration)) | ||
| jc <- callJStatic("org.apache.spark.sql.functions", | ||
| "window", | ||
| x@jc, windowDuration, slideDuration) | ||
| } else if (!is.null(startTime)) { | ||
| stopifnot(is.character(startTime)) | ||
| jc <- callJStatic("org.apache.spark.sql.functions", | ||
| "window", | ||
| x@jc, windowDuration, windowDuration, startTime) | ||
| } else { | ||
| jc <- callJStatic("org.apache.spark.sql.functions", | ||
| "window", | ||
| x@jc, windowDuration) | ||
| } | ||
| column(jc) | ||
| }) | ||
|
|
||
| #' locate | ||
| #' | ||
| #' Locate the position of the first occurrence of substr. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be added to https://github.com/apache/spark/blob/master/R/pkg/R/generics.R?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also need to check window from the stats package can still be called?
https://stat.ethz.ch/R-manual/R-devel/library/stats/html/window.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
windowcan be called usingstats::window