17
17
18
18
//! Client API for sending requests to executors.
19
19
20
- use std:: sync:: Arc ;
20
+ use arrow:: io:: flight:: deserialize_schemas;
21
+ use arrow:: io:: ipc:: IpcSchema ;
22
+ use std:: sync:: { Arc , Mutex } ;
21
23
use std:: { collections:: HashMap , pin:: Pin } ;
22
24
use std:: {
23
25
convert:: { TryFrom , TryInto } ,
@@ -31,11 +33,10 @@ use crate::serde::scheduler::{
31
33
Action , ExecutePartition , ExecutePartitionResult , PartitionId , PartitionStats ,
32
34
} ;
33
35
34
- use arrow_flight:: utils:: flight_data_to_arrow_batch;
35
- use arrow_flight:: Ticket ;
36
- use arrow_flight:: { flight_service_client:: FlightServiceClient , FlightData } ;
36
+ use arrow_format:: flight:: data:: { FlightData , Ticket } ;
37
+ use arrow_format:: flight:: service:: flight_service_client:: FlightServiceClient ;
37
38
use datafusion:: arrow:: {
38
- array:: { StringArray , StructArray } ,
39
+ array:: { StructArray , Utf8Array } ,
39
40
datatypes:: { Schema , SchemaRef } ,
40
41
error:: { ArrowError , Result as ArrowResult } ,
41
42
record_batch:: RecordBatch ,
@@ -122,10 +123,12 @@ impl BallistaClient {
122
123
{
123
124
Some ( flight_data) => {
124
125
// convert FlightData to a stream
125
- let schema = Arc :: new ( Schema :: try_from ( & flight_data) ?) ;
126
+ let ( schema, ipc_schema) =
127
+ deserialize_schemas ( flight_data. data_body . as_slice ( ) ) . unwrap ( ) ;
128
+ let schema = Arc :: new ( schema) ;
126
129
127
130
// all the remaining stream messages should be dictionary and record batches
128
- Ok ( Box :: pin ( FlightDataStream :: new ( stream, schema) ) )
131
+ Ok ( Box :: pin ( FlightDataStream :: new ( stream, schema, ipc_schema ) ) )
129
132
}
130
133
None => Err ( ballista_error (
131
134
"Did not receive schema batch from flight server" ,
@@ -135,32 +138,45 @@ impl BallistaClient {
135
138
}
136
139
137
140
struct FlightDataStream {
138
- stream : Streaming < FlightData > ,
141
+ stream : Mutex < Streaming < FlightData > > ,
139
142
schema : SchemaRef ,
143
+ ipc_schema : IpcSchema ,
140
144
}
141
145
142
146
impl FlightDataStream {
143
- pub fn new ( stream : Streaming < FlightData > , schema : SchemaRef ) -> Self {
144
- Self { stream, schema }
147
+ pub fn new (
148
+ stream : Streaming < FlightData > ,
149
+ schema : SchemaRef ,
150
+ ipc_schema : IpcSchema ,
151
+ ) -> Self {
152
+ Self {
153
+ stream : Mutex :: new ( stream) ,
154
+ schema,
155
+ ipc_schema,
156
+ }
145
157
}
146
158
}
147
159
148
160
impl Stream for FlightDataStream {
149
161
type Item = ArrowResult < RecordBatch > ;
150
162
151
163
fn poll_next (
152
- mut self : std:: pin:: Pin < & mut Self > ,
164
+ self : std:: pin:: Pin < & mut Self > ,
153
165
cx : & mut Context < ' _ > ,
154
166
) -> Poll < Option < Self :: Item > > {
155
- self . stream . poll_next_unpin ( cx) . map ( |x| match x {
167
+ let mut stream = self . stream . lock ( ) . unwrap ( ) ;
168
+ stream. poll_next_unpin ( cx) . map ( |x| match x {
156
169
Some ( flight_data_chunk_result) => {
157
170
let converted_chunk = flight_data_chunk_result
158
171
. map_err ( |e| ArrowError :: from_external_error ( Box :: new ( e) ) )
159
172
. and_then ( |flight_data_chunk| {
160
- flight_data_to_arrow_batch (
173
+ let hm = HashMap :: new ( ) ;
174
+
175
+ arrow:: io:: flight:: deserialize_batch (
161
176
& flight_data_chunk,
162
177
self . schema . clone ( ) ,
163
- & [ ] ,
178
+ & self . ipc_schema ,
179
+ & hm,
164
180
)
165
181
} ) ;
166
182
Some ( converted_chunk)
0 commit comments