You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "alamb (via GitHub)" <gi...@apache.org> on 2023/06/08 10:06:47 UTC

[GitHub] [arrow-rs] alamb opened a new issue, #4385: Add doc example of constructing a MapArray

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: github-unsubscribe@arrow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] alamb commented on issue #4385: Add doc example of constructing a MapArray

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on issue #4385:
URL: https://github.com/apache/arrow-rs/issues/4385#issuecomment-1595001622

   `label_issue.py` automatically added labels {'arrow'} from #4382


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] tustvold closed issue #4385: Add doc example of constructing a MapArray

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold closed issue #4385: Add doc example of constructing a MapArray
URL: https://github.com/apache/arrow-rs/issues/4385


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org