Skip to content

Commit

Permalink
add starting point for flight-client example
Browse files Browse the repository at this point in the history
  • Loading branch information
andygrove committed Feb 1, 2020
1 parent 996f2a4 commit e72c605
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
44 changes: 44 additions & 0 deletions 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<dyn std::error::Error>> {

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(())
}
2 changes: 2 additions & 0 deletions rust/datafusion/examples/flight-server.rs
Expand Up @@ -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))
Expand Down

0 comments on commit e72c605

Please sign in to comment.