Keys
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:
- KvSwap swaps the key and value of each element.
- Values for extracting the value of each element.