| <!DOCTYPE html> |
| <!-- Generated by pkgdown: do not edit by hand --><html lang="en-US"> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| <meta charset="utf-8"> |
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
| <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> |
| <title>Connecting to a Flight server • Arrow R Package</title> |
| <!-- favicons --><link rel="icon" type="image/png" sizes="96x96" href="../favicon-96x96.png"> |
| <link rel="icon" type="”image/svg+xml”" href="../favicon.svg"> |
| <link rel="apple-touch-icon" sizes="180x180" href="../apple-touch-icon.png"> |
| <link rel="icon" sizes="any" href="../favicon.ico"> |
| <link rel="manifest" href="../site.webmanifest"> |
| <script src="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> |
| <link href="../deps/bootstrap-5.3.1/bootstrap.min.css" rel="stylesheet"> |
| <script src="../deps/bootstrap-5.3.1/bootstrap.bundle.min.js"></script><link href="../deps/font-awesome-6.5.2/css/all.min.css" rel="stylesheet"> |
| <link href="../deps/font-awesome-6.5.2/css/v4-shims.min.css" rel="stylesheet"> |
| <script src="../deps/headroom-0.11.0/headroom.min.js"></script><script src="../deps/headroom-0.11.0/jQuery.headroom.min.js"></script><script src="../deps/bootstrap-toc-1.0.1/bootstrap-toc.min.js"></script><script src="../deps/clipboard.js-2.0.11/clipboard.min.js"></script><script src="../deps/search-1.0.0/autocomplete.jquery.min.js"></script><script src="../deps/search-1.0.0/fuse.min.js"></script><script src="../deps/search-1.0.0/mark.min.js"></script><!-- pkgdown --><script src="../pkgdown.js"></script><link href="../extra.css" rel="stylesheet"> |
| <meta property="og:title" content="Connecting to a Flight server"> |
| <meta name="description" content="Learn how to efficiently stream Apache Arrow data objects across a network using Arrow Flight |
| "> |
| <meta property="og:description" content="Learn how to efficiently stream Apache Arrow data objects across a network using Arrow Flight |
| "> |
| <meta property="og:image" content="https://arrow.apache.org/img/arrow-logo_horizontal_black-txt_white-bg.png"> |
| <meta property="og:image:alt" content="Apache Arrow logo, displaying the triple chevron image adjacent to the text"> |
| <!-- Matomo --><script> |
| var _paq = window._paq = window._paq || []; |
| /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ |
| /* We explicitly disable cookie tracking to avoid privacy issues */ |
| _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 --><!-- Kapa AI --><script async src="https://widget.kapa.ai/kapa-widget.bundle.js" data-website-id="9db461d5-ac77-4b3f-a5c5-75efa78339d2" data-project-name="Apache Arrow" data-project-color="#000000" data-project-logo="https://arrow.apache.org/img/arrow-logo_chevrons_white-txt_black-bg.png" data-modal-disclaimer="This is a custom LLM with access to all of [Arrow documentation](https://arrow.apache.org/docs/). If you want an R-specific answer, please mention this in your question." data-consent-required="true" data-user-analytics-cookie-enabled="false" data-consent-screen-disclaimer="By clicking "I agree, let's chat", you consent to the use of the AI assistant in accordance with kapa.ai's [Privacy Policy](https://www.kapa.ai/content/privacy-policy). This service uses reCAPTCHA, which requires your consent to Google's [Privacy Policy](https://policies.google.com/privacy) and [Terms of Service](https://policies.google.com/terms). By proceeding, you explicitly agree to both kapa.ai's and Google's privacy policies."></script><!-- End Kapa AI --> |
| </head> |
| <body> |
| <a href="#main" class="visually-hidden-focusable">Skip to contents</a> |
| |
| |
| <nav class="navbar fixed-top navbar-dark navbar-expand-lg bg-black"><div class="container"> |
| |
| <a class="navbar-brand me-2" href="../index.html">Arrow R Package</a> |
| |
| <span class="version"> |
| <small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">22.0.0.9000</small> |
| </span> |
| |
| |
| <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation"> |
| <span class="navbar-toggler-icon"></span> |
| </button> |
| |
| <div id="navbar" class="collapse navbar-collapse ms-3"> |
| <ul class="navbar-nav me-auto"> |
| <li class="nav-item"><a class="nav-link" href="../articles/arrow.html">Get started</a></li> |
| <li class="nav-item"><a class="nav-link" href="../reference/index.html">Reference</a></li> |
| <li class="active nav-item dropdown"> |
| <button class="nav-link dropdown-toggle" type="button" id="dropdown-articles" data-bs-toggle="dropdown" aria-expanded="false" aria-haspopup="true">Articles</button> |
| <ul class="dropdown-menu" aria-labelledby="dropdown-articles"> |
| <li><hr class="dropdown-divider"></li> |
| <li><h6 class="dropdown-header" data-toc-skip>Using the package</h6></li> |
| <li><a class="dropdown-item" href="../articles/read_write.html">Reading and writing data files</a></li> |
| <li><a class="dropdown-item" href="../articles/data_wrangling.html">Data analysis with dplyr syntax</a></li> |
| <li><a class="dropdown-item" href="../articles/dataset.html">Working with multi-file data sets</a></li> |
| <li><a class="dropdown-item" href="../articles/python.html">Integrating Arrow, Python, and R</a></li> |
| <li><a class="dropdown-item" href="../articles/fs.html">Using cloud storage (S3, GCS)</a></li> |
| <li><a class="dropdown-item" href="../articles/flight.html">Connecting to a Flight server</a></li> |
| <li><hr class="dropdown-divider"></li> |
| <li><h6 class="dropdown-header" data-toc-skip>Arrow concepts</h6></li> |
| <li><a class="dropdown-item" href="../articles/data_objects.html">Data objects</a></li> |
| <li><a class="dropdown-item" href="../articles/data_types.html">Data types</a></li> |
| <li><a class="dropdown-item" href="../articles/metadata.html">Metadata</a></li> |
| <li><hr class="dropdown-divider"></li> |
| <li><h6 class="dropdown-header" data-toc-skip>Installation</h6></li> |
| <li><a class="dropdown-item" href="../articles/install.html">Installing on Linux</a></li> |
| <li><a class="dropdown-item" href="../articles/install_nightly.html">Installing development versions</a></li> |
| <li><hr class="dropdown-divider"></li> |
| <li><a class="dropdown-item" href="../articles/index.html">More articles...</a></li> |
| </ul> |
| </li> |
| <li class="nav-item"><a class="nav-link" href="../news/index.html">Changelog</a></li> |
| </ul> |
| <form class="form-inline my-2 my-lg-0" role="search"> |
| <input type="search" class="form-control me-sm-2" aria-label="Toggle navigation" name="search-input" data-search-index="../search.json" id="search-input" placeholder="" autocomplete="off"> |
| </form> |
| |
| <ul class="navbar-nav"> |
| <li class="nav-item"><a class="external-link nav-link" href="https://github.com/apache/arrow/" aria-label="GitHub"><span class="fa fab fa-github fa-lg"></span></a></li> |
| </ul> |
| </div> |
| |
| |
| </div> |
| </nav><div class="container template-article"> |
| |
| |
| |
| |
| <div class="row"> |
| <main id="main" class="col-md-9"><div class="page-header"> |
| |
| <h1>Connecting to a Flight server</h1> |
| |
| |
| <small class="dont-index">Source: <a href="https://github.com/apache/arrow/blob/main/r/vignettes/flight.Rmd" class="external-link"><code>vignettes/flight.Rmd</code></a></small> |
| <div class="d-none name"><code>flight.Rmd</code></div> |
| </div> |
| |
| |
| |
| <p><a href="https://arrow.apache.org/blog/2019/10/13/introducing-arrow-flight/" class="external-link">Arrow |
| Flight</a> is a general-purpose client-server framework for high |
| performance transport of large datasets over network interfaces, built |
| as part of the Apache Arrow project. It allows for highly efficient data |
| transfer by several means:</p> |
| <ul> |
| <li>Flight removes the need for deserialization during data |
| transfer.</li> |
| <li>Flight allows for parallel data streaming.</li> |
| <li>Flight employs optimizations designed to take advantage of Arrow’s |
| columnar format.</li> |
| </ul> |
| <p>The arrow package provides methods for connecting to Flight servers |
| to send and receive data.</p> |
| <div class="section level2"> |
| <h2 id="prerequisites">Prerequisites<a class="anchor" aria-label="anchor" href="#prerequisites"></a> |
| </h2> |
| <p>At present the arrow package in R does not supply an independent |
| implementation of Arrow Flight: it works by calling <a href="https://arrow.apache.org/docs/python/api/flight.html" class="external-link">Flight |
| methods supplied by PyArrow</a> Python, and requires both the <a href="https://rstudio.github.io/reticulate/" class="external-link">reticulate</a> package and |
| the Python PyArrow library to be installed. If you are using them for |
| the first time you can install them like this:</p> |
| <div class="sourceCode" id="cb1"><pre class="downlit sourceCode r"> |
| <code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/r/utils/install.packages.html" class="external-link">install.packages</a></span><span class="op">(</span><span class="st">"reticulate"</span><span class="op">)</span></span> |
| <span><span class="fu">arrow</span><span class="fu">::</span><span class="fu"><a href="../reference/install_pyarrow.html">install_pyarrow</a></span><span class="op">(</span><span class="op">)</span></span></code></pre></div> |
| <p>See the <a href="./python.html">python integrations article</a> for |
| more details on setting up pyarrow.</p> |
| </div> |
| <div class="section level2"> |
| <h2 id="example">Example<a class="anchor" aria-label="anchor" href="#example"></a> |
| </h2> |
| <p>The package includes methods for starting a Python-based Flight |
| server, as well as methods for connecting to a Flight server running |
| elsewhere. To illustrate both sides, in one R process we’ll start a demo |
| server:</p> |
| <div class="sourceCode" id="cb2"><pre class="downlit sourceCode r"> |
| <code class="sourceCode R"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/apache/arrow/" class="external-link">arrow</a></span><span class="op">)</span></span> |
| <span><span class="va">demo_server</span> <span class="op"><-</span> <span class="fu"><a href="../reference/load_flight_server.html">load_flight_server</a></span><span class="op">(</span><span class="st">"demo_flight_server"</span><span class="op">)</span></span> |
| <span><span class="va">server</span> <span class="op"><-</span> <span class="va">demo_server</span><span class="op">$</span><span class="fu">DemoFlightServer</span><span class="op">(</span>port <span class="op">=</span> <span class="fl">8089</span><span class="op">)</span></span> |
| <span><span class="va">server</span><span class="op">$</span><span class="fu">serve</span><span class="op">(</span><span class="op">)</span></span></code></pre></div> |
| <p>We’ll leave that one running.</p> |
| <p>In a different R process, let’s connect to it and put some data in |
| it.</p> |
| <div class="sourceCode" id="cb3"><pre class="downlit sourceCode r"> |
| <code class="sourceCode R"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/apache/arrow/" class="external-link">arrow</a></span><span class="op">)</span></span> |
| <span><span class="va">client</span> <span class="op"><-</span> <span class="fu"><a href="../reference/flight_connect.html">flight_connect</a></span><span class="op">(</span>port <span class="op">=</span> <span class="fl">8089</span><span class="op">)</span></span> |
| <span><span class="fu"><a href="../reference/flight_put.html">flight_put</a></span><span class="op">(</span><span class="va">client</span>, <span class="va">iris</span>, path <span class="op">=</span> <span class="st">"test_data/iris"</span><span class="op">)</span></span></code></pre></div> |
| <p>Now, in yet another R process, we can connect to the server and pull |
| the data we put there:</p> |
| <div class="sourceCode" id="cb4"><pre class="downlit sourceCode r"> |
| <code class="sourceCode R"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/apache/arrow/" class="external-link">arrow</a></span><span class="op">)</span></span> |
| <span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://dplyr.tidyverse.org" class="external-link">dplyr</a></span><span class="op">)</span></span> |
| <span><span class="va">client</span> <span class="op"><-</span> <span class="fu"><a href="../reference/flight_connect.html">flight_connect</a></span><span class="op">(</span>port <span class="op">=</span> <span class="fl">8089</span><span class="op">)</span></span> |
| <span><span class="va">client</span> <span class="op">|></span></span> |
| <span> <span class="fu"><a href="../reference/flight_get.html">flight_get</a></span><span class="op">(</span><span class="st">"test_data/iris"</span><span class="op">)</span> <span class="op">|></span></span> |
| <span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html" class="external-link">group_by</a></span><span class="op">(</span><span class="va">Species</span><span class="op">)</span> <span class="op">|></span></span> |
| <span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/summarise.html" class="external-link">summarize</a></span><span class="op">(</span>max_petal <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/Extremes.html" class="external-link">max</a></span><span class="op">(</span><span class="va">Petal.Length</span><span class="op">)</span><span class="op">)</span></span> |
| <span></span> |
| <span><span class="co">## # A tibble: 3 x 2</span></span> |
| <span><span class="co">## Species max_petal</span></span> |
| <span><span class="co">## <fct> <dbl></span></span> |
| <span><span class="co">## 1 setosa 1.9</span></span> |
| <span><span class="co">## 2 versicolor 5.1</span></span> |
| <span><span class="co">## 3 virginica 6.9</span></span></code></pre></div> |
| <p>Because <code><a href="../reference/flight_get.html">flight_get()</a></code> returns an Arrow data structure, |
| you can directly pipe its result into a <a href="https://dplyr.tidyverse.org/" class="external-link">dplyr</a> workflow. See the article |
| on <a href="./data_wrangling.html">data wrangling</a> for more |
| information on working with Arrow objects via a dplyr interface.</p> |
| </div> |
| <div class="section level2"> |
| <h2 id="further-reading">Further reading<a class="anchor" aria-label="anchor" href="#further-reading"></a> |
| </h2> |
| <ul> |
| <li>The specification of the <a href="https://arrow.apache.org/docs/format/Flight.html" class="external-link">Flight remote |
| procedure call protocol</a> is listed on the Arrow project homepage</li> |
| <li>The Arrow C++ documentation contains a list of <a href="https://arrow.apache.org/docs/cpp/flight.html#best-practices" class="external-link">best |
| practices</a> for Arrow Flight.</li> |
| <li>A detailed worked example of an Arrow Flight server in Python is |
| provided in the <a href="https://arrow.apache.org/cookbook/py/flight.html" class="external-link">Apache Arrow |
| Python Cookbook</a>.</li> |
| </ul> |
| </div> |
| </main><aside class="col-md-3"><nav id="toc" aria-label="Table of contents"><h2>On this page</h2> |
| </nav></aside> |
| </div> |
| |
| |
| |
| <footer><div class="pkgdown-footer-left"> |
| <p><a href="https://arrow.apache.org/docs/r/versions.html">Older versions of these docs</a></p> |
| </div> |
| |
| <div class="pkgdown-footer-right"> |
| <p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.2.0.</p> |
| </div> |
| |
| </footer> |
| </div> |
| |
| |
| |
| |
| |
| </body> |
| </html> |