alamb opened a new issue, #4385: URL: https://github.com/apache/arrow-rs/issues/4385
**Is your feature request related to a problem or challenge? Please describe what you are trying to do.** People on a discord channel were recently confused about creating `MapArray`s The current documentation https://docs.rs/arrow/41.0.0/arrow/array/struct.MapArray.html does not give an example of how to create `MapArrays` **Describe the solution you'd like** A clear example of how to construct a `MapArray` linked from the `MapArray` docs **Describe alternatives you've considered** <!-- A clear and concise description of any alternative solutions or features you've considered. --> **Additional context** @tustvold suggests "using the builder" which I think means https://docs.rs/arrow/41.0.0/arrow/array/struct.MapBuilder.html Here is the example code for constructing it: ```rust fn build_map_array(list: Vec<HashMap<String, proto::Value>>) -> Result<Arc<MapArray>> { let mut entry_offset = vec![]; let mut keys = vec![]; let mut values = vec![]; let mut offset = 0; for kv in list { entry_offset.push(offset as u64); offset += kv.len(); for (key, value) in kv { keys.push(key); values.push(format!("{}:{}", value.type_name(), value)); } } println!("offset list: {:?}", entry_offset); let map_data = ArrayDataBuilder::new(datatype_map()) .len(3) .add_buffer(Buffer::from_vec(entry_offset)) .add_child_data( StructArray::from(vec![ ( Arc::new(Field::new("keys", DataType::Utf8, false)), Arc::new(StringArray::from(keys)) as ArrayRef, ), ( Arc::new(Field::new("values", DataType::Utf8, false)), Arc::new(StringArray::from(values)) as ArrayRef, ), ]) .into_data(), ) .build()?; Ok(Arc::new(MapArray::from(map_data))) } ``` (which I am not sure is right) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
