From e72c605456440d5072a00f59195374d90acadf08 Mon Sep 17 00:00:00 2001 From: Andy Grove Date: Sat, 1 Feb 2020 12:06:40 -0700 Subject: [PATCH] add starting point for flight-client example --- rust/datafusion/examples/flight-client.rs | 44 +++++++++++++++++++++++ rust/datafusion/examples/flight-server.rs | 2 ++ 2 files changed, 46 insertions(+) create mode 100644 rust/datafusion/examples/flight-client.rs diff --git a/rust/datafusion/examples/flight-client.rs b/rust/datafusion/examples/flight-client.rs new file mode 100644 index 0000000000000..80fd7f4fbf89e --- /dev/null +++ b/rust/datafusion/examples/flight-client.rs @@ -0,0 +1,44 @@ +// 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. + +use std::pin::Pin; + +use futures::Stream; +use tonic::transport::Server; +use tonic::{Request, Response, Status, Streaming}; + +use flight::flight_service_client::FlightServiceClient; + +use flight::{ + FlightData, FlightDescriptor, FlightInfo, Ticket, +}; + +#[tokio::main] +async fn main() -> Result<(), Box> { + + let mut client = FlightServiceClient::connect("http://localhost:50051").await?; + + let request = tonic::Request::new(Ticket { + ticket: "SELECT id FROM alltypes_plain".into(), + }); + + let response = client.do_get(request).await?; + + println!("RESPONSE={:?}", response); + + Ok(()) +} diff --git a/rust/datafusion/examples/flight-server.rs b/rust/datafusion/examples/flight-server.rs index 880245077a0a6..c653a3d8ec4c7 100644 --- a/rust/datafusion/examples/flight-server.rs +++ b/rust/datafusion/examples/flight-server.rs @@ -90,6 +90,8 @@ impl FlightService for FlightServiceImpl { .map(|batch| Ok(FlightData::from(batch))) .collect(); + println!("Returning {} flights", flights.len()); + let output = futures::stream::iter(flights); Ok(Response::new(Box::pin(output) as Self::DoGetStream))