import logging

import apache_beam as beam


logger = logging.getLogger(__name__)


@beam.ptransform_fn
def count_words(pipeline: beam.Pipeline):
    logger.info("Count words")
    return (pipeline
        | 'Create' >> beam.Create(['a', 'b', 'c', 'd', 'a', 'b', 'c', 'd'])
        | 'PairWithOne' >> beam.Map(lambda x: (x, 1))
        | 'GroupAndSum' >> beam.CombinePerKey(sum)
    )
