Keys

Pydoc Pydoc


Takes a collection of key-value pairs and returns the key of each element.

Example

In the following example, we create a pipeline with a PCollection of key-value pairs. Then, we apply Keys to extract the keys and discard the values.

import apache_beam as beam

with beam.Pipeline() as pipeline:
  icons = (
      pipeline
      | 'Garden plants' >> beam.Create([
          ('🍓', 'Strawberry'),
          ('🥕', 'Carrot'),
          ('🍆', 'Eggplant'),
          ('🍅', 'Tomato'),
          ('🥔', 'Potato'),
      ])
      | 'Keys' >> beam.Keys()
      | beam.Map(print)
  )

Output PCollection after Keys:

icons = [
    '🍓',
    '🥕',
    '🍆',
    '🍅',
    '🥔',
]
View on GitHub View on GitHub


Pydoc Pydoc