Class TimeWindowFunction
- java.lang.Object
-
- org.datavec.api.transform.sequence.window.TimeWindowFunction
-
- All Implemented Interfaces:
Serializable
,WindowFunction
public class TimeWindowFunction extends Object implements WindowFunction
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TimeWindowFunction.Builder
-
Constructor Summary
Constructors Constructor Description TimeWindowFunction(String timeColumn, long windowSize, TimeUnit windowSizeUnit)
Constructor with zero offsetTimeWindowFunction(String timeColumn, long windowSize, TimeUnit windowSizeUnit, boolean addWindowStartTimeColumn, boolean addWindowEndTimeColumn)
Constructor with zero offset, and supports adding columns containing the start and/or end times of the windowTimeWindowFunction(String timeColumn, long windowSize, TimeUnit windowSizeUnit, long offset, TimeUnit offsetUnit)
Constructor with optional offsetTimeWindowFunction(String timeColumn, long windowSize, TimeUnit windowSizeUnit, long offset, TimeUnit offsetUnit, boolean addWindowStartTimeColumn, boolean addWindowEndTimeColumn, boolean excludeEmptyWindows)
Constructor with optional offset
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description List<List<List<Writable>>>
applyToSequence(List<List<Writable>> sequence)
Apply the windowing function to the given sequenceSchema
getInputSchema()
long
getWindowEndTimeForTime(long time)
Calculates the end time of the window for which the specified time belongs, in unix epoch (millisecond) format.long
getWindowStartTimeForTime(long time)
Calculates the start time of the window for which the specified time belongs, in unix epoch (millisecond) format
For example, if the window size is 1 hour with offset 0, then a time 10:17 would return 10:00, as the 1 hour window is for 10:00:00.000 to 10:59:59.999 inclusive, or 10:00:00.000 (inclusive) to 11:00:00.000 (exclusive)void
setInputSchema(Schema schema)
String
toString()
Schema
transform(Schema inputSchema)
Get the output schema, given the input schema.
-
-
-
Constructor Detail
-
TimeWindowFunction
public TimeWindowFunction(String timeColumn, long windowSize, TimeUnit windowSizeUnit)
Constructor with zero offset- Parameters:
timeColumn
- Name of the column that contains the time values (must be a time column)windowSize
- Numerical quantity for the size of the time window (used in conjunction with windowSizeUnit)windowSizeUnit
- Unit of the time window
-
TimeWindowFunction
public TimeWindowFunction(String timeColumn, long windowSize, TimeUnit windowSizeUnit, boolean addWindowStartTimeColumn, boolean addWindowEndTimeColumn)
Constructor with zero offset, and supports adding columns containing the start and/or end times of the window- Parameters:
timeColumn
- Name of the column that contains the time values (must be a time column)windowSize
- Numerical quantity for the size of the time window (used in conjunction with windowSizeUnit)windowSizeUnit
- Unit of the time windowaddWindowStartTimeColumn
- If true: add a time column (name: "windowStartTime") that contains the start time of the windowaddWindowStartTimeColumn
- If true: add a time column (name: "windowEndTime") that contains the end time of the window
-
TimeWindowFunction
public TimeWindowFunction(String timeColumn, long windowSize, TimeUnit windowSizeUnit, long offset, TimeUnit offsetUnit)
Constructor with optional offset- Parameters:
timeColumn
- Name of the column that contains the time values (must be a time column)windowSize
- Numerical quantity for the size of the time window (used in conjunction with windowSizeUnit)windowSizeUnit
- Unit of the time windowoffset
- Optional offset amount, to shift start/end of the time window forward or backoffsetUnit
- Optional offset unit for the offset amount.
-
TimeWindowFunction
public TimeWindowFunction(String timeColumn, long windowSize, TimeUnit windowSizeUnit, long offset, TimeUnit offsetUnit, boolean addWindowStartTimeColumn, boolean addWindowEndTimeColumn, boolean excludeEmptyWindows)
Constructor with optional offset- Parameters:
timeColumn
- Name of the column that contains the time values (must be a time column)windowSize
- Numerical quantity for the size of the time window (used in conjunction with windowSizeUnit)windowSizeUnit
- Unit of the time windowoffset
- Optional offset amount, to shift start/end of the time window forward or backoffsetUnit
- Optional offset unit for the offset amount.addWindowStartTimeColumn
- If true: add a column (at the end) with the window start timeaddWindowEndTimeColumn
- If true: add a column (at the end) with the window end timeexcludeEmptyWindows
- If true: exclude any windows that don't have any values in them
-
-
Method Detail
-
setInputSchema
public void setInputSchema(Schema schema)
- Specified by:
setInputSchema
in interfaceWindowFunction
-
getInputSchema
public Schema getInputSchema()
- Specified by:
getInputSchema
in interfaceWindowFunction
- Returns:
-
transform
public Schema transform(Schema inputSchema)
Description copied from interface:WindowFunction
Get the output schema, given the input schema. Typically the output schema is the same as the input schema, but not necessarily (for example, if the window function adds columns for the window start/end times)- Specified by:
transform
in interfaceWindowFunction
- Parameters:
inputSchema
- Schema of the input data- Returns:
- Schema of the output windows
-
applyToSequence
public List<List<List<Writable>>> applyToSequence(List<List<Writable>> sequence)
Description copied from interface:WindowFunction
Apply the windowing function to the given sequence- Specified by:
applyToSequence
in interfaceWindowFunction
- Parameters:
sequence
- the input sequence- Returns:
- the sequence with the window function applied
-
getWindowStartTimeForTime
public long getWindowStartTimeForTime(long time)
Calculates the start time of the window for which the specified time belongs, in unix epoch (millisecond) format
For example, if the window size is 1 hour with offset 0, then a time 10:17 would return 10:00, as the 1 hour window is for 10:00:00.000 to 10:59:59.999 inclusive, or 10:00:00.000 (inclusive) to 11:00:00.000 (exclusive)- Parameters:
time
- Time at which to determine the window start time (milliseconds epoch format)
-
getWindowEndTimeForTime
public long getWindowEndTimeForTime(long time)
Calculates the end time of the window for which the specified time belongs, in unix epoch (millisecond) format. Note: this value is not included in the interval. Put another way, it is the start time of the next interval: i.e., is equivalent togetWindowStartTimeForTime(long)
+ interval (in milliseconds).
To get the last inclusive time for the interval, subtract 1L (1 millisecond) from the value returned by this method.
For example, if the window size is 1 hour with offset 0, then a time 10:17 would return 11:00, as the 1 hour window is for 10:00:00.000 (inclusive) to 11:00:00.000 (exclusive)- Parameters:
time
- Time at which to determine the window start time- Returns:
-
-