Encodes a batch to a number of [EncodedData] items (dictionary batches + the record batch). The [DictionaryTracker] keeps track of dictionaries with new `dict_id`s (so they are only sent once) Make sure the [DictionaryTracker] is initialized at the start of the stream.
(
&self,
batch: &RecordBatch,
dictionary_tracker: &mut DictionaryTracker,
write_options: &IpcWriteOptions,
compression_context: &mut CompressionContext,
)
| 468 | /// The [DictionaryTracker] keeps track of dictionaries with new `dict_id`s (so they are only sent once) |
| 469 | /// Make sure the [DictionaryTracker] is initialized at the start of the stream. |
| 470 | pub fn encode( |
| 471 | &self, |
| 472 | batch: &RecordBatch, |
| 473 | dictionary_tracker: &mut DictionaryTracker, |
| 474 | write_options: &IpcWriteOptions, |
| 475 | compression_context: &mut CompressionContext, |
| 476 | ) -> Result<(Vec<EncodedData>, EncodedData), ArrowError> { |
| 477 | let schema = batch.schema(); |
| 478 | let mut encoded_dictionaries = Vec::with_capacity(schema.flattened_fields().len()); |
| 479 | |
| 480 | let mut dict_id = dictionary_tracker.dict_ids.clone().into_iter(); |
| 481 | |
| 482 | for (i, field) in schema.fields().iter().enumerate() { |
| 483 | let column = batch.column(i); |
| 484 | self.encode_dictionaries( |
| 485 | field, |
| 486 | column, |
| 487 | &mut encoded_dictionaries, |
| 488 | dictionary_tracker, |
| 489 | write_options, |
| 490 | &mut dict_id, |
| 491 | compression_context, |
| 492 | )?; |
| 493 | } |
| 494 | |
| 495 | let encoded_message = |
| 496 | self.record_batch_to_bytes(batch, write_options, compression_context)?; |
| 497 | Ok((encoded_dictionaries, encoded_message)) |
| 498 | } |
| 499 | |
| 500 | /// Encodes a batch to a number of [EncodedData] items (dictionary batches + the record batch). |
| 501 | /// The [DictionaryTracker] keeps track of dictionaries with new `dict_id`s (so they are only sent once) |