com.google.cloud.dataflow.sdk.transforms.windowing

## Class OutputTimeFn.Defaults<W extends BoundedWindow>

- java.lang.Object
- - com.google.cloud.dataflow.sdk.transforms.windowing.OutputTimeFn<W>
  - - com.google.cloud.dataflow.sdk.transforms.windowing.OutputTimeFn.Defaults<W>

All Implemented Interfaces:
  Serializable

Enclosing class:
  OutputTimeFn<W extends BoundedWindow>

    public abstract static class OutputTimeFn.Defaults<W extends BoundedWindow>
    extends OutputTimeFn<W>

(Experimental) Default method implementations for `OutputTimeFn` where the output time depends on the input element timestamps and possibly the window.

To complete an implementation, override `OutputTimeFn.assignOutputTime(org.joda.time.Instant, W)`, at a minimum.

By default, `combine(org.joda.time.Instant, org.joda.time.Instant)` and `merge(W, java.lang.Iterable<? extends org.joda.time.Instant>)` return the earliest timestamp of their inputs.

See Also:
  Serialized Form

### Nested Class Summary

### Nested classes/interfaces inherited from class com.google.cloud.dataflow.sdk.transforms.windowing.OutputTimeFn

`OutputTimeFn.Defaults<W extends BoundedWindow>, OutputTimeFn.DependsOnlyOnWindow<W extends BoundedWindow>`

### Constructor Summary

Constructors
`protected` `Defaults()`

### Method Summary

All Methods Instance Methods Concrete Methods
`Instant` `combine(Instant outputTimestamp, Instant otherOutputTimestamp)` Combines the given output times, which must be from the same window, into an output time for a computed value.
`boolean` `dependsOnlyOnEarliestInputTimestamp()` Returns `true` if the result of combination of many output timestamps actually depends only on the earliest.
`boolean` `dependsOnlyOnWindow()` Returns `true` if the result does not depend on what outputs were combined but only the window they are in.
`boolean` `equals(Object other)`
`int` `hashCode()`
`Instant` `merge(W resultWindow, Iterable<? extends Instant> mergingTimestamps)` Merges the given output times, presumed to be combined output times for windows that are merging, into an output time for the `resultWindow`.

### Methods inherited from class com.google.cloud.dataflow.sdk.transforms.windowing.OutputTimeFn

`assignOutputTime`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### Defaults

    protected Defaults()

### Method Detail

#### combine

    public Instant combine(Instant outputTimestamp,
                           Instant otherOutputTimestamp)

Combines the given output times, which must be from the same window, into an output time for a computed value.

- `combine` must be commutative: `combine(a, b).equals(combine(b, a))`.
- `combine` must be associative: `combine(a, combine(b, c)).equals(combine(combine(a, b), c))`.

Specified by:
  `combine` in class `OutputTimeFn<W extends BoundedWindow>`
Returns:
  the earlier of the two timestamps.

#### merge

    public Instant merge(W resultWindow,
                         Iterable<? extends Instant> mergingTimestamps)

Merges the given output times, presumed to be combined output times for windows that are merging, into an output time for the `resultWindow`.

When windows `w1` and `w2` merge to become a new window `w1plus2`, then `OutputTimeFn.merge(W, java.lang.Iterable<? extends org.joda.time.Instant>)` must be implemented such that the output time is the same as if all timestamps were assigned in `w1plus2`. Formally:

`fn.merge(w, fn.assignOutputTime(t1, w1), fn.assignOutputTime(t2, w2))`

must be equal to

`fn.combine(fn.assignOutputTime(t1, w1plus2), fn.assignOutputTime(t2, w1plus2))`

If the assigned time depends only on the window, the correct implementation of `merge()` necessarily returns the result of `assignOutputTime(t1, w1plus2)` (which equals `assignOutputTime(t2, w1plus2)`. Defaults for this case are provided by `OutputTimeFn.DependsOnlyOnWindow`.

For many other `OutputTimeFn` implementations, such as taking the earliest or latest timestamp, this will be the same as `combine()`. Defaults for this case are provided by `OutputTimeFn.Defaults`.

Specified by:
  `merge` in class `OutputTimeFn<W extends BoundedWindow>`
Returns:
  the result of `combine(outputTimstamp, otherOutputTimestamp)`, by default.

#### dependsOnlyOnWindow

    public final boolean dependsOnlyOnWindow()

Returns `true` if the result does not depend on what outputs were combined but only the window they are in. The canonical example is if all timestamps are sure to be the end of the window.

This may allow optimizations, since it is typically very efficient to retrieve the window and combining output timestamps is not necessary.

If the assigned output time for an implementation depends only on the window, consider extending `OutputTimeFn.DependsOnlyOnWindow`, which returns `true` here and also provides a framework for easily implementing a correct `OutputTimeFn.merge(W, java.lang.Iterable<? extends org.joda.time.Instant>)`, `OutputTimeFn.combine(org.joda.time.Instant, org.joda.time.Instant)` and `OutputTimeFn.assignOutputTime(org.joda.time.Instant, W)`.

Specified by:
  `dependsOnlyOnWindow` in class `OutputTimeFn<W extends BoundedWindow>`
Returns:
  `false`. An `OutputTimeFn` that depends only on the window should extend `OutputTimeFn.DependsOnlyOnWindow`.

#### dependsOnlyOnEarliestInputTimestamp

    public boolean dependsOnlyOnEarliestInputTimestamp()

Returns `true` if the result of combination of many output timestamps actually depends only on the earliest.

This may allow optimizations when it is very efficient to retrieve the earliest timestamp to be combined.

Specified by:
  `dependsOnlyOnEarliestInputTimestamp` in class `OutputTimeFn<W extends BoundedWindow>`
Returns:
  `true` by default.

#### equals

    public boolean equals(Object other)

Overrides:
  `equals` in class `Object`
Returns:
  `true` if the two `OutputTimeFn` instances have the same class, by default.

#### hashCode

    public int hashCode()

Overrides:
  `hashCode` in class `Object`