Extracts flight data from the next message, updating decoding state as necessary.
(&mut self, data: FlightData)
| 261 | /// Extracts flight data from the next message, updating decoding |
| 262 | /// state as necessary. |
| 263 | fn extract_message(&mut self, data: FlightData) -> Result<Option<DecodedFlightData>> { |
| 264 | use arrow_ipc::MessageHeader; |
| 265 | let message = arrow_ipc::root_as_message(&data.data_header[..]) |
| 266 | .map_err(|e| FlightError::DecodeError(format!("Error decoding root message: {e}")))?; |
| 267 | |
| 268 | match message.header_type() { |
| 269 | MessageHeader::NONE => Ok(Some(DecodedFlightData::new_none(data))), |
| 270 | MessageHeader::Schema => { |
| 271 | let schema = Schema::try_from(&data) |
| 272 | .map_err(|e| FlightError::DecodeError(format!("Error decoding schema: {e}")))?; |
| 273 | |
| 274 | let schema = Arc::new(schema); |
| 275 | let dictionaries_by_field = HashMap::new(); |
| 276 | |
| 277 | self.state = Some(FlightStreamState { |
| 278 | schema: Arc::clone(&schema), |
| 279 | dictionaries_by_field, |
| 280 | }); |
| 281 | Ok(Some(DecodedFlightData::new_schema(data, schema))) |
| 282 | } |
| 283 | MessageHeader::DictionaryBatch => { |
| 284 | let state = if let Some(state) = self.state.as_mut() { |
| 285 | state |
| 286 | } else { |
| 287 | return Err(FlightError::protocol( |
| 288 | "Received DictionaryBatch prior to Schema", |
| 289 | )); |
| 290 | }; |
| 291 | |
| 292 | let buffer = Buffer::from(data.data_body); |
| 293 | let dictionary_batch = message.header_as_dictionary_batch().ok_or_else(|| { |
| 294 | FlightError::protocol( |
| 295 | "Could not get dictionary batch from DictionaryBatch message", |
| 296 | ) |
| 297 | })?; |
| 298 | |
| 299 | arrow_ipc::reader::read_dictionary( |
| 300 | &buffer, |
| 301 | dictionary_batch, |
| 302 | &state.schema, |
| 303 | &mut state.dictionaries_by_field, |
| 304 | &message.version(), |
| 305 | ) |
| 306 | .map_err(|e| { |
| 307 | FlightError::DecodeError(format!("Error decoding ipc dictionary: {e}")) |
| 308 | })?; |
| 309 | |
| 310 | // Updated internal state, but no decoded message |
| 311 | Ok(None) |
| 312 | } |
| 313 | MessageHeader::RecordBatch => { |
| 314 | let state = if let Some(state) = self.state.as_ref() { |
| 315 | state |
| 316 | } else { |
| 317 | return Err(FlightError::protocol( |
| 318 | "Received RecordBatch prior to Schema", |
| 319 | )); |
| 320 | }; |
no test coverage detected