WithKeys

Takes a PCollection<V> and produces a PCollection<KV<K, V>> by associating each input element with a key.

There are two versions of WithKeys, depending on how the key should be determined:

  • WithKeys.of(SerializableFunction<V, K> fn) takes a function to compute the key from each value.
  • WithKeys.of(K key) associates each value with the specified key.

Examples

  • Keys for extracting the key of each component.
  • Values for extracting the value of each element.
  • KvSwap swaps key-value pair values.

Last updated on 2026/02/21

Have you found everything you were looking for?

Was it all useful and clear? Is there anything that you would like to change? Let us know!