github.com/apache/beam/sdks/v2@v2.48.2/python/apache_beam/examples/cookbook/bigquery_side_input_test.py (about)

     1  #
     2  # Licensed to the Apache Software Foundation (ASF) under one or more
     3  # contributor license agreements.  See the NOTICE file distributed with
     4  # this work for additional information regarding copyright ownership.
     5  # The ASF licenses this file to You under the Apache License, Version 2.0
     6  # (the "License"); you may not use this file except in compliance with
     7  # the License.  You may obtain a copy of the License at
     8  #
     9  #    http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  #
    17  
    18  """Test for the BigQuery side input example."""
    19  
    20  # pytype: skip-file
    21  
    22  import logging
    23  import unittest
    24  
    25  import apache_beam as beam
    26  from apache_beam.examples.cookbook import bigquery_side_input
    27  from apache_beam.testing.test_pipeline import TestPipeline
    28  from apache_beam.testing.util import assert_that
    29  from apache_beam.testing.util import equal_to
    30  
    31  
    32  class BigQuerySideInputTest(unittest.TestCase):
    33    def test_create_groups(self):
    34      with TestPipeline() as p:
    35  
    36        group_ids_pcoll = p | 'CreateGroupIds' >> beam.Create(['A', 'B', 'C'])
    37        corpus_pcoll = p | 'CreateCorpus' >> beam.Create([{
    38            'f': 'corpus1'
    39        }, {
    40            'f': 'corpus2'
    41        }])
    42        words_pcoll = p | 'CreateWords' >> beam.Create([{
    43            'f': 'word1'
    44        }, {
    45            'f': 'word2'
    46        }])
    47        ignore_corpus_pcoll = p | 'CreateIgnoreCorpus' >> beam.Create(['corpus1'])
    48        ignore_word_pcoll = p | 'CreateIgnoreWord' >> beam.Create(['word1'])
    49  
    50        groups = bigquery_side_input.create_groups(
    51            group_ids_pcoll,
    52            corpus_pcoll,
    53            words_pcoll,
    54            ignore_corpus_pcoll,
    55            ignore_word_pcoll)
    56  
    57        assert_that(
    58            groups,
    59            equal_to([('A', 'corpus2', 'word2'), ('B', 'corpus2', 'word2'),
    60                      ('C', 'corpus2', 'word2')]))
    61  
    62  
    63  if __name__ == '__main__':
    64    logging.getLogger().setLevel(logging.INFO)
    65    unittest.main()