layout: section title: “Latest” permalink: /documentation/transforms/java/aggregation/latest/ section_menu: section-menu/documentation.html

Latest

  • Latest.globally() takes a collection of values and produces the collection containing the single value with the latest implicit timestamp.
  • Latest.perKey() takes a collection of key value pairs, and returns the latest value for each key, according to the implicit timestamp.

For elements with the same timestamp, the output element is arbitrarily selected.

Examples

Example: compute the latest value for each session

 PCollection input = ...;
 PCollection sessioned = input
    .apply(Window.into(Sessions.withGapDuration(Duration.standardMinutes(5)));
 PCollection latestValues = sessioned.apply(Latest.globally());

Related transforms

  • [Reify]({{ site.baseurl }}/documentation/transforms/java/elementwise/reify) converts between explicit and implicit form of various Beam values
  • [WithTimestamps]({{ site.baseurl }}/documentation/transforms/java/elementwise/withtimestamps) assigns timestamps to all the elements of a collection