1-
2- use crate :: { flight :: { SqlFlightClient } , prices :: PricesClient , tls :: new_tls_flight_channel } ;
1+ use crate :: { flight :: SqlFlightClient , prices :: PricesClient , tls :: new_tls_flight_channel } ;
2+ use arrow_flight :: decode :: FlightRecordBatchStream ;
33use std:: error:: Error ;
4- use arrow_flight:: sql:: client:: FlightSqlServiceClient ;
5- use tonic:: { transport:: { Channel } } ;
6- use tonic:: { Streaming } ;
7- use arrow_flight:: { FlightData } ;
8-
9-
10- pub async fn new_spice_client ( api_key : String , http_addr : String , flight_addr : String , firecache_addr : String ) -> Result < SpiceClient , Box < dyn Error > > {
11- let flight_chan = new_tls_flight_channel ( flight_addr) . await ;
12- if flight_chan. is_err ( ) {
13- return Err ( flight_chan. err ( ) . expect ( "" ) . into ( ) )
14- }
4+ use tonic:: transport:: Channel ;
5+
6+ pub async fn new_spice_client ( api_key : String ) -> Result < SpiceClient , Box < dyn Error > > {
7+ return new_spice_client_with_address (
8+ api_key. to_string ( ) ,
9+ "https://data.spiceai.io" . to_string ( ) ,
10+ "https://flight.spiceai.io" . to_string ( ) ,
11+ )
12+ . await ;
13+ }
1514
16- match new_tls_flight_channel ( firecache_addr) . await {
15+ pub async fn new_spice_client_with_address (
16+ api_key : String ,
17+ http_addr : String ,
18+ flight_addr : String ,
19+ ) -> Result < SpiceClient , Box < dyn Error > > {
20+ match new_tls_flight_channel ( flight_addr) . await {
1721 Err ( e) => Err ( e. into ( ) ) ,
18- Ok ( firecache_chan) => Ok ( SpiceClient :: new (
19- http_addr,
20- api_key,
21- flight_chan. expect ( "" ) ,
22- firecache_chan
23- ) )
22+ Ok ( flight_chan) => Ok ( SpiceClient :: new ( http_addr, api_key, flight_chan) ) ,
2423 }
2524}
2625
2726pub struct SpiceClient {
2827 flight : SqlFlightClient ,
29- firecache : SqlFlightClient ,
30- pub prices : PricesClient
28+ pub prices : PricesClient ,
3129}
3230
3331impl SpiceClient {
34- pub fn new ( http_addr : String , api_key : String , flight : Channel , firecache : Channel ) -> Self {
32+ pub fn new ( http_addr : String , api_key : String , flight : Channel ) -> Self {
3533 Self {
3634 flight : SqlFlightClient :: new ( flight, api_key. clone ( ) ) ,
37- firecache : SqlFlightClient :: new ( firecache, api_key. clone ( ) ) ,
38- prices : PricesClient :: new ( Some ( http_addr) , api_key)
35+ prices : PricesClient :: new ( Some ( http_addr) , api_key) ,
3936 }
4037 }
41- pub async fn query ( & mut self , query : String , timeout : Option < u32 > ) -> Result < Streaming < FlightData > , Box < dyn Error > > {
38+ pub async fn query (
39+ & mut self ,
40+ query : String ,
41+ timeout : Option < u32 > ,
42+ ) -> Result < FlightRecordBatchStream , Box < dyn Error > > {
4243 self . flight . query ( query, timeout) . await
4344 }
44-
45- pub async fn firecache_query ( & mut self , query : String , timeout : Option < u32 > ) -> Result < Streaming < FlightData > , Box < dyn Error > > {
46- self . firecache . query ( query, timeout) . await
47- }
48-
49-
50- }
45+ }
0 commit comments