9 Flight

9.1 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 which is called via reticulate. This is quite different from the other capabilities in the R package, nearly all of which are all implemented directly.

9.2 Connect to a Flight server

You want to connect to a Flight server running on a specified host and port.

9.2.1 Solution

local_client <- flight_connect(host = "127.0.0.1", port = 8089)

9.2.2 See also

For an example of how to set up a Flight server from R, see the Flight vignette.

9.3 Send data to a Flight server

You want to send data that you have in memory to a Flight server

9.3.1 Solution

# 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"
)

9.4 Check what resources exist on a Flight server

You want to see what paths are available on a Flight server.

9.4.1 Solution

# Connect to the Flight server
local_client <- flight_connect(host = "127.0.0.1", port = 8089)

# Retrieve path listing
list_flights(local_client)
# [1] "pollution_data"

9.5 Retrieve data from a Flight server

You want to retrieve data on a Flight server from a specified path.

9.5.1 Solution

# Connect to the Flight server
local_client <- flight_connect(host = "127.0.0.1", port = 8089)

# Retrieve data
flight_get(
  local_client,
  "pollution_data"
)
# 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