def run(self, test_runner_api=True, runner=None, options=None, interactive=None): """Runs the pipeline. Returns whatever our runner returns after running. If another runner instance and options are provided, that runner will execute the pipeline with the given options. If either of them is not set, a ValueError is raised. The usage is similar to directly invoking `runner.run_pipeline(pipeline, options)`. Additionally, an interactive field can be set to override the pipeline's self.interactive field to mark current pipeline as being initiated from an interactive environment. """ from apache_beam.runners.interactive import interactive_runner if interactive: self.interactive = interactive elif isinstance(self.runner, interactive_runner.InteractiveRunner): self.interactive = True else: self.interactive = False runner_in_use = self.runner options_in_use = self._options if runner and options: runner_in_use = runner options_in_use = options elif not runner and options: raise ValueError( 'Parameter runner is not given when parameter options ' 'is given.') elif not options and runner: raise ValueError( 'Parameter options is not given when parameter runner ' 'is given.') # When possible, invoke a round trip through the runner API. if test_runner_api and self._verify_runner_api_compatible(): return Pipeline.from_runner_api( self.to_runner_api(use_fake_coders=True), runner_in_use, options_in_use).run(test_runner_api=False, interactive=self.interactive) if options_in_use.view_as(TypeOptions).runtime_type_check: from apache_beam.typehints import typecheck self.visit(typecheck.TypeCheckVisitor()) if options_in_use.view_as(SetupOptions).save_main_session: # If this option is chosen, verify we can pickle the main session early. tmpdir = tempfile.mkdtemp() try: pickler.dump_session( os.path.join(tmpdir, 'main_session.pickle')) finally: shutil.rmtree(tmpdir) return runner_in_use.run_pipeline(self, options_in_use)
def run(self, test_runner_api=True): """Runs the pipeline. Returns whatever our runner returns after running.""" # When possible, invoke a round trip through the runner API. if test_runner_api and self._verify_runner_api_compatible(): return Pipeline.from_runner_api( self.to_runner_api(), self.runner, self._options).run(False) if self._options.view_as(TypeOptions).runtime_type_check: from apache_beam.typehints import typecheck self.visit(typecheck.TypeCheckVisitor()) if self._options.view_as(SetupOptions).save_main_session: # If this option is chosen, verify we can pickle the main session early. tmpdir = tempfile.mkdtemp() try: pickler.dump_session(os.path.join(tmpdir, 'main_session.pickle')) finally: shutil.rmtree(tmpdir) return self.runner.run_pipeline(self)