def test_side_input_visitor(self):
    p = TestPipeline()
    pc = p | beam.Create([])

    transform = beam.Map(
        lambda x,
        y,
        z: (x, y, z),
        beam.pvalue.AsSingleton(pc),
        beam.pvalue.AsMultiMap(pc))
    applied_transform = AppliedPTransform(None, transform, "label", [pc])
    DataflowRunner.side_input_visitor().visit_transform(applied_transform)
    self.assertEqual(2, len(applied_transform.side_inputs))
    for side_input in applied_transform.side_inputs:
      self.assertEqual(
          common_urns.side_inputs.MULTIMAP.urn,
          side_input._side_input_data().access_pattern)
Ejemplo n.º 2
0
    def test_group_by_key_input_visitor_with_valid_inputs(self):
        p = TestPipeline()
        pcoll1 = PCollection(p)
        pcoll2 = PCollection(p)
        pcoll3 = PCollection(p)

        pcoll1.element_type = None
        pcoll2.element_type = typehints.Any
        pcoll3.element_type = typehints.KV[typehints.Any, typehints.Any]
        for pcoll in [pcoll1, pcoll2, pcoll3]:
            applied = AppliedPTransform(None, beam.GroupByKey(), "label",
                                        [pcoll])
            applied.outputs[None] = PCollection(None)
            DataflowRunner.group_by_key_input_visitor().visit_transform(
                applied)
            self.assertEqual(pcoll.element_type, typehints.KV[typehints.Any,
                                                              typehints.Any])