blob: 767af336e9f28ec31c861c93d8b5cd9a9f0f4043 [file] [log] [blame]
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>apache_beam.runners.interactive.pipeline_instrument module &mdash; Apache Beam documentation</title>
<script type="text/javascript" src="_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/language_data.js"></script>
<script async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="apache_beam.runners.interactive.recording_manager module" href="apache_beam.runners.interactive.recording_manager.html" />
<link rel="prev" title="apache_beam.runners.interactive.pipeline_fragment module" href="apache_beam.runners.interactive.pipeline_fragment.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="index.html" class="icon icon-home"> Apache Beam
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="apache_beam.coders.html">apache_beam.coders package</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.dataframe.html">apache_beam.dataframe package</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.io.html">apache_beam.io package</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.metrics.html">apache_beam.metrics package</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.ml.html">apache_beam.ml package</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.options.html">apache_beam.options package</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.portability.html">apache_beam.portability package</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="apache_beam.runners.html">apache_beam.runners package</a><ul class="current">
<li class="toctree-l2 current"><a class="reference internal" href="apache_beam.runners.html#subpackages">Subpackages</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="apache_beam.runners.dataflow.html">apache_beam.runners.dataflow package</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.runners.direct.html">apache_beam.runners.direct package</a></li>
<li class="toctree-l3 current"><a class="reference internal" href="apache_beam.runners.interactive.html">apache_beam.runners.interactive package</a><ul class="current">
<li class="toctree-l4"><a class="reference internal" href="apache_beam.runners.interactive.html#subpackages">Subpackages</a></li>
<li class="toctree-l4 current"><a class="reference internal" href="apache_beam.runners.interactive.html#submodules">Submodules</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.runners.job.html">apache_beam.runners.job package</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="apache_beam.runners.html#submodules">Submodules</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.transforms.html">apache_beam.transforms package</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.typehints.html">apache_beam.typehints package</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.utils.html">apache_beam.utils package</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.error.html">apache_beam.error module</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.pipeline.html">apache_beam.pipeline module</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.pvalue.html">apache_beam.pvalue module</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">Apache Beam</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html">Docs</a> &raquo;</li>
<li><a href="apache_beam.runners.html">apache_beam.runners package</a> &raquo;</li>
<li><a href="apache_beam.runners.interactive.html">apache_beam.runners.interactive package</a> &raquo;</li>
<li>apache_beam.runners.interactive.pipeline_instrument module</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/apache_beam.runners.interactive.pipeline_instrument.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="module-apache_beam.runners.interactive.pipeline_instrument">
<span id="apache-beam-runners-interactive-pipeline-instrument-module"></span><h1>apache_beam.runners.interactive.pipeline_instrument module<a class="headerlink" href="#module-apache_beam.runners.interactive.pipeline_instrument" title="Permalink to this headline"></a></h1>
<p>Module to instrument interactivity to the given pipeline.</p>
<p>For internal use only; no backwards-compatibility guarantees.
This module accesses current interactive environment and analyzes given pipeline
to transform original pipeline into a one-shot pipeline with interactivity.</p>
<dl class="class">
<dt id="apache_beam.runners.interactive.pipeline_instrument.PipelineInstrument">
<em class="property">class </em><code class="descclassname">apache_beam.runners.interactive.pipeline_instrument.</code><code class="descname">PipelineInstrument</code><span class="sig-paren">(</span><em>pipeline</em>, <em>options=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/runners/interactive/pipeline_instrument.html#PipelineInstrument"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.runners.interactive.pipeline_instrument.PipelineInstrument" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference external" href="https://docs.python.org/3/library/functions.html#object" title="(in Python v3.10)"><code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></a></p>
<p>A pipeline instrument for pipeline to be executed by interactive runner.</p>
<p>This module should never depend on underlying runner that interactive runner
delegates. It instruments the original instance of pipeline directly by
appending or replacing transforms with help of cache. It provides
interfaces to recover states of original pipeline. It’s the interactive
runner’s responsibility to coordinate supported underlying runners to run
the pipeline instrumented and recover the original pipeline states if needed.</p>
<dl class="method">
<dt id="apache_beam.runners.interactive.pipeline_instrument.PipelineInstrument.instrumented_pipeline_proto">
<code class="descname">instrumented_pipeline_proto</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/runners/interactive/pipeline_instrument.html#PipelineInstrument.instrumented_pipeline_proto"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.runners.interactive.pipeline_instrument.PipelineInstrument.instrumented_pipeline_proto" title="Permalink to this definition"></a></dt>
<dd><p>Always returns a new instance of portable instrumented proto.</p>
</dd></dl>
<dl class="method">
<dt id="apache_beam.runners.interactive.pipeline_instrument.PipelineInstrument.prune_subgraph_for">
<code class="descname">prune_subgraph_for</code><span class="sig-paren">(</span><em>pipeline</em>, <em>required_transform_ids</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/runners/interactive/pipeline_instrument.html#PipelineInstrument.prune_subgraph_for"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.runners.interactive.pipeline_instrument.PipelineInstrument.prune_subgraph_for" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="method">
<dt id="apache_beam.runners.interactive.pipeline_instrument.PipelineInstrument.background_caching_pipeline_proto">
<code class="descname">background_caching_pipeline_proto</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/runners/interactive/pipeline_instrument.html#PipelineInstrument.background_caching_pipeline_proto"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.runners.interactive.pipeline_instrument.PipelineInstrument.background_caching_pipeline_proto" title="Permalink to this definition"></a></dt>
<dd><p>Returns the background caching pipeline.</p>
<p>This method creates a background caching pipeline by: adding writes to cache
from each unbounded source (done in the instrument method), and cutting out
all components (transform, PCollections, coders, windowing strategies) that
are not the unbounded sources or writes to cache (or subtransforms thereof).</p>
</dd></dl>
<dl class="attribute">
<dt id="apache_beam.runners.interactive.pipeline_instrument.PipelineInstrument.cacheables">
<code class="descname">cacheables</code><a class="headerlink" href="#apache_beam.runners.interactive.pipeline_instrument.PipelineInstrument.cacheables" title="Permalink to this definition"></a></dt>
<dd><p>Returns the Cacheables by PCollection ids.</p>
<p>If you’re already working with user defined pipelines and PCollections,
do not build a PipelineInstrument just to get the cacheables. Instead,
use apache_beam.runners.interactive.utils.cacheables.</p>
</dd></dl>
<dl class="attribute">
<dt id="apache_beam.runners.interactive.pipeline_instrument.PipelineInstrument.has_unbounded_sources">
<code class="descname">has_unbounded_sources</code><a class="headerlink" href="#apache_beam.runners.interactive.pipeline_instrument.PipelineInstrument.has_unbounded_sources" title="Permalink to this definition"></a></dt>
<dd><p>Returns whether the pipeline has any recordable sources.</p>
</dd></dl>
<dl class="attribute">
<dt id="apache_beam.runners.interactive.pipeline_instrument.PipelineInstrument.original_pipeline_proto">
<code class="descname">original_pipeline_proto</code><a class="headerlink" href="#apache_beam.runners.interactive.pipeline_instrument.PipelineInstrument.original_pipeline_proto" title="Permalink to this definition"></a></dt>
<dd><p>Returns a snapshot of the pipeline proto before instrumentation.</p>
</dd></dl>
<dl class="attribute">
<dt id="apache_beam.runners.interactive.pipeline_instrument.PipelineInstrument.user_pipeline">
<code class="descname">user_pipeline</code><a class="headerlink" href="#apache_beam.runners.interactive.pipeline_instrument.PipelineInstrument.user_pipeline" title="Permalink to this definition"></a></dt>
<dd><p>Returns a reference to the pipeline instance defined by the user. If a
pipeline has no cacheable PCollection and the user pipeline cannot be
found, return None indicating there is nothing to be cached in the user
pipeline.</p>
<p>The pipeline given for instrumenting and mutated in this class is not
necessarily the pipeline instance defined by the user. From the watched
scopes, this class figures out what the user pipeline instance is.
This metadata can be used for tracking pipeline results.</p>
</dd></dl>
<dl class="attribute">
<dt id="apache_beam.runners.interactive.pipeline_instrument.PipelineInstrument.runner_pcoll_to_user_pcoll">
<code class="descname">runner_pcoll_to_user_pcoll</code><a class="headerlink" href="#apache_beam.runners.interactive.pipeline_instrument.PipelineInstrument.runner_pcoll_to_user_pcoll" title="Permalink to this definition"></a></dt>
<dd><p>Returns cacheable PCollections correlated from instances in the runner
pipeline to instances in the user pipeline.</p>
</dd></dl>
<dl class="method">
<dt id="apache_beam.runners.interactive.pipeline_instrument.PipelineInstrument.find_cacheables">
<code class="descname">find_cacheables</code><span class="sig-paren">(</span><span class="sig-paren">)</span> &#x2192; Dict[str, apache_beam.runners.interactive.caching.cacheable.Cacheable]<a class="reference internal" href="_modules/apache_beam/runners/interactive/pipeline_instrument.html#PipelineInstrument.find_cacheables"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.runners.interactive.pipeline_instrument.PipelineInstrument.find_cacheables" title="Permalink to this definition"></a></dt>
<dd><p>Finds PCollections that need to be cached for analyzed pipeline.</p>
<p>There might be multiple pipelines defined and watched, this will only find
cacheables belong to the analyzed pipeline.</p>
</dd></dl>
<dl class="method">
<dt id="apache_beam.runners.interactive.pipeline_instrument.PipelineInstrument.instrument">
<code class="descname">instrument</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/runners/interactive/pipeline_instrument.html#PipelineInstrument.instrument"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.runners.interactive.pipeline_instrument.PipelineInstrument.instrument" title="Permalink to this definition"></a></dt>
<dd><p>Instruments original pipeline with cache.</p>
<p>For cacheable output PCollection, if cache for the key doesn’t exist, do
_write_cache(); for cacheable input PCollection, if cache for the key
exists, do _read_cache(). No instrument in any other situation.</p>
<dl class="docutils">
<dt>Modifies:</dt>
<dd>self._pipeline</dd>
</dl>
</dd></dl>
<dl class="method">
<dt id="apache_beam.runners.interactive.pipeline_instrument.PipelineInstrument.preprocess">
<code class="descname">preprocess</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/runners/interactive/pipeline_instrument.html#PipelineInstrument.preprocess"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.runners.interactive.pipeline_instrument.PipelineInstrument.preprocess" title="Permalink to this definition"></a></dt>
<dd><p>Pre-processes the pipeline.</p>
<p>Since the pipeline instance in the class might not be the same instance
defined in the user code, the pre-process will figure out the relationship
of cacheable PCollections between these 2 instances by replacing ‘pcoll’
fields in the cacheable dictionary with ones from the running instance.</p>
</dd></dl>
<dl class="method">
<dt id="apache_beam.runners.interactive.pipeline_instrument.PipelineInstrument.pcoll_id">
<code class="descname">pcoll_id</code><span class="sig-paren">(</span><em>pcoll</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/runners/interactive/pipeline_instrument.html#PipelineInstrument.pcoll_id"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.runners.interactive.pipeline_instrument.PipelineInstrument.pcoll_id" title="Permalink to this definition"></a></dt>
<dd><p>Gets the PCollection id of the given pcoll.</p>
<p>Returns ‘’ if not found.</p>
</dd></dl>
<dl class="method">
<dt id="apache_beam.runners.interactive.pipeline_instrument.PipelineInstrument.cache_key">
<code class="descname">cache_key</code><span class="sig-paren">(</span><em>pcoll</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/runners/interactive/pipeline_instrument.html#PipelineInstrument.cache_key"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.runners.interactive.pipeline_instrument.PipelineInstrument.cache_key" title="Permalink to this definition"></a></dt>
<dd><p>Gets the identifier of a cacheable PCollection in cache.</p>
<p>If the pcoll is not a cacheable, return ‘’.
This is only needed in pipeline instrument when the origin of given pcoll
is unknown (whether it’s from the user pipeline or a runner pipeline). If
a pcoll is from the user pipeline, always use CacheKey.from_pcoll to build
the key.
The key is what the pcoll would use as identifier if it’s materialized in
cache. It doesn’t mean that there would definitely be such cache already.
Also, the pcoll can come from the original user defined pipeline object or
an equivalent pcoll from a transformed copy of the original pipeline.</p>
</dd></dl>
</dd></dl>
<dl class="function">
<dt id="apache_beam.runners.interactive.pipeline_instrument.build_pipeline_instrument">
<code class="descclassname">apache_beam.runners.interactive.pipeline_instrument.</code><code class="descname">build_pipeline_instrument</code><span class="sig-paren">(</span><em>pipeline</em>, <em>options=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/runners/interactive/pipeline_instrument.html#build_pipeline_instrument"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.runners.interactive.pipeline_instrument.build_pipeline_instrument" title="Permalink to this definition"></a></dt>
<dd><p>Creates PipelineInstrument for a pipeline and its options with cache.</p>
<p>Throughout the process, the returned PipelineInstrument snapshots the given
pipeline and then mutates the pipeline. It’s invoked by interactive components
such as the InteractiveRunner and the given pipeline should be implicitly
created runner pipelines instead of pipeline instances defined by the user.</p>
<p>This is the shorthand for doing 3 steps: 1) compute once for metadata of the
given runner pipeline and everything watched from user pipelines; 2) associate
info between the runner pipeline and its corresponding user pipeline,
eliminate data from other user pipelines if there are any; 3) mutate the
runner pipeline to apply interactivity.</p>
</dd></dl>
<dl class="function">
<dt id="apache_beam.runners.interactive.pipeline_instrument.pcoll_to_pcoll_id">
<code class="descclassname">apache_beam.runners.interactive.pipeline_instrument.</code><code class="descname">pcoll_to_pcoll_id</code><span class="sig-paren">(</span><em>pipeline</em>, <em>original_context</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/runners/interactive/pipeline_instrument.html#pcoll_to_pcoll_id"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.runners.interactive.pipeline_instrument.pcoll_to_pcoll_id" title="Permalink to this definition"></a></dt>
<dd><p>Returns a dict mapping PCollections string to PCollection IDs.</p>
<p>Using a PipelineVisitor to iterate over every node in the pipeline,
records the mapping from PCollections to PCollections IDs. This mapping
will be used to query cached PCollections.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">(dict from str to str) a dict mapping str(pcoll) to pcoll_id.</td>
</tr>
</tbody>
</table>
</dd></dl>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="apache_beam.runners.interactive.recording_manager.html" class="btn btn-neutral float-right" title="apache_beam.runners.interactive.recording_manager module" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="apache_beam.runners.interactive.pipeline_fragment.html" class="btn btn-neutral float-left" title="apache_beam.runners.interactive.pipeline_fragment module" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>