blob: 8512f6c99d484f1129dbb61e3d3b14f82aa3a65d [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.io.gcp.spanner 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.io.avroio module" href="apache_beam.io.avroio.html" />
<link rel="prev" title="apache_beam.io.gcp.resource_identifiers module" href="apache_beam.io.gcp.resource_identifiers.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 current"><a class="reference internal" href="apache_beam.io.html">apache_beam.io package</a><ul class="current">
<li class="toctree-l2 current"><a class="reference internal" href="apache_beam.io.html#subpackages">Subpackages</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.aws.html">apache_beam.io.aws package</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.azure.html">apache_beam.io.azure package</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.external.html">apache_beam.io.external package</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.flink.html">apache_beam.io.flink package</a></li>
<li class="toctree-l3 current"><a class="reference internal" href="apache_beam.io.gcp.html">apache_beam.io.gcp package</a><ul class="current">
<li class="toctree-l4"><a class="reference internal" href="apache_beam.io.gcp.html#subpackages">Subpackages</a></li>
<li class="toctree-l4 current"><a class="reference internal" href="apache_beam.io.gcp.html#submodules">Submodules</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="apache_beam.io.html#submodules">Submodules</a></li>
</ul>
</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"><a class="reference internal" href="apache_beam.runners.html">apache_beam.runners package</a></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.io.html">apache_beam.io package</a> &raquo;</li>
<li><a href="apache_beam.io.gcp.html">apache_beam.io.gcp package</a> &raquo;</li>
<li>apache_beam.io.gcp.spanner module</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/apache_beam.io.gcp.spanner.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.io.gcp.spanner">
<span id="apache-beam-io-gcp-spanner-module"></span><h1>apache_beam.io.gcp.spanner module<a class="headerlink" href="#module-apache_beam.io.gcp.spanner" title="Permalink to this headline"></a></h1>
<p>PTransforms for supporting Spanner in Python pipelines.</p>
<p>These transforms are currently supported by Beam portable
Flink and Spark runners.</p>
<p><strong>Setup</strong></p>
<p>Transforms provided in this module are cross-language transforms
implemented in the Beam Java SDK. During the pipeline construction, Python SDK
will connect to a Java expansion service to expand these transforms.
To facilitate this, a small amount of setup is needed before using these
transforms in a Beam Python pipeline.</p>
<p>There are several ways to setup cross-language Spanner transforms.</p>
<ul class="simple">
<li>Option 1: use the default expansion service</li>
<li>Option 2: specify a custom expansion service</li>
</ul>
<p>See below for details regarding each of these options.</p>
<p><em>Option 1: Use the default expansion service</em></p>
<p>This is the recommended and easiest setup option for using Python Spanner
transforms. This option is only available for Beam 2.26.0 and later.</p>
<p>This option requires following pre-requisites before running the Beam
pipeline.</p>
<ul class="simple">
<li>Install Java runtime in the computer from where the pipeline is constructed
and make sure that ‘java’ command is available.</li>
</ul>
<p>In this option, Python SDK will either download (for released Beam version) or
build (when running from a Beam Git clone) a expansion service jar and use
that to expand transforms. Currently Spanner transforms use the
‘beam-sdks-java-io-google-cloud-platform-expansion-service’ jar for this
purpose.</p>
<p><em>Option 2: specify a custom expansion service</em></p>
<p>In this option, you startup your own expansion service and provide that as
a parameter when using the transforms provided in this module.</p>
<p>This option requires following pre-requisites before running the Beam
pipeline.</p>
<ul class="simple">
<li>Startup your own expansion service.</li>
<li>Update your pipeline to provide the expansion service address when
initiating Spanner transforms provided in this module.</li>
</ul>
<p>Flink Users can use the built-in Expansion Service of the Flink Runner’s
Job Server. If you start Flink’s Job Server, the expansion service will be
started on port 8097. For a different address, please set the
expansion_service parameter.</p>
<p><strong>More information</strong></p>
<p>For more information regarding cross-language transforms see:
- <a class="reference external" href="https://beam.apache.org/roadmap/portability/">https://beam.apache.org/roadmap/portability/</a></p>
<p>For more information specific to Flink runner see:
- <a class="reference external" href="https://beam.apache.org/documentation/runners/flink/">https://beam.apache.org/documentation/runners/flink/</a></p>
<dl class="class">
<dt id="apache_beam.io.gcp.spanner.TimeUnit">
<em class="property">class </em><code class="descclassname">apache_beam.io.gcp.spanner.</code><code class="descname">TimeUnit</code><a class="reference internal" href="_modules/apache_beam/io/gcp/spanner.html#TimeUnit"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.io.gcp.spanner.TimeUnit" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference external" href="https://docs.python.org/3/library/enum.html#enum.Enum" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">enum.Enum</span></code></a></p>
<p>An enumeration.</p>
<dl class="attribute">
<dt id="apache_beam.io.gcp.spanner.TimeUnit.NANOSECONDS">
<code class="descname">NANOSECONDS</code><em class="property"> = 1</em><a class="headerlink" href="#apache_beam.io.gcp.spanner.TimeUnit.NANOSECONDS" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="attribute">
<dt id="apache_beam.io.gcp.spanner.TimeUnit.MICROSECONDS">
<code class="descname">MICROSECONDS</code><em class="property"> = 2</em><a class="headerlink" href="#apache_beam.io.gcp.spanner.TimeUnit.MICROSECONDS" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="attribute">
<dt id="apache_beam.io.gcp.spanner.TimeUnit.MILLISECONDS">
<code class="descname">MILLISECONDS</code><em class="property"> = 3</em><a class="headerlink" href="#apache_beam.io.gcp.spanner.TimeUnit.MILLISECONDS" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="attribute">
<dt id="apache_beam.io.gcp.spanner.TimeUnit.SECONDS">
<code class="descname">SECONDS</code><em class="property"> = 4</em><a class="headerlink" href="#apache_beam.io.gcp.spanner.TimeUnit.SECONDS" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="attribute">
<dt id="apache_beam.io.gcp.spanner.TimeUnit.HOURS">
<code class="descname">HOURS</code><em class="property"> = 5</em><a class="headerlink" href="#apache_beam.io.gcp.spanner.TimeUnit.HOURS" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="attribute">
<dt id="apache_beam.io.gcp.spanner.TimeUnit.DAYS">
<code class="descname">DAYS</code><em class="property"> = 6</em><a class="headerlink" href="#apache_beam.io.gcp.spanner.TimeUnit.DAYS" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</dd></dl>
<dl class="class">
<dt id="apache_beam.io.gcp.spanner.TimestampBoundMode">
<em class="property">class </em><code class="descclassname">apache_beam.io.gcp.spanner.</code><code class="descname">TimestampBoundMode</code><a class="reference internal" href="_modules/apache_beam/io/gcp/spanner.html#TimestampBoundMode"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.io.gcp.spanner.TimestampBoundMode" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference external" href="https://docs.python.org/3/library/enum.html#enum.Enum" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">enum.Enum</span></code></a></p>
<p>An enumeration.</p>
<dl class="attribute">
<dt id="apache_beam.io.gcp.spanner.TimestampBoundMode.MAX_STALENESS">
<code class="descname">MAX_STALENESS</code><em class="property"> = 1</em><a class="headerlink" href="#apache_beam.io.gcp.spanner.TimestampBoundMode.MAX_STALENESS" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="attribute">
<dt id="apache_beam.io.gcp.spanner.TimestampBoundMode.EXACT_STALENESS">
<code class="descname">EXACT_STALENESS</code><em class="property"> = 2</em><a class="headerlink" href="#apache_beam.io.gcp.spanner.TimestampBoundMode.EXACT_STALENESS" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="attribute">
<dt id="apache_beam.io.gcp.spanner.TimestampBoundMode.READ_TIMESTAMP">
<code class="descname">READ_TIMESTAMP</code><em class="property"> = 3</em><a class="headerlink" href="#apache_beam.io.gcp.spanner.TimestampBoundMode.READ_TIMESTAMP" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="attribute">
<dt id="apache_beam.io.gcp.spanner.TimestampBoundMode.MIN_READ_TIMESTAMP">
<code class="descname">MIN_READ_TIMESTAMP</code><em class="property"> = 4</em><a class="headerlink" href="#apache_beam.io.gcp.spanner.TimestampBoundMode.MIN_READ_TIMESTAMP" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="attribute">
<dt id="apache_beam.io.gcp.spanner.TimestampBoundMode.STRONG">
<code class="descname">STRONG</code><em class="property"> = 5</em><a class="headerlink" href="#apache_beam.io.gcp.spanner.TimestampBoundMode.STRONG" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</dd></dl>
<dl class="class">
<dt id="apache_beam.io.gcp.spanner.ReadFromSpanner">
<em class="property">class </em><code class="descclassname">apache_beam.io.gcp.spanner.</code><code class="descname">ReadFromSpanner</code><span class="sig-paren">(</span><em>project_id</em>, <em>instance_id</em>, <em>database_id</em>, <em>row_type=None</em>, <em>sql=None</em>, <em>table=None</em>, <em>host=None</em>, <em>emulator_host=None</em>, <em>batching=None</em>, <em>timestamp_bound_mode=None</em>, <em>read_timestamp=None</em>, <em>staleness=None</em>, <em>time_unit=None</em>, <em>expansion_service=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/io/gcp/spanner.html#ReadFromSpanner"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.io.gcp.spanner.ReadFromSpanner" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="apache_beam.transforms.external.html#apache_beam.transforms.external.ExternalTransform" title="apache_beam.transforms.external.ExternalTransform"><code class="xref py py-class docutils literal notranslate"><span class="pre">apache_beam.transforms.external.ExternalTransform</span></code></a></p>
<p>A PTransform which reads from the specified Spanner instance’s database.</p>
<p>This transform required type of the row it has to return to provide the
schema. Example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">NamedTuple</span>
<span class="kn">from</span> <span class="nn">apache_beam</span> <span class="kn">import</span> <span class="n">coders</span>
<span class="k">class</span> <span class="nc">ExampleRow</span><span class="p">(</span><span class="n">NamedTuple</span><span class="p">):</span>
<span class="nb">id</span><span class="p">:</span> <span class="nb">int</span>
<span class="n">name</span><span class="p">:</span> <span class="n">unicode</span>
<span class="n">coders</span><span class="o">.</span><span class="n">registry</span><span class="o">.</span><span class="n">register_coder</span><span class="p">(</span><span class="n">ExampleRow</span><span class="p">,</span> <span class="n">coders</span><span class="o">.</span><span class="n">RowCoder</span><span class="p">)</span>
<span class="k">with</span> <span class="n">Pipeline</span><span class="p">()</span> <span class="k">as</span> <span class="n">p</span><span class="p">:</span>
<span class="n">result</span> <span class="o">=</span> <span class="p">(</span>
<span class="n">p</span>
<span class="o">|</span> <span class="n">ReadFromSpanner</span><span class="p">(</span>
<span class="n">instance_id</span><span class="o">=</span><span class="s1">&#39;your_instance_id&#39;</span><span class="p">,</span>
<span class="n">database_id</span><span class="o">=</span><span class="s1">&#39;your_database_id&#39;</span><span class="p">,</span>
<span class="n">project_id</span><span class="o">=</span><span class="s1">&#39;your_project_id&#39;</span><span class="p">,</span>
<span class="n">row_type</span><span class="o">=</span><span class="n">ExampleRow</span><span class="p">,</span>
<span class="n">sql</span><span class="o">=</span><span class="s1">&#39;SELECT * FROM some_table&#39;</span><span class="p">,</span>
<span class="n">timestamp_bound_mode</span><span class="o">=</span><span class="n">TimestampBoundMode</span><span class="o">.</span><span class="n">MAX_STALENESS</span><span class="p">,</span>
<span class="n">staleness</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span>
<span class="n">time_unit</span><span class="o">=</span><span class="n">TimeUnit</span><span class="o">.</span><span class="n">HOURS</span><span class="p">,</span>
<span class="p">)</span><span class="o">.</span><span class="n">with_output_types</span><span class="p">(</span><span class="n">ExampleRow</span><span class="p">))</span>
</pre></div>
</div>
<p>Experimental; no backwards compatibility guarantees.</p>
<p>Initializes a read operation from Spanner.</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">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>project_id</strong> – Specifies the Cloud Spanner project.</li>
<li><strong>instance_id</strong> – Specifies the Cloud Spanner instance.</li>
<li><strong>database_id</strong> – Specifies the Cloud Spanner database.</li>
<li><strong>row_type</strong> – Row type that fits the given query or table. Passed as
NamedTuple, e.g. NamedTuple(‘name’, [(‘row_name’, unicode)])</li>
<li><strong>sql</strong> – An sql query to execute. It’s results must fit the
provided row_type. Don’t use when table is set.</li>
<li><strong>table</strong> – A spanner table. When provided all columns from row_type
will be selected to query. Don’t use when query is set.</li>
<li><strong>batching</strong> – By default Batch API is used to read data from Cloud
Spanner. It is useful to disable batching when the underlying query
is not root-partitionable.</li>
<li><strong>host</strong> – Specifies the Cloud Spanner host.</li>
<li><strong>emulator_host</strong> – Specifies Spanner emulator host.</li>
<li><strong>timestamp_bound_mode</strong> – Defines how Cloud Spanner will choose a
timestamp for a read-only transaction or a single read/query.
Passed as TimestampBoundMode enum. Possible values:
STRONG: A timestamp bound that will perform reads and queries at a
timestamp where all previously committed transactions are visible.
READ_TIMESTAMP: Returns a timestamp bound that will perform reads
and queries at the given timestamp.
MIN_READ_TIMESTAMP: Returns a timestamp bound that will perform reads
and queries at a timestamp chosen to be at least given timestamp value.
EXACT_STALENESS: Returns a timestamp bound that will perform reads and
queries at an exact staleness. The timestamp is chosen soon after the
read is started.
MAX_STALENESS: Returns a timestamp bound that will perform reads and
queries at a timestamp chosen to be at most time_unit stale.</li>
<li><strong>read_timestamp</strong> – Timestamp in string. Use only when
timestamp_bound_mode is set to READ_TIMESTAMP or MIN_READ_TIMESTAMP.</li>
<li><strong>staleness</strong> – Staleness value as int. Use only when
timestamp_bound_mode is set to EXACT_STALENESS or MAX_STALENESS.
time_unit has to be set along with this param.</li>
<li><strong>time_unit</strong> – Time unit for staleness_value passed as TimeUnit enum.
Possible values: NANOSECONDS, MICROSECONDS, MILLISECONDS, SECONDS,
HOURS, DAYS.</li>
<li><strong>expansion_service</strong> – The address (host:port) of the ExpansionService.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<dl class="attribute">
<dt id="apache_beam.io.gcp.spanner.ReadFromSpanner.URN">
<code class="descname">URN</code><em class="property"> = 'beam:external:java:spanner:read:v1'</em><a class="headerlink" href="#apache_beam.io.gcp.spanner.ReadFromSpanner.URN" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</dd></dl>
<dl class="class">
<dt id="apache_beam.io.gcp.spanner.SpannerDelete">
<em class="property">class </em><code class="descclassname">apache_beam.io.gcp.spanner.</code><code class="descname">SpannerDelete</code><span class="sig-paren">(</span><em>project_id</em>, <em>instance_id</em>, <em>database_id</em>, <em>table</em>, <em>max_batch_size_bytes=None</em>, <em>max_number_mutations=None</em>, <em>max_number_rows=None</em>, <em>grouping_factor=None</em>, <em>host=None</em>, <em>emulator_host=None</em>, <em>commit_deadline=None</em>, <em>max_cumulative_backoff=None</em>, <em>expansion_service=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/io/gcp/spanner.html#SpannerDelete"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.io.gcp.spanner.SpannerDelete" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="apache_beam.transforms.external.html#apache_beam.transforms.external.ExternalTransform" title="apache_beam.transforms.external.ExternalTransform"><code class="xref py py-class docutils literal notranslate"><span class="pre">apache_beam.transforms.external.ExternalTransform</span></code></a></p>
<p>A PTransform which writes delete mutations to the specified Spanner
table.</p>
<p>This transform receives rows defined as NamedTuple. Example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">NamedTuple</span>
<span class="kn">from</span> <span class="nn">apache_beam</span> <span class="kn">import</span> <span class="n">coders</span>
<span class="k">class</span> <span class="nc">ExampleKey</span><span class="p">(</span><span class="n">NamedTuple</span><span class="p">):</span>
<span class="nb">id</span><span class="p">:</span> <span class="nb">int</span>
<span class="n">name</span><span class="p">:</span> <span class="n">unicode</span>
<span class="n">coders</span><span class="o">.</span><span class="n">registry</span><span class="o">.</span><span class="n">register_coder</span><span class="p">(</span><span class="n">ExampleKey</span><span class="p">,</span> <span class="n">coders</span><span class="o">.</span><span class="n">RowCoder</span><span class="p">)</span>
<span class="k">with</span> <span class="n">Pipeline</span><span class="p">()</span> <span class="k">as</span> <span class="n">p</span><span class="p">:</span>
<span class="n">_</span> <span class="o">=</span> <span class="p">(</span>
<span class="n">p</span>
<span class="o">|</span> <span class="s1">&#39;Impulse&#39;</span> <span class="o">&gt;&gt;</span> <span class="n">beam</span><span class="o">.</span><span class="n">Impulse</span><span class="p">()</span>
<span class="o">|</span> <span class="s1">&#39;Generate&#39;</span> <span class="o">&gt;&gt;</span> <span class="n">beam</span><span class="o">.</span><span class="n">FlatMap</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="nb">range</span><span class="p">(</span><span class="n">num_rows</span><span class="p">))</span>
<span class="o">|</span> <span class="s1">&#39;To row&#39;</span> <span class="o">&gt;&gt;</span> <span class="n">beam</span><span class="o">.</span><span class="n">Map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="n">ExampleKey</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">n</span><span class="p">))</span>
<span class="o">.</span><span class="n">with_output_types</span><span class="p">(</span><span class="n">ExampleKey</span><span class="p">)</span>
<span class="o">|</span> <span class="s1">&#39;Write to Spanner&#39;</span> <span class="o">&gt;&gt;</span> <span class="n">SpannerDelete</span><span class="p">(</span>
<span class="n">instance_id</span><span class="o">=</span><span class="s1">&#39;your_instance&#39;</span><span class="p">,</span>
<span class="n">database_id</span><span class="o">=</span><span class="s1">&#39;existing_database&#39;</span><span class="p">,</span>
<span class="n">project_id</span><span class="o">=</span><span class="s1">&#39;your_project_id&#39;</span><span class="p">,</span>
<span class="n">table</span><span class="o">=</span><span class="s1">&#39;your_table&#39;</span><span class="p">))</span>
</pre></div>
</div>
<p>Experimental; no backwards compatibility guarantees.</p>
<p>Initializes a delete operation to a Spanner table.</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">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>project_id</strong> – Specifies the Cloud Spanner project.</li>
<li><strong>instance_id</strong> – Specifies the Cloud Spanner instance.</li>
<li><strong>database_id</strong> – Specifies the Cloud Spanner database.</li>
<li><strong>table</strong> – Specifies the Cloud Spanner table.</li>
<li><strong>max_batch_size_bytes</strong> – Specifies the batch size limit (max number of
bytes mutated per batch). Default value is 1048576 bytes = 1MB.</li>
<li><strong>max_number_mutations</strong> – Specifies the cell mutation limit (maximum
number of mutated cells per batch). Default value is 5000.</li>
<li><strong>max_number_rows</strong> – Specifies the row mutation limit (maximum number of
mutated rows per batch). Default value is 500.</li>
<li><strong>grouping_factor</strong> – Specifies the multiple of max mutation (in terms
of both bytes per batch and cells per batch) that is used to select a
set of mutations to sort by key for batching. This sort uses local
memory on the workers, so using large values can cause out of memory
errors. Default value is 1000.</li>
<li><strong>host</strong> – Specifies the Cloud Spanner host.</li>
<li><strong>emulator_host</strong> – Specifies Spanner emulator host.</li>
<li><strong>commit_deadline</strong> – Specifies the deadline for the Commit API call.
Default is 15 secs. DEADLINE_EXCEEDED errors will prompt a backoff/retry
until the value of commit_deadline is reached. DEADLINE_EXCEEDED errors
are ar reported with logging and counters. Pass seconds as value.</li>
<li><strong>max_cumulative_backoff</strong> – Specifies the maximum cumulative backoff
time when retrying after DEADLINE_EXCEEDED errors. Default is 900s
(15min). If the mutations still have not been written after this time,
they are treated as a failure, and handled according to the setting of
failure_mode. Pass seconds as value.</li>
<li><strong>expansion_service</strong> – The address (host:port) of the ExpansionService.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<dl class="attribute">
<dt id="apache_beam.io.gcp.spanner.SpannerDelete.URN">
<code class="descname">URN</code><em class="property"> = 'beam:external:java:spanner:delete:v1'</em><a class="headerlink" href="#apache_beam.io.gcp.spanner.SpannerDelete.URN" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</dd></dl>
<dl class="class">
<dt id="apache_beam.io.gcp.spanner.SpannerInsert">
<em class="property">class </em><code class="descclassname">apache_beam.io.gcp.spanner.</code><code class="descname">SpannerInsert</code><span class="sig-paren">(</span><em>project_id</em>, <em>instance_id</em>, <em>database_id</em>, <em>table</em>, <em>max_batch_size_bytes=None</em>, <em>max_number_mutations=None</em>, <em>max_number_rows=None</em>, <em>grouping_factor=None</em>, <em>host=None</em>, <em>emulator_host=None</em>, <em>commit_deadline=None</em>, <em>max_cumulative_backoff=None</em>, <em>expansion_service=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/io/gcp/spanner.html#SpannerInsert"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.io.gcp.spanner.SpannerInsert" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="apache_beam.transforms.external.html#apache_beam.transforms.external.ExternalTransform" title="apache_beam.transforms.external.ExternalTransform"><code class="xref py py-class docutils literal notranslate"><span class="pre">apache_beam.transforms.external.ExternalTransform</span></code></a></p>
<p>A PTransform which writes insert mutations to the specified Spanner
table.</p>
<p>This transform receives rows defined as NamedTuple. Example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">NamedTuple</span>
<span class="kn">from</span> <span class="nn">apache_beam</span> <span class="kn">import</span> <span class="n">coders</span>
<span class="k">class</span> <span class="nc">ExampleRow</span><span class="p">(</span><span class="n">NamedTuple</span><span class="p">):</span>
<span class="nb">id</span><span class="p">:</span> <span class="nb">int</span>
<span class="n">name</span><span class="p">:</span> <span class="n">unicode</span>
<span class="n">coders</span><span class="o">.</span><span class="n">registry</span><span class="o">.</span><span class="n">register_coder</span><span class="p">(</span><span class="n">ExampleRow</span><span class="p">,</span> <span class="n">coders</span><span class="o">.</span><span class="n">RowCoder</span><span class="p">)</span>
<span class="k">with</span> <span class="n">Pipeline</span><span class="p">()</span> <span class="k">as</span> <span class="n">p</span><span class="p">:</span>
<span class="n">_</span> <span class="o">=</span> <span class="p">(</span>
<span class="n">p</span>
<span class="o">|</span> <span class="s1">&#39;Impulse&#39;</span> <span class="o">&gt;&gt;</span> <span class="n">beam</span><span class="o">.</span><span class="n">Impulse</span><span class="p">()</span>
<span class="o">|</span> <span class="s1">&#39;Generate&#39;</span> <span class="o">&gt;&gt;</span> <span class="n">beam</span><span class="o">.</span><span class="n">FlatMap</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="nb">range</span><span class="p">(</span><span class="n">num_rows</span><span class="p">))</span>
<span class="o">|</span> <span class="s1">&#39;To row&#39;</span> <span class="o">&gt;&gt;</span> <span class="n">beam</span><span class="o">.</span><span class="n">Map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="n">ExampleRow</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">n</span><span class="p">))</span>
<span class="o">.</span><span class="n">with_output_types</span><span class="p">(</span><span class="n">ExampleRow</span><span class="p">)</span>
<span class="o">|</span> <span class="s1">&#39;Write to Spanner&#39;</span> <span class="o">&gt;&gt;</span> <span class="n">SpannerInsert</span><span class="p">(</span>
<span class="n">instance_id</span><span class="o">=</span><span class="s1">&#39;your_instance&#39;</span><span class="p">,</span>
<span class="n">database_id</span><span class="o">=</span><span class="s1">&#39;existing_database&#39;</span><span class="p">,</span>
<span class="n">project_id</span><span class="o">=</span><span class="s1">&#39;your_project_id&#39;</span><span class="p">,</span>
<span class="n">table</span><span class="o">=</span><span class="s1">&#39;your_table&#39;</span><span class="p">))</span>
</pre></div>
</div>
<p>Experimental; no backwards compatibility guarantees.</p>
<p>Initializes an insert operation to a Spanner table.</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">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>project_id</strong> – Specifies the Cloud Spanner project.</li>
<li><strong>instance_id</strong> – Specifies the Cloud Spanner instance.</li>
<li><strong>database_id</strong> – Specifies the Cloud Spanner database.</li>
<li><strong>table</strong> – Specifies the Cloud Spanner table.</li>
<li><strong>max_batch_size_bytes</strong> – Specifies the batch size limit (max number of
bytes mutated per batch). Default value is 1048576 bytes = 1MB.</li>
<li><strong>max_number_mutations</strong> – Specifies the cell mutation limit (maximum
number of mutated cells per batch). Default value is 5000.</li>
<li><strong>max_number_rows</strong> – Specifies the row mutation limit (maximum number of
mutated rows per batch). Default value is 500.</li>
<li><strong>grouping_factor</strong> – Specifies the multiple of max mutation (in terms
of both bytes per batch and cells per batch) that is used to select a
set of mutations to sort by key for batching. This sort uses local
memory on the workers, so using large values can cause out of memory
errors. Default value is 1000.</li>
<li><strong>host</strong> – Specifies the Cloud Spanner host.</li>
<li><strong>emulator_host</strong> – Specifies Spanner emulator host.</li>
<li><strong>commit_deadline</strong> – Specifies the deadline for the Commit API call.
Default is 15 secs. DEADLINE_EXCEEDED errors will prompt a backoff/retry
until the value of commit_deadline is reached. DEADLINE_EXCEEDED errors
are ar reported with logging and counters. Pass seconds as value.</li>
<li><strong>max_cumulative_backoff</strong> – Specifies the maximum cumulative backoff
time when retrying after DEADLINE_EXCEEDED errors. Default is 900s
(15min). If the mutations still have not been written after this time,
they are treated as a failure, and handled according to the setting of
failure_mode. Pass seconds as value.</li>
<li><strong>expansion_service</strong> – The address (host:port) of the ExpansionService.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<dl class="attribute">
<dt id="apache_beam.io.gcp.spanner.SpannerInsert.URN">
<code class="descname">URN</code><em class="property"> = 'beam:external:java:spanner:insert:v1'</em><a class="headerlink" href="#apache_beam.io.gcp.spanner.SpannerInsert.URN" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</dd></dl>
<dl class="class">
<dt id="apache_beam.io.gcp.spanner.SpannerReplace">
<em class="property">class </em><code class="descclassname">apache_beam.io.gcp.spanner.</code><code class="descname">SpannerReplace</code><span class="sig-paren">(</span><em>project_id</em>, <em>instance_id</em>, <em>database_id</em>, <em>table</em>, <em>max_batch_size_bytes=None</em>, <em>max_number_mutations=None</em>, <em>max_number_rows=None</em>, <em>grouping_factor=None</em>, <em>host=None</em>, <em>emulator_host=None</em>, <em>commit_deadline=None</em>, <em>max_cumulative_backoff=None</em>, <em>expansion_service=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/io/gcp/spanner.html#SpannerReplace"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.io.gcp.spanner.SpannerReplace" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="apache_beam.transforms.external.html#apache_beam.transforms.external.ExternalTransform" title="apache_beam.transforms.external.ExternalTransform"><code class="xref py py-class docutils literal notranslate"><span class="pre">apache_beam.transforms.external.ExternalTransform</span></code></a></p>
<p>A PTransform which writes replace mutations to the specified Spanner
table.</p>
<p>This transform receives rows defined as NamedTuple. Example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">NamedTuple</span>
<span class="kn">from</span> <span class="nn">apache_beam</span> <span class="kn">import</span> <span class="n">coders</span>
<span class="k">class</span> <span class="nc">ExampleRow</span><span class="p">(</span><span class="n">NamedTuple</span><span class="p">):</span>
<span class="nb">id</span><span class="p">:</span> <span class="nb">int</span>
<span class="n">name</span><span class="p">:</span> <span class="n">unicode</span>
<span class="n">coders</span><span class="o">.</span><span class="n">registry</span><span class="o">.</span><span class="n">register_coder</span><span class="p">(</span><span class="n">ExampleRow</span><span class="p">,</span> <span class="n">coders</span><span class="o">.</span><span class="n">RowCoder</span><span class="p">)</span>
<span class="k">with</span> <span class="n">Pipeline</span><span class="p">()</span> <span class="k">as</span> <span class="n">p</span><span class="p">:</span>
<span class="n">_</span> <span class="o">=</span> <span class="p">(</span>
<span class="n">p</span>
<span class="o">|</span> <span class="s1">&#39;Impulse&#39;</span> <span class="o">&gt;&gt;</span> <span class="n">beam</span><span class="o">.</span><span class="n">Impulse</span><span class="p">()</span>
<span class="o">|</span> <span class="s1">&#39;Generate&#39;</span> <span class="o">&gt;&gt;</span> <span class="n">beam</span><span class="o">.</span><span class="n">FlatMap</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="nb">range</span><span class="p">(</span><span class="n">num_rows</span><span class="p">))</span>
<span class="o">|</span> <span class="s1">&#39;To row&#39;</span> <span class="o">&gt;&gt;</span> <span class="n">beam</span><span class="o">.</span><span class="n">Map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="n">ExampleRow</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">n</span><span class="p">))</span>
<span class="o">.</span><span class="n">with_output_types</span><span class="p">(</span><span class="n">ExampleRow</span><span class="p">)</span>
<span class="o">|</span> <span class="s1">&#39;Write to Spanner&#39;</span> <span class="o">&gt;&gt;</span> <span class="n">SpannerReplace</span><span class="p">(</span>
<span class="n">instance_id</span><span class="o">=</span><span class="s1">&#39;your_instance&#39;</span><span class="p">,</span>
<span class="n">database_id</span><span class="o">=</span><span class="s1">&#39;existing_database&#39;</span><span class="p">,</span>
<span class="n">project_id</span><span class="o">=</span><span class="s1">&#39;your_project_id&#39;</span><span class="p">,</span>
<span class="n">table</span><span class="o">=</span><span class="s1">&#39;your_table&#39;</span><span class="p">))</span>
</pre></div>
</div>
<p>Experimental; no backwards compatibility guarantees.</p>
<p>Initializes a replace operation to a Spanner table.</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">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>project_id</strong> – Specifies the Cloud Spanner project.</li>
<li><strong>instance_id</strong> – Specifies the Cloud Spanner instance.</li>
<li><strong>database_id</strong> – Specifies the Cloud Spanner database.</li>
<li><strong>table</strong> – Specifies the Cloud Spanner table.</li>
<li><strong>max_batch_size_bytes</strong> – Specifies the batch size limit (max number of
bytes mutated per batch). Default value is 1048576 bytes = 1MB.</li>
<li><strong>max_number_mutations</strong> – Specifies the cell mutation limit (maximum
number of mutated cells per batch). Default value is 5000.</li>
<li><strong>max_number_rows</strong> – Specifies the row mutation limit (maximum number of
mutated rows per batch). Default value is 500.</li>
<li><strong>grouping_factor</strong> – Specifies the multiple of max mutation (in terms
of both bytes per batch and cells per batch) that is used to select a
set of mutations to sort by key for batching. This sort uses local
memory on the workers, so using large values can cause out of memory
errors. Default value is 1000.</li>
<li><strong>host</strong> – Specifies the Cloud Spanner host.</li>
<li><strong>emulator_host</strong> – Specifies Spanner emulator host.</li>
<li><strong>commit_deadline</strong> – Specifies the deadline for the Commit API call.
Default is 15 secs. DEADLINE_EXCEEDED errors will prompt a backoff/retry
until the value of commit_deadline is reached. DEADLINE_EXCEEDED errors
are ar reported with logging and counters. Pass seconds as value.</li>
<li><strong>max_cumulative_backoff</strong> – Specifies the maximum cumulative backoff
time when retrying after DEADLINE_EXCEEDED errors. Default is 900s
(15min). If the mutations still have not been written after this time,
they are treated as a failure, and handled according to the setting of
failure_mode. Pass seconds as value.</li>
<li><strong>expansion_service</strong> – The address (host:port) of the ExpansionService.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<dl class="attribute">
<dt id="apache_beam.io.gcp.spanner.SpannerReplace.URN">
<code class="descname">URN</code><em class="property"> = 'beam:external:java:spanner:replace:v1'</em><a class="headerlink" href="#apache_beam.io.gcp.spanner.SpannerReplace.URN" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</dd></dl>
<dl class="class">
<dt id="apache_beam.io.gcp.spanner.SpannerInsertOrUpdate">
<em class="property">class </em><code class="descclassname">apache_beam.io.gcp.spanner.</code><code class="descname">SpannerInsertOrUpdate</code><span class="sig-paren">(</span><em>project_id</em>, <em>instance_id</em>, <em>database_id</em>, <em>table</em>, <em>max_batch_size_bytes=None</em>, <em>max_number_mutations=None</em>, <em>max_number_rows=None</em>, <em>grouping_factor=None</em>, <em>host=None</em>, <em>emulator_host=None</em>, <em>commit_deadline=None</em>, <em>max_cumulative_backoff=None</em>, <em>expansion_service=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/io/gcp/spanner.html#SpannerInsertOrUpdate"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.io.gcp.spanner.SpannerInsertOrUpdate" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="apache_beam.transforms.external.html#apache_beam.transforms.external.ExternalTransform" title="apache_beam.transforms.external.ExternalTransform"><code class="xref py py-class docutils literal notranslate"><span class="pre">apache_beam.transforms.external.ExternalTransform</span></code></a></p>
<p>A PTransform which writes insert-or-update mutations to the specified Spanner
table.</p>
<p>This transform receives rows defined as NamedTuple. Example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">NamedTuple</span>
<span class="kn">from</span> <span class="nn">apache_beam</span> <span class="kn">import</span> <span class="n">coders</span>
<span class="k">class</span> <span class="nc">ExampleRow</span><span class="p">(</span><span class="n">NamedTuple</span><span class="p">):</span>
<span class="nb">id</span><span class="p">:</span> <span class="nb">int</span>
<span class="n">name</span><span class="p">:</span> <span class="n">unicode</span>
<span class="n">coders</span><span class="o">.</span><span class="n">registry</span><span class="o">.</span><span class="n">register_coder</span><span class="p">(</span><span class="n">ExampleRow</span><span class="p">,</span> <span class="n">coders</span><span class="o">.</span><span class="n">RowCoder</span><span class="p">)</span>
<span class="k">with</span> <span class="n">Pipeline</span><span class="p">()</span> <span class="k">as</span> <span class="n">p</span><span class="p">:</span>
<span class="n">_</span> <span class="o">=</span> <span class="p">(</span>
<span class="n">p</span>
<span class="o">|</span> <span class="s1">&#39;Impulse&#39;</span> <span class="o">&gt;&gt;</span> <span class="n">beam</span><span class="o">.</span><span class="n">Impulse</span><span class="p">()</span>
<span class="o">|</span> <span class="s1">&#39;Generate&#39;</span> <span class="o">&gt;&gt;</span> <span class="n">beam</span><span class="o">.</span><span class="n">FlatMap</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="nb">range</span><span class="p">(</span><span class="n">num_rows</span><span class="p">))</span>
<span class="o">|</span> <span class="s1">&#39;To row&#39;</span> <span class="o">&gt;&gt;</span> <span class="n">beam</span><span class="o">.</span><span class="n">Map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="n">ExampleRow</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">n</span><span class="p">))</span>
<span class="o">.</span><span class="n">with_output_types</span><span class="p">(</span><span class="n">ExampleRow</span><span class="p">)</span>
<span class="o">|</span> <span class="s1">&#39;Write to Spanner&#39;</span> <span class="o">&gt;&gt;</span> <span class="n">SpannerInsertOrUpdate</span><span class="p">(</span>
<span class="n">instance_id</span><span class="o">=</span><span class="s1">&#39;your_instance&#39;</span><span class="p">,</span>
<span class="n">database_id</span><span class="o">=</span><span class="s1">&#39;existing_database&#39;</span><span class="p">,</span>
<span class="n">project_id</span><span class="o">=</span><span class="s1">&#39;your_project_id&#39;</span><span class="p">,</span>
<span class="n">table</span><span class="o">=</span><span class="s1">&#39;your_table&#39;</span><span class="p">))</span>
</pre></div>
</div>
<p>Experimental; no backwards compatibility guarantees.</p>
<p>Initializes an insert-or-update operation to a Spanner table.</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">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>project_id</strong> – Specifies the Cloud Spanner project.</li>
<li><strong>instance_id</strong> – Specifies the Cloud Spanner instance.</li>
<li><strong>database_id</strong> – Specifies the Cloud Spanner database.</li>
<li><strong>table</strong> – Specifies the Cloud Spanner table.</li>
<li><strong>max_batch_size_bytes</strong> – Specifies the batch size limit (max number of
bytes mutated per batch). Default value is 1048576 bytes = 1MB.</li>
<li><strong>max_number_mutations</strong> – Specifies the cell mutation limit (maximum
number of mutated cells per batch). Default value is 5000.</li>
<li><strong>max_number_rows</strong> – Specifies the row mutation limit (maximum number of
mutated rows per batch). Default value is 500.</li>
<li><strong>grouping_factor</strong> – Specifies the multiple of max mutation (in terms
of both bytes per batch and cells per batch) that is used to select a
set of mutations to sort by key for batching. This sort uses local
memory on the workers, so using large values can cause out of memory
errors. Default value is 1000.</li>
<li><strong>host</strong> – Specifies the Cloud Spanner host.</li>
<li><strong>emulator_host</strong> – Specifies Spanner emulator host.</li>
<li><strong>commit_deadline</strong> – Specifies the deadline for the Commit API call.
Default is 15 secs. DEADLINE_EXCEEDED errors will prompt a backoff/retry
until the value of commit_deadline is reached. DEADLINE_EXCEEDED errors
are ar reported with logging and counters. Pass seconds as value.</li>
<li><strong>max_cumulative_backoff</strong> – Specifies the maximum cumulative backoff
time when retrying after DEADLINE_EXCEEDED errors. Default is 900s
(15min). If the mutations still have not been written after this time,
they are treated as a failure, and handled according to the setting of
failure_mode. Pass seconds as value.</li>
<li><strong>expansion_service</strong> – The address (host:port) of the ExpansionService.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<dl class="attribute">
<dt id="apache_beam.io.gcp.spanner.SpannerInsertOrUpdate.URN">
<code class="descname">URN</code><em class="property"> = 'beam:external:java:spanner:insert_or_update:v1'</em><a class="headerlink" href="#apache_beam.io.gcp.spanner.SpannerInsertOrUpdate.URN" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</dd></dl>
<dl class="class">
<dt id="apache_beam.io.gcp.spanner.SpannerUpdate">
<em class="property">class </em><code class="descclassname">apache_beam.io.gcp.spanner.</code><code class="descname">SpannerUpdate</code><span class="sig-paren">(</span><em>project_id</em>, <em>instance_id</em>, <em>database_id</em>, <em>table</em>, <em>max_batch_size_bytes=None</em>, <em>max_number_mutations=None</em>, <em>max_number_rows=None</em>, <em>grouping_factor=None</em>, <em>host=None</em>, <em>emulator_host=None</em>, <em>commit_deadline=None</em>, <em>max_cumulative_backoff=None</em>, <em>expansion_service=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/io/gcp/spanner.html#SpannerUpdate"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.io.gcp.spanner.SpannerUpdate" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="apache_beam.transforms.external.html#apache_beam.transforms.external.ExternalTransform" title="apache_beam.transforms.external.ExternalTransform"><code class="xref py py-class docutils literal notranslate"><span class="pre">apache_beam.transforms.external.ExternalTransform</span></code></a></p>
<p>A PTransform which writes update mutations to the specified Spanner
table.</p>
<p>This transform receives rows defined as NamedTuple. Example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">NamedTuple</span>
<span class="kn">from</span> <span class="nn">apache_beam</span> <span class="kn">import</span> <span class="n">coders</span>
<span class="k">class</span> <span class="nc">ExampleRow</span><span class="p">(</span><span class="n">NamedTuple</span><span class="p">):</span>
<span class="nb">id</span><span class="p">:</span> <span class="nb">int</span>
<span class="n">name</span><span class="p">:</span> <span class="n">unicode</span>
<span class="n">coders</span><span class="o">.</span><span class="n">registry</span><span class="o">.</span><span class="n">register_coder</span><span class="p">(</span><span class="n">ExampleRow</span><span class="p">,</span> <span class="n">coders</span><span class="o">.</span><span class="n">RowCoder</span><span class="p">)</span>
<span class="k">with</span> <span class="n">Pipeline</span><span class="p">()</span> <span class="k">as</span> <span class="n">p</span><span class="p">:</span>
<span class="n">_</span> <span class="o">=</span> <span class="p">(</span>
<span class="n">p</span>
<span class="o">|</span> <span class="s1">&#39;Impulse&#39;</span> <span class="o">&gt;&gt;</span> <span class="n">beam</span><span class="o">.</span><span class="n">Impulse</span><span class="p">()</span>
<span class="o">|</span> <span class="s1">&#39;Generate&#39;</span> <span class="o">&gt;&gt;</span> <span class="n">beam</span><span class="o">.</span><span class="n">FlatMap</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="nb">range</span><span class="p">(</span><span class="n">num_rows</span><span class="p">))</span>
<span class="o">|</span> <span class="s1">&#39;To row&#39;</span> <span class="o">&gt;&gt;</span> <span class="n">beam</span><span class="o">.</span><span class="n">Map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="n">ExampleRow</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">n</span><span class="p">))</span>
<span class="o">.</span><span class="n">with_output_types</span><span class="p">(</span><span class="n">ExampleRow</span><span class="p">)</span>
<span class="o">|</span> <span class="s1">&#39;Write to Spanner&#39;</span> <span class="o">&gt;&gt;</span> <span class="n">SpannerUpdate</span><span class="p">(</span>
<span class="n">instance_id</span><span class="o">=</span><span class="s1">&#39;your_instance&#39;</span><span class="p">,</span>
<span class="n">database_id</span><span class="o">=</span><span class="s1">&#39;existing_database&#39;</span><span class="p">,</span>
<span class="n">project_id</span><span class="o">=</span><span class="s1">&#39;your_project_id&#39;</span><span class="p">,</span>
<span class="n">table</span><span class="o">=</span><span class="s1">&#39;your_table&#39;</span><span class="p">))</span>
</pre></div>
</div>
<p>Experimental; no backwards compatibility guarantees.</p>
<p>Initializes an update operation to a Spanner table.</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">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>project_id</strong> – Specifies the Cloud Spanner project.</li>
<li><strong>instance_id</strong> – Specifies the Cloud Spanner instance.</li>
<li><strong>database_id</strong> – Specifies the Cloud Spanner database.</li>
<li><strong>table</strong> – Specifies the Cloud Spanner table.</li>
<li><strong>max_batch_size_bytes</strong> – Specifies the batch size limit (max number of
bytes mutated per batch). Default value is 1048576 bytes = 1MB.</li>
<li><strong>max_number_mutations</strong> – Specifies the cell mutation limit (maximum
number of mutated cells per batch). Default value is 5000.</li>
<li><strong>max_number_rows</strong> – Specifies the row mutation limit (maximum number of
mutated rows per batch). Default value is 500.</li>
<li><strong>grouping_factor</strong> – Specifies the multiple of max mutation (in terms
of both bytes per batch and cells per batch) that is used to select a
set of mutations to sort by key for batching. This sort uses local
memory on the workers, so using large values can cause out of memory
errors. Default value is 1000.</li>
<li><strong>host</strong> – Specifies the Cloud Spanner host.</li>
<li><strong>emulator_host</strong> – Specifies Spanner emulator host.</li>
<li><strong>commit_deadline</strong> – Specifies the deadline for the Commit API call.
Default is 15 secs. DEADLINE_EXCEEDED errors will prompt a backoff/retry
until the value of commit_deadline is reached. DEADLINE_EXCEEDED errors
are ar reported with logging and counters. Pass seconds as value.</li>
<li><strong>max_cumulative_backoff</strong> – Specifies the maximum cumulative backoff
time when retrying after DEADLINE_EXCEEDED errors. Default is 900s
(15min). If the mutations still have not been written after this time,
they are treated as a failure, and handled according to the setting of
failure_mode. Pass seconds as value.</li>
<li><strong>expansion_service</strong> – The address (host:port) of the ExpansionService.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<dl class="attribute">
<dt id="apache_beam.io.gcp.spanner.SpannerUpdate.URN">
<code class="descname">URN</code><em class="property"> = 'beam:external:java:spanner:update:v1'</em><a class="headerlink" href="#apache_beam.io.gcp.spanner.SpannerUpdate.URN" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</dd></dl>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="apache_beam.io.avroio.html" class="btn btn-neutral float-right" title="apache_beam.io.avroio module" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="apache_beam.io.gcp.resource_identifiers.html" class="btn btn-neutral float-left" title="apache_beam.io.gcp.resource_identifiers 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>