blob: 1b659febb5ccffa265b57b80db563fa3507ed858 [file] [log] [blame]
<!DOCTYPE html>
<html class="writer-html5" lang="en" data-content_root="./">
<head>
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>apache_beam.io.source_test_utils module &mdash; Apache Beam 2.67.0 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=b86133f3" />
<link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=e59714d7" />
<script src="_static/jquery.js?v=5d32c60e"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="_static/documentation_options.js?v=959b4fbe"></script>
<script src="_static/doctools.js?v=9a2dae69"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/js/theme.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="apache_beam.io.textio module" href="apache_beam.io.textio.html" />
<link rel="prev" title="apache_beam.io.snowflake module" href="apache_beam.io.snowflake.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" aria-label="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="Navigation menu">
<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"><a class="reference internal" href="apache_beam.io.html#subpackages">Subpackages</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="apache_beam.io.html#submodules">Submodules</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.avroio.html">apache_beam.io.avroio module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.concat_source.html">apache_beam.io.concat_source module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.debezium.html">apache_beam.io.debezium module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.filebasedsink.html">apache_beam.io.filebasedsink module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.filebasedsource.html">apache_beam.io.filebasedsource module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.fileio.html">apache_beam.io.fileio module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.filesystem.html">apache_beam.io.filesystem module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.filesystemio.html">apache_beam.io.filesystemio module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.filesystems.html">apache_beam.io.filesystems module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.hadoopfilesystem.html">apache_beam.io.hadoopfilesystem module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.iobase.html">apache_beam.io.iobase module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.jdbc.html">apache_beam.io.jdbc module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.kafka.html">apache_beam.io.kafka module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.kinesis.html">apache_beam.io.kinesis module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.localfilesystem.html">apache_beam.io.localfilesystem module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.mongodbio.html">apache_beam.io.mongodbio module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.parquetio.html">apache_beam.io.parquetio module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.range_trackers.html">apache_beam.io.range_trackers module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.requestresponse.html">apache_beam.io.requestresponse module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.restriction_trackers.html">apache_beam.io.restriction_trackers module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.snowflake.html">apache_beam.io.snowflake module</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">apache_beam.io.source_test_utils module</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#apache_beam.io.source_test_utils.read_from_source"><code class="docutils literal notranslate"><span class="pre">read_from_source()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apache_beam.io.source_test_utils.assert_sources_equal_reference_source"><code class="docutils literal notranslate"><span class="pre">assert_sources_equal_reference_source()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apache_beam.io.source_test_utils.assert_reentrant_reads_succeed"><code class="docutils literal notranslate"><span class="pre">assert_reentrant_reads_succeed()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apache_beam.io.source_test_utils.assert_split_at_fraction_behavior"><code class="docutils literal notranslate"><span class="pre">assert_split_at_fraction_behavior()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apache_beam.io.source_test_utils.assert_split_at_fraction_binary"><code class="docutils literal notranslate"><span class="pre">assert_split_at_fraction_binary()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apache_beam.io.source_test_utils.assert_split_at_fraction_exhaustive"><code class="docutils literal notranslate"><span class="pre">assert_split_at_fraction_exhaustive()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apache_beam.io.source_test_utils.assert_split_at_fraction_fails"><code class="docutils literal notranslate"><span class="pre">assert_split_at_fraction_fails()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#apache_beam.io.source_test_utils.assert_split_at_fraction_succeeds_and_consistent"><code class="docutils literal notranslate"><span class="pre">assert_split_at_fraction_succeeds_and_consistent()</span></code></a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.textio.html">apache_beam.io.textio module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.tfrecordio.html">apache_beam.io.tfrecordio module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.utils.html">apache_beam.io.utils module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.io.watermark_estimators.html">apache_beam.io.watermark_estimators module</a></li>
</ul>
</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.testing.html">apache_beam.testing 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>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.yaml.html">apache_beam.yaml 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="Mobile navigation menu" >
<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="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html" class="icon icon-home" aria-label="Home"></a></li>
<li class="breadcrumb-item"><a href="apache_beam.io.html">apache_beam.io package</a></li>
<li class="breadcrumb-item active">apache_beam.io.source_test_utils module</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/apache_beam.io.source_test_utils.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">
<section id="module-apache_beam.io.source_test_utils">
<span id="apache-beam-io-source-test-utils-module"></span><h1>apache_beam.io.source_test_utils module<a class="headerlink" href="#module-apache_beam.io.source_test_utils" title="Link to this heading"></a></h1>
<p>Helper functions and test harnesses for source implementations.</p>
<p>This module contains helper functions and test harnesses for checking
correctness of source (a subclass of <code class="docutils literal notranslate"><span class="pre">iobase.BoundedSource</span></code>) and range
tracker (a subclass of``iobase.RangeTracker``) implementations.</p>
<p>Contains a few lightweight utilities (e.g. reading items from a source such as
<code class="docutils literal notranslate"><span class="pre">readFromSource()</span></code>, as well as heavyweight property testing and stress
testing harnesses that help getting a large amount of test coverage with few
code.</p>
<p>Most notable ones are:
* <code class="docutils literal notranslate"><span class="pre">assertSourcesEqualReferenceSource()</span></code> helps testing that the data read by
the union of sources produced by <code class="docutils literal notranslate"><span class="pre">BoundedSource.split()</span></code> is the same as data
read by the original source.
* If your source implements dynamic work rebalancing, use the
<code class="docutils literal notranslate"><span class="pre">assertSplitAtFraction()</span></code> family of functions - they test behavior of
<code class="docutils literal notranslate"><span class="pre">RangeTracker.try_split()</span></code>, in particular, that various consistency
properties are respected and the total set of data read by the source is
preserved when splits happen. Use <code class="docutils literal notranslate"><span class="pre">assertSplitAtFractionBehavior()</span></code> to test
individual cases of <code class="docutils literal notranslate"><span class="pre">RangeTracker.try_split()</span></code> and use
<code class="docutils literal notranslate"><span class="pre">assertSplitAtFractionExhaustive()</span></code> as a heavy-weight stress test including
concurrency. We strongly recommend to use both.</p>
<dl class="simple">
<dt>For example usages, see the unit tests of modules such as</dt><dd><ul class="simple">
<li><p>apache_beam.io.source_test_utils_test.py</p></li>
<li><p>apache_beam.io.avroio_test.py</p></li>
</ul>
</dd>
</dl>
<dl class="py function">
<dt class="sig sig-object py" id="apache_beam.io.source_test_utils.read_from_source">
<span class="sig-prename descclassname"><span class="pre">apache_beam.io.source_test_utils.</span></span><span class="sig-name descname"><span class="pre">read_from_source</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">source</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">start_position</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">stop_position</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/io/source_test_utils.html#read_from_source"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#apache_beam.io.source_test_utils.read_from_source" title="Link to this definition"></a></dt>
<dd><p>Reads elements from the given <code class="docutils literal notranslate"><span class="pre">`BoundedSource`</span></code>.</p>
<p>Only reads elements within the given position range.
:param source: <a class="reference internal" href="apache_beam.io.iobase.html#apache_beam.io.iobase.BoundedSource" title="apache_beam.io.iobase.BoundedSource"><code class="xref py py-class docutils literal notranslate"><span class="pre">BoundedSource</span></code></a> implementation.
:type source: ~apache_beam.io.iobase.BoundedSource
:param start_position: start position for reading.
:type start_position: int
:param stop_position: stop position for reading.
:type stop_position: int</p>
<dl class="field-list simple">
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p>the set of values read from the sources.</p>
</dd>
<dt class="field-even">Return type<span class="colon">:</span></dt>
<dd class="field-even"><p>List[<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a>]</p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="apache_beam.io.source_test_utils.assert_sources_equal_reference_source">
<span class="sig-prename descclassname"><span class="pre">apache_beam.io.source_test_utils.</span></span><span class="sig-name descname"><span class="pre">assert_sources_equal_reference_source</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">reference_source_info</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sources_info</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/io/source_test_utils.html#assert_sources_equal_reference_source"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#apache_beam.io.source_test_utils.assert_sources_equal_reference_source" title="Link to this definition"></a></dt>
<dd><p>Tests if a reference source is equal to a given set of sources.</p>
<p>Given a reference source (a <a class="reference internal" href="apache_beam.io.iobase.html#apache_beam.io.iobase.BoundedSource" title="apache_beam.io.iobase.BoundedSource"><code class="xref py py-class docutils literal notranslate"><span class="pre">BoundedSource</span></code></a>
and a position range) and a list of sources, assert that the union of the
records read from the list of sources is equal to the records read from the
reference source.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>reference_source_info</strong> (<em>Tuple</em><em>[</em><a class="reference internal" href="apache_beam.io.iobase.html#apache_beam.io.iobase.BoundedSource" title="apache_beam.io.iobase.BoundedSource"><em>BoundedSource</em></a><em>, </em><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><em>int</em></a><em>, </em><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><em>int</em></a><em>]</em>) – a three-tuple that gives the reference
<a class="reference internal" href="apache_beam.io.iobase.html#apache_beam.io.iobase.BoundedSource" title="apache_beam.io.iobase.BoundedSource"><code class="xref py py-class docutils literal notranslate"><span class="pre">BoundedSource</span></code></a>, position to start
reading at, and position to stop reading at.</p></li>
<li><p><strong>sources_info</strong> (<em>Iterable</em><em>[</em><em>Tuple</em><em>[</em><a class="reference internal" href="apache_beam.io.iobase.html#apache_beam.io.iobase.BoundedSource" title="apache_beam.io.iobase.BoundedSource"><em>BoundedSource</em></a><em>, </em><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><em>int</em></a><em>, </em><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><em>int</em></a><em>]</em><em>]</em>) – a set of sources. Each source is a three-tuple that is of the same
format described above.</p></li>
</ul>
</dd>
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#ValueError" title="(in Python v3.13)"><strong>ValueError</strong></a> – if the set of data produced by the reference source
and the given set of sources are not equivalent.</p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="apache_beam.io.source_test_utils.assert_reentrant_reads_succeed">
<span class="sig-prename descclassname"><span class="pre">apache_beam.io.source_test_utils.</span></span><span class="sig-name descname"><span class="pre">assert_reentrant_reads_succeed</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">source_info</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/io/source_test_utils.html#assert_reentrant_reads_succeed"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#apache_beam.io.source_test_utils.assert_reentrant_reads_succeed" title="Link to this definition"></a></dt>
<dd><p>Tests if a given source can be read in a reentrant manner.</p>
<p>Assume that given source produces the set of values <code class="docutils literal notranslate"><span class="pre">{v1,</span> <span class="pre">v2,</span> <span class="pre">v3,</span> <span class="pre">...</span> <span class="pre">vn}</span></code>.
For <code class="docutils literal notranslate"><span class="pre">i</span></code> in range <code class="docutils literal notranslate"><span class="pre">[1,</span> <span class="pre">n-1]</span></code> this method performs a reentrant read after
reading <code class="docutils literal notranslate"><span class="pre">i</span></code> elements and verifies that both the original and reentrant read
produce the expected set of values.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>source_info</strong> (<em>Tuple</em><em>[</em><a class="reference internal" href="apache_beam.io.iobase.html#apache_beam.io.iobase.BoundedSource" title="apache_beam.io.iobase.BoundedSource"><em>BoundedSource</em></a><em>, </em><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><em>int</em></a><em>, </em><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><em>int</em></a><em>]</em>) – a three-tuple that gives the reference
<a class="reference internal" href="apache_beam.io.iobase.html#apache_beam.io.iobase.BoundedSource" title="apache_beam.io.iobase.BoundedSource"><code class="xref py py-class docutils literal notranslate"><span class="pre">BoundedSource</span></code></a>, position to start reading
at, and a position to stop reading at.</p>
</dd>
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#ValueError" title="(in Python v3.13)"><strong>ValueError</strong></a> – if source is too trivial or reentrant read result
in an incorrect read.</p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="apache_beam.io.source_test_utils.assert_split_at_fraction_behavior">
<span class="sig-prename descclassname"><span class="pre">apache_beam.io.source_test_utils.</span></span><span class="sig-name descname"><span class="pre">assert_split_at_fraction_behavior</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">source</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">num_items_to_read_before_split</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">split_fraction</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">expected_outcome</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/io/source_test_utils.html#assert_split_at_fraction_behavior"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#apache_beam.io.source_test_utils.assert_split_at_fraction_behavior" title="Link to this definition"></a></dt>
<dd><p>Verifies the behaviour of splitting a source at a given fraction.</p>
<p>Asserts that splitting a <a class="reference internal" href="apache_beam.io.iobase.html#apache_beam.io.iobase.BoundedSource" title="apache_beam.io.iobase.BoundedSource"><code class="xref py py-class docutils literal notranslate"><span class="pre">BoundedSource</span></code></a> either
fails after reading <strong>num_items_to_read_before_split</strong> items, or succeeds in
a way that is consistent according to
<a class="reference internal" href="#apache_beam.io.source_test_utils.assert_split_at_fraction_succeeds_and_consistent" title="apache_beam.io.source_test_utils.assert_split_at_fraction_succeeds_and_consistent"><code class="xref py py-func docutils literal notranslate"><span class="pre">assert_split_at_fraction_succeeds_and_consistent()</span></code></a>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>source</strong> (<a class="reference internal" href="apache_beam.io.iobase.html#apache_beam.io.iobase.BoundedSource" title="apache_beam.io.iobase.BoundedSource"><em>BoundedSource</em></a>) – the source to perform
dynamic splitting on.</p></li>
<li><p><strong>num_items_to_read_before_split</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><em>int</em></a>) – number of items to read before
splitting.</p></li>
<li><p><strong>split_fraction</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.13)"><em>float</em></a>) – fraction to split at.</p></li>
<li><p><strong>expected_outcome</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><em>int</em></a>) – a value from
<code class="xref py py-class docutils literal notranslate"><span class="pre">ExpectedSplitOutcome</span></code>.</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>a tuple that gives the number of items produced by reading
the two ranges produced after dynamic splitting. If splitting did not
occur, the first value of the tuple will represent the full set of records
read by the source while the second value of the tuple will be <code class="docutils literal notranslate"><span class="pre">-1</span></code>.</p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p>Tuple[<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)">int</a>, <a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)">int</a>]</p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="apache_beam.io.source_test_utils.assert_split_at_fraction_binary">
<span class="sig-prename descclassname"><span class="pre">apache_beam.io.source_test_utils.</span></span><span class="sig-name descname"><span class="pre">assert_split_at_fraction_binary</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">source</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">expected_items</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">num_items_to_read_before_split</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">left_fraction</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">left_result</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">right_fraction</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">right_result</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">stats</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">start_position</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">stop_position</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/io/source_test_utils.html#assert_split_at_fraction_binary"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#apache_beam.io.source_test_utils.assert_split_at_fraction_binary" title="Link to this definition"></a></dt>
<dd><p>Performs dynamic work rebalancing for fractions within a given range.</p>
<p>Asserts that given a start position, a source can be split at every
interesting fraction (halfway between two fractions that differ by at
least one item) and the results are consistent if a split succeeds.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>source</strong> – source to perform dynamic splitting on.</p></li>
<li><p><strong>expected_items</strong> – total set of items expected when reading the source.</p></li>
<li><p><strong>num_items_to_read_before_split</strong> – number of items to read before splitting.</p></li>
<li><p><strong>left_fraction</strong> – left fraction for binary splitting.</p></li>
<li><p><strong>left_result</strong> – result received by splitting at left fraction.</p></li>
<li><p><strong>right_fraction</strong> – right fraction for binary splitting.</p></li>
<li><p><strong>right_result</strong> – result received by splitting at right fraction.</p></li>
<li><p><strong>stats</strong> – a <code class="docutils literal notranslate"><span class="pre">SplitFractionStatistics</span></code> for storing results.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="apache_beam.io.source_test_utils.assert_split_at_fraction_exhaustive">
<span class="sig-prename descclassname"><span class="pre">apache_beam.io.source_test_utils.</span></span><span class="sig-name descname"><span class="pre">assert_split_at_fraction_exhaustive</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">source</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">start_position</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">stop_position</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">perform_multi_threaded_test</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/io/source_test_utils.html#assert_split_at_fraction_exhaustive"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#apache_beam.io.source_test_utils.assert_split_at_fraction_exhaustive" title="Link to this definition"></a></dt>
<dd><p>Performs and tests dynamic work rebalancing exhaustively.</p>
<p>Asserts that for each possible start position, a source can be split at
every interesting fraction (halfway between two fractions that differ by at
least one item) and the results are consistent if a split succeeds.
Verifies multi threaded splitting as well.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>source</strong> (<a class="reference internal" href="apache_beam.io.iobase.html#apache_beam.io.iobase.BoundedSource" title="apache_beam.io.iobase.BoundedSource"><em>BoundedSource</em></a>) – the source to perform
dynamic splitting on.</p></li>
<li><p><strong>perform_multi_threaded_test</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – if <a class="reference external" href="https://docs.python.org/3/library/constants.html#True" title="(in Python v3.13)"><code class="xref py py-data docutils literal notranslate"><span class="pre">True</span></code></a> performs a
multi-threaded test, otherwise this test is skipped.</p></li>
</ul>
</dd>
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#ValueError" title="(in Python v3.13)"><strong>ValueError</strong></a> – if the exhaustive splitting test fails.</p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="apache_beam.io.source_test_utils.assert_split_at_fraction_fails">
<span class="sig-prename descclassname"><span class="pre">apache_beam.io.source_test_utils.</span></span><span class="sig-name descname"><span class="pre">assert_split_at_fraction_fails</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">source</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">num_items_to_read_before_split</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">split_fraction</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/io/source_test_utils.html#assert_split_at_fraction_fails"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#apache_beam.io.source_test_utils.assert_split_at_fraction_fails" title="Link to this definition"></a></dt>
<dd><p>Asserts that dynamic work rebalancing at a given fraction fails.</p>
<p>Asserts that trying to perform dynamic splitting after reading
‘num_items_to_read_before_split’ items from the source fails.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>source</strong> – source to perform dynamic splitting on.</p></li>
<li><p><strong>num_items_to_read_before_split</strong> – number of items to read before splitting.</p></li>
<li><p><strong>split_fraction</strong> – fraction to split at.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="apache_beam.io.source_test_utils.assert_split_at_fraction_succeeds_and_consistent">
<span class="sig-prename descclassname"><span class="pre">apache_beam.io.source_test_utils.</span></span><span class="sig-name descname"><span class="pre">assert_split_at_fraction_succeeds_and_consistent</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">source</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">num_items_to_read_before_split</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">split_fraction</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/io/source_test_utils.html#assert_split_at_fraction_succeeds_and_consistent"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#apache_beam.io.source_test_utils.assert_split_at_fraction_succeeds_and_consistent" title="Link to this definition"></a></dt>
<dd><p>Verifies some consistency properties of dynamic work rebalancing.</p>
<p>Equivalent to the following pseudocode::</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">original_range_tracker</span> <span class="o">=</span> <span class="n">source</span><span class="o">.</span><span class="n">getRangeTracker</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="n">original_reader</span> <span class="o">=</span> <span class="n">source</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="n">original_range_tracker</span><span class="p">)</span>
<span class="n">items_before_split</span> <span class="o">=</span> <span class="n">read</span> <span class="n">N</span> <span class="n">items</span> <span class="kn">from</span><span class="w"> </span><span class="nn">original_reader</span>
<span class="n">suggested_split_position</span> <span class="o">=</span> <span class="n">original_range_tracker</span><span class="o">.</span><span class="n">position_for_fraction</span><span class="p">(</span>
<span class="n">split_fraction</span><span class="p">)</span>
<span class="n">original_stop_position</span> <span class="o">-</span> <span class="n">original_range_tracker</span><span class="o">.</span><span class="n">stop_position</span><span class="p">()</span>
<span class="n">split_result</span> <span class="o">=</span> <span class="n">range_tracker</span><span class="o">.</span><span class="n">try_split</span><span class="p">()</span>
<span class="n">split_position</span><span class="p">,</span> <span class="n">split_fraction</span> <span class="o">=</span> <span class="n">split_result</span>
<span class="n">primary_range_tracker</span> <span class="o">=</span> <span class="n">source</span><span class="o">.</span><span class="n">get_range_tracker</span><span class="p">(</span>
<span class="n">original_range_tracker</span><span class="o">.</span><span class="n">start_position</span><span class="p">(),</span> <span class="n">split_position</span><span class="p">)</span>
<span class="n">residual_range_tracker</span> <span class="o">=</span> <span class="n">source</span><span class="o">.</span><span class="n">get_range_tracker</span><span class="p">(</span><span class="n">split_position</span><span class="p">,</span>
<span class="n">original_stop_position</span><span class="p">)</span>
<span class="k">assert</span> <span class="n">that</span><span class="p">:</span> <span class="n">items</span> <span class="n">when</span> <span class="n">reading</span> <span class="n">source</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="n">primary_range_tracker</span><span class="p">)</span> <span class="o">==</span>
<span class="n">items_before_split</span> <span class="o">+</span> <span class="n">items</span> <span class="kn">from</span><span class="w"> </span><span class="nn">continuing</span> <span class="n">to</span> <span class="n">read</span> <span class="s1">&#39;original_reader&#39;</span>
<span class="k">assert</span> <span class="n">that</span><span class="p">:</span> <span class="n">items</span> <span class="n">when</span> <span class="n">reading</span> <span class="n">source</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="n">original_range_tracker</span><span class="p">)</span> <span class="o">=</span>
<span class="n">items</span> <span class="n">when</span> <span class="n">reading</span> <span class="n">source</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="n">primary_range_tracker</span><span class="p">)</span> <span class="o">+</span> <span class="n">items</span> <span class="n">when</span> <span class="n">reading</span>
<span class="n">source</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="n">residual_range_tracker</span><span class="p">)</span>
</pre></div>
</div>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>source</strong> – source to perform dynamic work rebalancing on.</p></li>
<li><p><strong>num_items_to_read_before_split</strong> – number of items to read before splitting.</p></li>
<li><p><strong>split_fraction</strong> – fraction to split at.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
</section>
</div>
</div>
<footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
<a href="apache_beam.io.snowflake.html" class="btn btn-neutral float-left" title="apache_beam.io.snowflake module" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
<a href="apache_beam.io.textio.html" class="btn btn-neutral float-right" title="apache_beam.io.textio module" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
</div>
<hr/>
<div role="contentinfo">
<p>&#169; Copyright %Y, Apache Beam.</p>
</div>
Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>