Given a dictionary batch IPC message/body along with the full state of a stream including schema, dictionary cache, metadata, and other flags, this function will parse the buffer into an array of dictionary values.
(
buf: &Buffer,
batch: crate::DictionaryBatch,
schema: &Schema,
dictionaries_by_id: &mut HashMap<i64, ArrayRef>,
metadata: &MetadataVersion,
require_alignment: bool,
skip_v
| 865 | /// stream including schema, dictionary cache, metadata, and other flags, this |
| 866 | /// function will parse the buffer into an array of dictionary values. |
| 867 | fn get_dictionary_values( |
| 868 | buf: &Buffer, |
| 869 | batch: crate::DictionaryBatch, |
| 870 | schema: &Schema, |
| 871 | dictionaries_by_id: &mut HashMap<i64, ArrayRef>, |
| 872 | metadata: &MetadataVersion, |
| 873 | require_alignment: bool, |
| 874 | skip_validation: UnsafeFlag, |
| 875 | ) -> Result<ArrayRef, ArrowError> { |
| 876 | let id = batch.id(); |
| 877 | #[allow(deprecated)] |
| 878 | let fields_using_this_dictionary = schema.fields_with_dict_id(id); |
| 879 | let first_field = fields_using_this_dictionary.first().ok_or_else(|| { |
| 880 | ArrowError::InvalidArgumentError(format!("dictionary id {id} not found in schema")) |
| 881 | })?; |
| 882 | |
| 883 | // As the dictionary batch does not contain the type of the |
| 884 | // values array, we need to retrieve this from the schema. |
| 885 | // Get an array representing this dictionary's values. |
| 886 | let dictionary_values: ArrayRef = match first_field.data_type() { |
| 887 | DataType::Dictionary(_, value_type) => { |
| 888 | // Make a fake schema for the dictionary batch. |
| 889 | let value = value_type.as_ref().clone(); |
| 890 | let schema = Schema::new(vec![Field::new("", value, true)]); |
| 891 | // Read a single column |
| 892 | let record_batch = RecordBatchDecoder::try_new( |
| 893 | buf, |
| 894 | batch.data().unwrap(), |
| 895 | Arc::new(schema), |
| 896 | dictionaries_by_id, |
| 897 | metadata, |
| 898 | )? |
| 899 | .with_require_alignment(require_alignment) |
| 900 | .with_skip_validation(skip_validation) |
| 901 | .read_record_batch()?; |
| 902 | |
| 903 | Some(record_batch.column(0).clone()) |
| 904 | } |
| 905 | _ => None, |
| 906 | } |
| 907 | .ok_or_else(|| { |
| 908 | ArrowError::InvalidArgumentError(format!("dictionary id {id} not found in schema")) |
| 909 | })?; |
| 910 | |
| 911 | Ok(dictionary_values) |
| 912 | } |
| 913 | |
| 914 | /// Read the data for a given block |
| 915 | fn read_block<R: Read + Seek>(mut reader: R, block: &Block) -> Result<Buffer, ArrowError> { |
no test coverage detected