| |
| |
| |
| <!DOCTYPE html> |
| <html class="writer-html5" lang="en" > |
| <head> |
| <meta charset="utf-8" /> |
| |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| |
| <title>The Arrow C stream interface — Apache Arrow v3.0.0</title> |
| |
| |
| |
| <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" /> |
| <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> |
| <link rel="stylesheet" href="../_static/theme_overrides.css" type="text/css" /> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <!--[if lt IE 9]> |
| <script src="../_static/js/html5shiv.min.js"></script> |
| <![endif]--> |
| |
| |
| <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script> |
| <script src="../_static/jquery.js"></script> |
| <script src="../_static/underscore.js"></script> |
| <script src="../_static/doctools.js"></script> |
| <script src="../_static/language_data.js"></script> |
| |
| <script type="text/javascript" src="../_static/js/theme.js"></script> |
| |
| |
| <link rel="canonical" href="https://arrow.apache.org/docs/format/CStreamInterface.html" /> |
| <link rel="index" title="Index" href="../genindex.html" /> |
| <link rel="search" title="Search" href="../search.html" /> |
| <link rel="next" title="Other Data Structures" href="Other.html" /> |
| <link rel="prev" title="The Arrow C data interface" href="CDataInterface.html" /> |
|
|
|
|
| <!-- Matomo -->
|
| <script>
|
| var _paq = window._paq = window._paq || [];
|
| /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
|
| _paq.push(["setDoNotTrack", true]);
|
| _paq.push(["disableCookies"]);
|
| _paq.push(['trackPageView']);
|
| _paq.push(['enableLinkTracking']);
|
| (function() {
|
| var u="https://analytics.apache.org/";
|
| _paq.push(['setTrackerUrl', u+'matomo.php']);
|
| _paq.push(['setSiteId', '20']);
|
| var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
|
| g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
|
| })();
|
| </script>
|
| <!-- End Matomo Code -->
|
|
|
| </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 Arrow |
| |
| |
| |
| </a> |
| |
| |
| |
| |
| <div class="version"> |
| 3.0.0 |
| </div> |
| |
| |
| |
| |
| <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"> |
| |
| |
| |
| |
| |
| |
| <p class="caption"><span class="caption-text">Specifications and Protocols</span></p> |
| <ul class="current"> |
| <li class="toctree-l1"><a class="reference internal" href="Versioning.html">Format Versioning and Stability</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="Columnar.html">Arrow Columnar Format</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="Flight.html">Arrow Flight RPC</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="Integration.html">Integration Testing</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="CDataInterface.html">The Arrow C data interface</a></li> |
| <li class="toctree-l1 current"><a class="current reference internal" href="#">The Arrow C stream interface</a><ul> |
| <li class="toctree-l2"><a class="reference internal" href="#semantics">Semantics</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="#structure-definition">Structure definition</a><ul> |
| <li class="toctree-l3"><a class="reference internal" href="#the-arrowarraystream-structure">The ArrowArrayStream structure</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="#error-codes">Error codes</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="#result-lifetimes">Result lifetimes</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="#stream-lifetime">Stream lifetime</a></li> |
| </ul> |
| </li> |
| <li class="toctree-l2"><a class="reference internal" href="#c-consumer-example">C consumer example</a></li> |
| </ul> |
| </li> |
| <li class="toctree-l1"><a class="reference internal" href="Other.html">Other Data Structures</a></li> |
| </ul> |
| <p class="caption"><span class="caption-text">Libraries</span></p> |
| <ul> |
| <li class="toctree-l1"><a class="reference internal" href="../status.html">Implementation Status</a></li> |
| <li class="toctree-l1"><a class="reference external" href="https://arrow.apache.org/docs/c_glib/">C/GLib</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../cpp/index.html">C++</a></li> |
| <li class="toctree-l1"><a class="reference external" href="https://github.com/apache/arrow/blob/master/csharp/README.md">C#</a></li> |
| <li class="toctree-l1"><a class="reference external" href="https://godoc.org/github.com/apache/arrow/go/arrow">Go</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../java/index.html">Java</a></li> |
| <li class="toctree-l1"><a class="reference external" href="https://arrow.apache.org/docs/js/">JavaScript</a></li> |
| <li class="toctree-l1"><a class="reference external" href="https://github.com/apache/arrow/blob/master/julia/Arrow/README.md">Julia</a></li> |
| <li class="toctree-l1"><a class="reference external" href="https://github.com/apache/arrow/blob/master/matlab/README.md">MATLAB</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../python/index.html">Python</a></li> |
| <li class="toctree-l1"><a class="reference external" href="https://arrow.apache.org/docs/r/">R</a></li> |
| <li class="toctree-l1"><a class="reference external" href="https://github.com/apache/arrow/blob/master/ruby/README.md">Ruby</a></li> |
| <li class="toctree-l1"><a class="reference external" href="https://docs.rs/crate/arrow/">Rust</a></li> |
| </ul> |
| <p class="caption"><span class="caption-text">Development</span></p> |
| <ul> |
| <li class="toctree-l1"><a class="reference internal" href="../developers/contributing.html">Contributing to Apache Arrow</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../developers/cpp/index.html">C++ Development</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../developers/python.html">Python Development</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../developers/archery.html">Daily Development using Archery</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../developers/crossbow.html">Packaging and Testing with Crossbow</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../developers/docker.html">Running Docker Builds</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../developers/benchmarks.html">Benchmarks</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../developers/documentation.html">Building the Documentation</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 Arrow</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" class="icon icon-home"></a> »</li> |
| |
| <li>The Arrow C stream interface</li> |
| |
| |
| <li class="wy-breadcrumbs-aside"> |
| |
| |
| <a href="../_sources/format/CStreamInterface.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="the-arrow-c-stream-interface"> |
| <span id="c-stream-interface"></span><h1>The Arrow C stream interface<a class="headerlink" href="#the-arrow-c-stream-interface" title="Permalink to this headline">¶</a></h1> |
| <div class="admonition warning"> |
| <p class="admonition-title">Warning</p> |
| <p>This interface is experimental and may evolve based on feedback from |
| early users. ABI stability is not guaranteed yet. Feel free to |
| <a class="reference external" href="https://arrow.apache.org/community/">contact us</a>.</p> |
| </div> |
| <p>The C stream interface builds on the structures defined in the |
| <a class="reference internal" href="CDataInterface.html#c-data-interface"><span class="std std-ref">C data interface</span></a> and combines them into a higher-level |
| specification so as to ease the communication of streaming data within a single |
| process.</p> |
| <div class="section" id="semantics"> |
| <h2>Semantics<a class="headerlink" href="#semantics" title="Permalink to this headline">¶</a></h2> |
| <p>An Arrow C stream exposes a streaming source of data chunks, each with the |
| same schema. Chunks are obtained by calling a blocking pull-style iteration |
| function.</p> |
| </div> |
| <div class="section" id="structure-definition"> |
| <h2>Structure definition<a class="headerlink" href="#structure-definition" title="Permalink to this headline">¶</a></h2> |
| <p>The C stream interface is defined by a single <code class="docutils literal notranslate"><span class="pre">struct</span></code> definition:</p> |
| <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="k">struct</span> <span class="n">ArrowArrayStream</span> <span class="p">{</span> |
| <span class="c1">// Callbacks providing stream functionality</span> |
| <span class="kt">int</span> <span class="p">(</span><span class="o">*</span><span class="n">get_schema</span><span class="p">)(</span><span class="k">struct</span> <span class="n">ArrowArrayStream</span><span class="o">*</span><span class="p">,</span> <span class="k">struct</span> <span class="n">ArrowSchema</span><span class="o">*</span> <span class="n">out</span><span class="p">);</span> |
| <span class="kt">int</span> <span class="p">(</span><span class="o">*</span><span class="n">get_next</span><span class="p">)(</span><span class="k">struct</span> <span class="n">ArrowArrayStream</span><span class="o">*</span><span class="p">,</span> <span class="k">struct</span> <span class="n">ArrowArray</span><span class="o">*</span> <span class="n">out</span><span class="p">);</span> |
| <span class="k">const</span> <span class="kt">char</span><span class="o">*</span> <span class="p">(</span><span class="o">*</span><span class="n">get_last_error</span><span class="p">)(</span><span class="k">struct</span> <span class="n">ArrowArrayStream</span><span class="o">*</span><span class="p">);</span> |
| |
| <span class="c1">// Release callback</span> |
| <span class="kt">void</span> <span class="p">(</span><span class="o">*</span><span class="n">release</span><span class="p">)(</span><span class="k">struct</span> <span class="n">ArrowArrayStream</span><span class="o">*</span><span class="p">);</span> |
| |
| <span class="c1">// Opaque producer-specific data</span> |
| <span class="kt">void</span><span class="o">*</span> <span class="n">private_data</span><span class="p">;</span> |
| <span class="p">};</span> |
| </pre></div> |
| </div> |
| <div class="section" id="the-arrowarraystream-structure"> |
| <h3>The ArrowArrayStream structure<a class="headerlink" href="#the-arrowarraystream-structure" title="Permalink to this headline">¶</a></h3> |
| <p>The <code class="docutils literal notranslate"><span class="pre">ArrowArrayStream</span></code> provides the required callbacks to interact with a |
| streaming source of Arrow arrays. It has the following fields:</p> |
| <dl class="c member"> |
| <dt id="c.ArrowArrayStream.get_schema"> |
| int (*<code class="sig-prename descclassname">ArrowArrayStream<code class="sig-prename descclassname">.</code></code><code class="sig-name descname">get_schema</code>)<span class="sig-paren">(</span><em class="property">struct</em> ArrowArrayStream*, <em class="property">struct</em> ArrowSchema *out<span class="sig-paren">)</span><a class="headerlink" href="#c.ArrowArrayStream.get_schema" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p><em>Mandatory.</em> This callback allows the consumer to query the schema of |
| the chunks of data in the stream. The schema is the same for all |
| data chunks.</p> |
| <p>This callback must NOT be called on a released <code class="docutils literal notranslate"><span class="pre">ArrowArrayStream</span></code>.</p> |
| <p><em>Return value:</em> 0 on success, a non-zero |
| <a class="reference internal" href="#c-stream-interface-error-codes"><span class="std std-ref">error code</span></a> otherwise.</p> |
| </dd></dl> |
| |
| <dl class="c member"> |
| <dt id="c.ArrowArrayStream.get_next"> |
| int (*<code class="sig-prename descclassname">ArrowArrayStream<code class="sig-prename descclassname">.</code></code><code class="sig-name descname">get_next</code>)<span class="sig-paren">(</span><em class="property">struct</em> ArrowArrayStream*, <em class="property">struct</em> ArrowArray *out<span class="sig-paren">)</span><a class="headerlink" href="#c.ArrowArrayStream.get_next" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p><em>Mandatory.</em> This callback allows the consumer to get the next chunk |
| of data in the stream.</p> |
| <p>This callback must NOT be called on a released <code class="docutils literal notranslate"><span class="pre">ArrowArrayStream</span></code>.</p> |
| <p><em>Return value:</em> 0 on success, a non-zero |
| <a class="reference internal" href="#c-stream-interface-error-codes"><span class="std std-ref">error code</span></a> otherwise.</p> |
| <p>On success, the consumer must check whether the <code class="docutils literal notranslate"><span class="pre">ArrowArray</span></code> is |
| marked <a class="reference internal" href="CDataInterface.html#c-data-interface-released"><span class="std std-ref">released</span></a>. If the |
| <code class="docutils literal notranslate"><span class="pre">ArrowArray</span></code> is released, then the end of stream has been reached. |
| Otherwise, the <code class="docutils literal notranslate"><span class="pre">ArrowArray</span></code> contains a valid data chunk.</p> |
| </dd></dl> |
| |
| <dl class="c member"> |
| <dt id="c.ArrowArrayStream.get_last_error"> |
| <em class="property">const</em> char *(*<code class="sig-prename descclassname">ArrowArrayStream<code class="sig-prename descclassname">.</code></code><code class="sig-name descname">get_last_error</code>)<span class="sig-paren">(</span><em class="property">struct</em> ArrowArrayStream*<span class="sig-paren">)</span><a class="headerlink" href="#c.ArrowArrayStream.get_last_error" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p><em>Mandatory.</em> This callback allows the consumer to get a textual description |
| of the last error.</p> |
| <p>This callback must ONLY be called if the last operation on the |
| <code class="docutils literal notranslate"><span class="pre">ArrowArrayStream</span></code> returned an error. It must NOT be called on a |
| released <code class="docutils literal notranslate"><span class="pre">ArrowArrayStream</span></code>.</p> |
| <p><em>Return value:</em> a pointer to a NULL-terminated character string (UTF8-encoded). |
| NULL can also be returned if no detailed description is available.</p> |
| <p>The returned pointer is only guaranteed to be valid until the next call of |
| one of the stream’s callbacks. The character string it points to should |
| be copied to consumer-managed storage if it is intended to survive longer.</p> |
| </dd></dl> |
| |
| <dl class="c member"> |
| <dt id="c.ArrowArrayStream.release"> |
| void (*<code class="sig-prename descclassname">ArrowArrayStream<code class="sig-prename descclassname">.</code></code><code class="sig-name descname">release</code>)<span class="sig-paren">(</span><em class="property">struct</em> ArrowArrayStream*<span class="sig-paren">)</span><a class="headerlink" href="#c.ArrowArrayStream.release" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p><em>Mandatory.</em> A pointer to a producer-provided release callback.</p> |
| </dd></dl> |
| |
| <dl class="c member"> |
| <dt id="c.ArrowArrayStream.private_data"> |
| void *<code class="sig-prename descclassname">ArrowArrayStream<code class="sig-prename descclassname">.</code></code><code class="sig-name descname">private_data</code><a class="headerlink" href="#c.ArrowArrayStream.private_data" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p><em>Optional.</em> An opaque pointer to producer-provided private data.</p> |
| <p>Consumers MUST not process this member. Lifetime of this member |
| is handled by the producer, and especially by the release callback.</p> |
| </dd></dl> |
| |
| </div> |
| <div class="section" id="error-codes"> |
| <span id="c-stream-interface-error-codes"></span><h3>Error codes<a class="headerlink" href="#error-codes" title="Permalink to this headline">¶</a></h3> |
| <p>The <code class="docutils literal notranslate"><span class="pre">get_schema</span></code> and <code class="docutils literal notranslate"><span class="pre">get_next</span></code> callbacks may return an error under the form |
| of a non-zero integer code. Such error codes should be interpreted like |
| <code class="docutils literal notranslate"><span class="pre">errno</span></code> numbers (as defined by the local platform). Note that the symbolic |
| forms of these constants are stable from platform to platform, but their numeric |
| values are platform-specific.</p> |
| <p>In particular, it is recommended to recognize the following values:</p> |
| <ul class="simple"> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EINVAL</span></code>: for a parameter or input validation error</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">ENOMEM</span></code>: for a memory allocation failure (out of memory)</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EIO</span></code>: for a generic input/output error</p></li> |
| </ul> |
| <div class="admonition seealso"> |
| <p class="admonition-title">See also</p> |
| <p><a class="reference external" href="https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html">Standard POSIX error codes</a>.</p> |
| <p><a class="reference external" href="https://docs.microsoft.com/en-us/cpp/c-runtime-library/errno-doserrno-sys-errlist-and-sys-nerr">Error codes recognized by the Windows C runtime library</a>.</p> |
| </div> |
| </div> |
| <div class="section" id="result-lifetimes"> |
| <h3>Result lifetimes<a class="headerlink" href="#result-lifetimes" title="Permalink to this headline">¶</a></h3> |
| <p>The data returned by the <code class="docutils literal notranslate"><span class="pre">get_schema</span></code> and <code class="docutils literal notranslate"><span class="pre">get_next</span></code> callbacks must be |
| released independently. Their lifetimes are not tied to that of the |
| <code class="docutils literal notranslate"><span class="pre">ArrowArrayStream</span></code>.</p> |
| </div> |
| <div class="section" id="stream-lifetime"> |
| <h3>Stream lifetime<a class="headerlink" href="#stream-lifetime" title="Permalink to this headline">¶</a></h3> |
| <p>Lifetime of the C stream is managed using a release callback with similar |
| usage as in the <a class="reference internal" href="CDataInterface.html#c-data-interface-released"><span class="std std-ref">C data interface</span></a>.</p> |
| </div> |
| </div> |
| <div class="section" id="c-consumer-example"> |
| <h2>C consumer example<a class="headerlink" href="#c-consumer-example" title="Permalink to this headline">¶</a></h2> |
| <p>Let’s say a particular database provides the following C API to execute |
| a SQL query and return the result set as a Arrow C stream:</p> |
| <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="kt">void</span> <span class="nf">MyDB_Query</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span><span class="o">*</span> <span class="n">query</span><span class="p">,</span> <span class="k">struct</span> <span class="n">ArrowArrayStream</span><span class="o">*</span> <span class="n">result_set</span><span class="p">);</span> |
| </pre></div> |
| </div> |
| <p>Then a consumer could use the following code to iterate over the results:</p> |
| <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="k">static</span> <span class="kt">void</span> <span class="nf">handle_error</span><span class="p">(</span><span class="kt">int</span> <span class="n">errcode</span><span class="p">,</span> <span class="k">struct</span> <span class="n">ArrowArrayStream</span><span class="o">*</span> <span class="n">stream</span><span class="p">)</span> <span class="p">{</span> |
| <span class="c1">// Print stream error</span> |
| <span class="k">const</span> <span class="kt">char</span><span class="o">*</span> <span class="n">errdesc</span> <span class="o">=</span> <span class="n">stream</span><span class="o">-></span><span class="n">get_last_error</span><span class="p">(</span><span class="n">stream</span><span class="p">);</span> |
| <span class="k">if</span> <span class="p">(</span><span class="n">errdesc</span> <span class="o">!=</span> <span class="nb">NULL</span><span class="p">)</span> <span class="p">{</span> |
| <span class="n">fputs</span><span class="p">(</span><span class="n">errdesc</span><span class="p">,</span> <span class="n">stderr</span><span class="p">);</span> |
| <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> |
| <span class="n">fputs</span><span class="p">(</span><span class="n">strerror</span><span class="p">(</span><span class="n">errcode</span><span class="p">),</span> <span class="n">stderr</span><span class="p">);</span> |
| <span class="p">}</span> |
| <span class="c1">// Release stream and abort</span> |
| <span class="n">stream</span><span class="o">-></span><span class="n">release</span><span class="p">(</span><span class="n">stream</span><span class="p">),</span> |
| <span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span> |
| <span class="p">}</span> |
| |
| <span class="kt">void</span> <span class="nf">run_query</span><span class="p">()</span> <span class="p">{</span> |
| <span class="k">struct</span> <span class="n">ArrowArrayStream</span> <span class="n">stream</span><span class="p">;</span> |
| <span class="k">struct</span> <span class="n">ArrowSchema</span> <span class="n">schema</span><span class="p">;</span> |
| <span class="k">struct</span> <span class="n">ArrowArray</span> <span class="n">chunk</span><span class="p">;</span> |
| <span class="kt">int</span> <span class="n">errcode</span><span class="p">;</span> |
| |
| <span class="n">MyDB_Query</span><span class="p">(</span><span class="s">"SELECT * FROM my_table"</span><span class="p">,</span> <span class="o">&</span><span class="n">stream</span><span class="p">);</span> |
| |
| <span class="c1">// Query result set schema</span> |
| <span class="n">errcode</span> <span class="o">=</span> <span class="n">stream</span><span class="p">.</span><span class="n">get_schema</span><span class="p">(</span><span class="o">&</span><span class="n">stream</span><span class="p">,</span> <span class="o">&</span><span class="n">schema</span><span class="p">);</span> |
| <span class="k">if</span> <span class="p">(</span><span class="n">errcode</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span> |
| <span class="n">handle_error</span><span class="p">(</span><span class="n">errcode</span><span class="p">,</span> <span class="o">&</span><span class="n">stream</span><span class="p">);</span> |
| <span class="p">}</span> |
| |
| <span class="kt">int64_t</span> <span class="n">num_rows</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> |
| |
| <span class="c1">// Iterate over results: loop until error or end of stream</span> |
| <span class="k">while</span> <span class="p">((</span><span class="n">errcode</span> <span class="o">=</span> <span class="n">stream</span><span class="p">.</span><span class="n">get_next</span><span class="p">(</span><span class="o">&</span><span class="n">stream</span><span class="p">,</span> <span class="o">&</span><span class="n">chunk</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="o">&&</span> |
| <span class="n">chunk</span><span class="p">.</span><span class="n">release</span> <span class="o">!=</span> <span class="nb">NULL</span><span class="p">)</span> <span class="p">{</span> |
| <span class="c1">// Do something with chunk...</span> |
| <span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">"Result chunk: got %lld rows</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">chunk</span><span class="p">.</span><span class="n">length</span><span class="p">);</span> |
| <span class="n">num_rows</span> <span class="o">+=</span> <span class="n">chunk</span><span class="p">.</span><span class="n">length</span><span class="p">;</span> |
| |
| <span class="c1">// Release chunk</span> |
| <span class="n">chunk</span><span class="p">.</span><span class="n">release</span><span class="p">(</span><span class="o">&</span><span class="n">chunk</span><span class="p">);</span> |
| <span class="p">}</span> |
| |
| <span class="c1">// Was it an error?</span> |
| <span class="k">if</span> <span class="p">(</span><span class="n">errcode</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span> |
| <span class="n">handle_error</span><span class="p">(</span><span class="n">errcode</span><span class="p">,</span> <span class="o">&</span><span class="n">stream</span><span class="p">);</span> |
| <span class="p">}</span> |
| |
| <span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">"Result stream ended: total %lld rows</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">num_rows</span><span class="p">);</span> |
| |
| <span class="c1">// Release schema and stream</span> |
| <span class="n">schema</span><span class="p">.</span><span class="n">release</span><span class="p">(</span><span class="o">&</span><span class="n">schema</span><span class="p">);</span> |
| <span class="n">stream</span><span class="p">.</span><span class="n">release</span><span class="p">(</span><span class="o">&</span><span class="n">stream</span><span class="p">);</span> |
| <span class="p">}</span> |
| </pre></div> |
| </div> |
| </div> |
| </div> |
| |
| |
| </div> |
| |
| </div> |
| <footer> |
| <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> |
| <a href="Other.html" class="btn btn-neutral float-right" title="Other Data Structures" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a> |
| <a href="CDataInterface.html" class="btn btn-neutral float-left" title="The Arrow C data interface" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a> |
| </div> |
| |
| <hr/> |
| |
| <div role="contentinfo"> |
| <p> |
| © Copyright 2016-2019 Apache Software Foundation. |
| |
| </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 type="text/javascript"> |
| jQuery(function () { |
| SphinxRtdTheme.Navigation.enable(true); |
| }); |
| </script> |
| |
| |
| |
| |
| |
| |
| |
| <script type="text/javascript" src="/docs/_static/versionwarning.js"></script></body> |
| </html> |