import logging

import apache_beam as beam


logger = logging.getLogger(__name__)


def count_words(p, target_method):
    logger.debug("Count words with target method %s", target_method)
    return (p | beam.Create(['a', 'b', 'c', 'd', 'a', 'b', 'c', 'd'])
            | 'PairWithOne' >> beam.Map(lambda x: (x, 1))
            | 'GroupAndSum' >> beam.CombinePerKey(sum)
            | 'save' >> target_method)
