pub struct FlightClient { /* private fields */ }
Expand description

A “Mid level” Apache Arrow Flight client.

FlightClient is intended as a convenience for interactions with Arrow Flight servers. For more direct control, such as access to the response headers, use FlightServiceClient directly via methods such as Self::inner or Self::into_inner.

Example:

use tonic::transport::Channel;
let channel = Channel::from_static("http://localhost:1234")
  .connect()
  .await
  .expect("error connecting");

let mut client = FlightClient::new(channel);

// Send 'Hi' bytes as the handshake request to the server
let response = client
  .handshake(Bytes::from("Hi"))
  .await
  .expect("error handshaking");

// Expect the server responded with 'Ho'
assert_eq!(response, Bytes::from("Ho"));

Implementations§

Creates a client client with the provided Channel

Creates a new higher level client with the provided lower level client

Return a reference to gRPC metadata included with each request

Return a reference to gRPC metadata included with each request

These headers can be used, for example, to include authorization or other application specific headers.

Add the specified header with value to all subsequent requests. See Self::metadata_mut for fine grained control.

Return a reference to the underlying tonic FlightServiceClient

Return a mutable reference to the underlying tonic FlightServiceClient

Consume this client and return the underlying tonic FlightServiceClient

Perform an Arrow Flight handshake with the server, sending payload as the HandshakeRequest payload and returning the HandshakeResponse bytes returned from the server

See FlightClient docs for an example.

Make a DoGet call to the server with the provided ticket, returning a FlightRecordBatchStream for reading RecordBatches.

Note

To access the returned FlightData use FlightRecordBatchStream::into_inner()

Example:
let mut client = FlightClient::new(channel);

// Invoke a do_get request on the server with a previously
// received Ticket

let response = client
   .do_get(ticket)
   .await
   .expect("error invoking do_get");

// Use try_collect to get the RecordBatches from the server
let batches: Vec<RecordBatch> = response
   .try_collect()
   .await
   .expect("no stream errors");

Make a GetFlightInfo call to the server with the provided FlightDescriptor and return the FlightInfo from the server. The FlightInfo can be used with Self::do_get to retrieve the requested batches.

Example:
let mut client = FlightClient::new(channel);

// Send a 'CMD' request to the server
let request = FlightDescriptor::new_cmd(b"MOAR DATA".to_vec());
let flight_info = client
  .get_flight_info(request)
  .await
  .expect("error handshaking");

// retrieve the first endpoint from the returned flight info
let ticket = flight_info
  .endpoint[0]
  // Extract the ticket
  .ticket
  .clone()
  .expect("expected ticket");

// Retrieve the corresponding RecordBatch stream with do_get
let data = client
  .do_get(ticket)
  .await
  .expect("error fetching data");

Make a DoPut call to the server with the provided Stream of FlightData and returning a stream of PutResult.

Example:
let mut client = FlightClient::new(channel);

// encode the batch as a stream of `FlightData`
let flight_data_stream = FlightDataEncoderBuilder::new()
  .build(futures::stream::iter(vec![Ok(batch)]))
  // data encoder return Results, but do_put requires FlightData
  .map(|batch|batch.unwrap());

// send the stream and get the results as `PutResult`
let response: Vec<PutResult>= client
  .do_put(flight_data_stream)
  .await
  .unwrap()
  .try_collect() // use TryStreamExt to collect stream
  .await
  .expect("error calling do_put");

Make a DoExchange call to the server with the provided Stream of FlightData and returning a stream of FlightData.

Example:
let mut client = FlightClient::new(channel);

// encode the batch as a stream of `FlightData`
let flight_data_stream = FlightDataEncoderBuilder::new()
  .build(futures::stream::iter(vec![Ok(batch)]))
  // data encoder return Results, but do_exchange requires FlightData
  .map(|batch|batch.unwrap());

// send the stream and get the results as `RecordBatches`
let response: Vec<RecordBatch> = client
  .do_exchange(flight_data_stream)
  .await
  .unwrap()
  .try_collect() // use TryStreamExt to collect stream
  .await
  .expect("error calling do_exchange");

Make a ListFlights call to the server with the provided critera and returning a Stream of FlightInfo.

Example:
let mut client = FlightClient::new(channel);

// Send 'Name=Foo' bytes as the "expression" to the server
// and gather the returned FlightInfo
let responses: Vec<FlightInfo> = client
  .list_flights(Bytes::from("Name=Foo"))
  .await
  .expect("error listing flights")
  .try_collect() // use TryStreamExt to collect stream
  .await
  .expect("error gathering flights");

Make a GetSchema call to the server with the provided FlightDescriptor and returning the associated Schema.

Example:
let mut client = FlightClient::new(channel);

// Request the schema result of a 'CMD' request to the server
let request = FlightDescriptor::new_cmd(b"MOAR DATA".to_vec());

let schema: Schema = client
  .get_schema(request)
  .await
  .expect("error making request");

Make a ListActions call to the server and returning a Stream of ActionType.

Example:
let mut client = FlightClient::new(channel);

// List available actions on the server:
let actions: Vec<ActionType> = client
  .list_actions()
  .await
  .expect("error listing actions")
  .try_collect() // use TryStreamExt to collect stream
  .await
  .expect("error gathering actions");

Make a DoAction call to the server and returning a Stream of opaque Bytes.

Example:
let mut client = FlightClient::new(channel);

let request = Action::new("my_action", "the body");

// Make a request to run the action on the server
let results: Vec<Bytes> = client
  .do_action(request)
  .await
  .expect("error executing acton")
  .try_collect() // use TryStreamExt to collect stream
  .await
  .expect("error gathering action results");

Trait Implementations§

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Wrap the input message T in a tonic::Request
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more