MCPcopy Create free account
hub / github.com/apache/arrow-rs / get_dictionary_values

Function get_dictionary_values

arrow-ipc/src/reader.rs:867–912  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

865/// stream including schema, dictionary cache, metadata, and other flags, this
866/// function will parse the buffer into an array of dictionary values.
867fn 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
915fn read_block<R: Read + Seek>(mut reader: R, block: &Block) -> Result<Buffer, ArrowError> {

Callers 2

read_dictionary_implFunction · 0.85
next_ipc_messageMethod · 0.85

Calls 12

try_newFunction · 0.85
firstMethod · 0.80
read_record_batchMethod · 0.80
idMethod · 0.45
fields_with_dict_idMethod · 0.45
data_typeMethod · 0.45
cloneMethod · 0.45
as_refMethod · 0.45
with_skip_validationMethod · 0.45
dataMethod · 0.45
columnMethod · 0.45

Tested by

no test coverage detected