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

Count

  • Count.globally() counts the number of elements in the entire PCollection. The result is a collection with a single element.
  • Count.perKey() counts how many elements are associated with each key. It ignores the values. The resulting collection has one output for every key in the input collection.
  • Count.perElement() counts how many times each element appears in the input collection. The output collection is a key-value pair, containing each unique element and the number of times it appeared in the original collection.

Examples

See BEAM-7703 for updates.

Related transforms

  • [ApproximateUnique]({{ site.baseurl }}/documentation/transforms/java/aggregation/approximateunique) estimates the number of distinct elements or distinct values in key-value pairs
  • [Sum]({{ site.baseurl }}/documentation/transforms/java/aggregation/sum) computes the sum of elements in a collection