Class TimeWindowFunction

    • 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 window
        addWindowStartTimeColumn - If true: add a time column (name: "windowStartTime") that contains the start time of the window
        addWindowStartTimeColumn - 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 window
        offset - Optional offset amount, to shift start/end of the time window forward or back
        offsetUnit - 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 window
        offset - Optional offset amount, to shift start/end of the time window forward or back
        offsetUnit - Optional offset unit for the offset amount.
        addWindowStartTimeColumn - If true: add a column (at the end) with the window start time
        addWindowEndTimeColumn - If true: add a column (at the end) with the window end time
        excludeEmptyWindows - If true: exclude any windows that don't have any values in them
    • Method Detail

      • 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 interface WindowFunction
        Parameters:
        inputSchema - Schema of the input data
        Returns:
        Schema of the output windows
      • 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 to getWindowStartTimeForTime(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: