| <!--- |
| Licensed to the Apache Software Foundation (ASF) under one |
| or more contributor license agreements. See the NOTICE file |
| distributed with this work for additional information |
| regarding copyright ownership. The ASF licenses this file |
| to you under the Apache License, Version 2.0 (the |
| "License"); you may not use this file except in compliance |
| with the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, |
| software distributed under the License is distributed on an |
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| KIND, either express or implied. See the License for the |
| specific language governing permissions and limitations |
| under the License. |
| --> |
| |
| # Flight |
| |
| ## Introduction |
| |
| Flight 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. |
| |
| Flight allows for highly efficient data transfer as it: |
| |
| * removes the need for serialization during data transfer |
| * allows for parallel data streaming |
| * is highly optimized to take advantage of Arrow’s columnar format. |
| |
| The arrow package provides methods for connecting to Flight RPC servers to send |
| and receive data. |
| |
| It should be noted that the Flight implementation in the R package depends on |
| [PyArrow](https://arrow.apache.org/docs/python/) which is called via |
| [reticulate](https://rstudio.github.io/reticulate/). This is quite different |
| from the other capabilities in the R package, nearly all of which are all |
| implemented directly. |
| |
| ## Connect to a Flight server |
| |
| You want to connect to a Flight server running on a specified host and port. |
| |
| ### Solution |
| |
| ```{r, eval = FALSE} |
| local_client <- flight_connect(host = "127.0.0.1", port = 8089) |
| ``` |
| |
| ### See also |
| |
| For an example of how to set up a Flight server from R, see |
| [the Flight vignette](https://arrow.apache.org/docs/r/articles/flight.html). |
| |
| ## Send data to a Flight server |
| |
| You want to send data that you have in memory to a Flight server |
| |
| ### Solution |
| |
| ```{r, eval = FALSE} |
| # Connect to the Flight server |
| local_client <- flight_connect(host = "127.0.0.1", port = 8089) |
| |
| # Send the data |
| flight_put( |
| local_client, |
| data = airquality, |
| path = "pollution_data" |
| ) |
| ``` |
| |
| ## Check what resources exist on a Flight server |
| |
| You want to see what paths are available on a Flight server. |
| |
| ### Solution |
| |
| ```{r, eval = FALSE} |
| # Connect to the Flight server |
| local_client <- flight_connect(host = "127.0.0.1", port = 8089) |
| |
| # Retrieve path listing |
| list_flights(local_client) |
| ``` |
| |
| ```{r} |
| # [1] "pollution_data" |
| ``` |
| |
| |
| ## Retrieve data from a Flight server |
| |
| You want to retrieve data on a Flight server from a specified path. |
| |
| ### Solution |
| |
| ```{r, eval = FALSE} |
| # Connect to the Flight server |
| local_client <- flight_connect(host = "127.0.0.1", port = 8089) |
| |
| # Retrieve data |
| flight_get( |
| local_client, |
| "pollution_data" |
| ) |
| ``` |
| |
| ```{r, eval = FALSE} |
| # Table |
| # 153 rows x 6 columns |
| # $Ozone <int32> |
| # $Solar.R <int32> |
| # $Wind <double> |
| # $Temp <int32> |
| # $Month <int32> |
| # $Day <int32> |
| # |
| # See $metadata for additional Schema metadata |
| ``` |