WithKeys

Javadoc Javadoc


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:

Examples

Example

PCollection<String> words = Create.of("Hello", "World", "Beam", "is", "fun");
PCollection<KV<Integer, String>> lengthAndWord =
  words.apply(WithKeys.of(new SerialiazableFunction<String, Integer>() {
    @Override
    public Integer apply(String s) {
      return s.length();
    }
  });