You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by al...@apache.org on 2022/06/21 15:04:45 UTC

[arrow-rs] branch master updated: minor: add a diagram to docstring for DictionaryArray (#1909)

This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new 50a9dd5d7 minor: add a diagram to docstring for DictionaryArray (#1909)
50a9dd5d7 is described below

commit 50a9dd5d7a697a894f2b8028190b8d1cb31a1096
Author: Andrew Lamb <an...@nerdnetworks.org>
AuthorDate: Tue Jun 21 11:04:39 2022 -0400

    minor: add a diagram to docstring for DictionaryArray (#1909)
    
    * minor: add a diagram to docstring for DictionaryArray
    
    * minor: clarify docstring on `DictionaryArray::lookup_key`
    
    * Apply suggestions from code review
    
    Co-authored-by: Ruihang Xia <wa...@gmail.com>
    Co-authored-by: Jörn Horstmann <gi...@jhorstmann.net>
    
    * make values smaller and keys larger
    
    Co-authored-by: Wakahisa <ne...@gmail.com>
    Co-authored-by: Ruihang Xia <wa...@gmail.com>
    Co-authored-by: Jörn Horstmann <gi...@jhorstmann.net>
---
 arrow/src/array/array_dictionary.rs | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/arrow/src/array/array_dictionary.rs b/arrow/src/array/array_dictionary.rs
index cff3daabb..d0222ba9d 100644
--- a/arrow/src/array/array_dictionary.rs
+++ b/arrow/src/array/array_dictionary.rs
@@ -33,6 +33,34 @@ use crate::error::Result;
 /// This is mostly used to represent strings or a limited set of primitive types as integers,
 /// for example when doing NLP analysis or representing chromosomes by name.
 ///
+/// [`DictionaryArray`] are represented using a `keys` array and a
+/// `values` array, which may be different lengths. The `keys` array
+/// stores indexes in the `values` array which holds
+/// the corresponding logical value, as shown here:
+///
+/// ```text
+/// ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
+///   ┌─────────────────┐  ┌─────────┐ │     ┌─────────────────┐
+/// │ │        A        │  │    0    │       │        A        │     values[keys[0]]
+///   ├─────────────────┤  ├─────────┤ │     ├─────────────────┤
+/// │ │        D        │  │    2    │       │        B        │     values[keys[1]]
+///   ├─────────────────┤  ├─────────┤ │     ├─────────────────┤
+/// │ │        B        │  │    2    │       │        B        │     values[keys[2]]
+///   └─────────────────┘  ├─────────┤ │     ├─────────────────┤
+/// │                      │    1    │       │        D        │     values[keys[3]]
+///                        ├─────────┤ │     ├─────────────────┤
+/// │                      │    1    │       │        D        │     values[keys[4]]
+///                        ├─────────┤ │     ├─────────────────┤
+/// │                      │    0    │       │        A        │     values[keys[5]]
+///                        └─────────┘ │     └─────────────────┘
+/// │       values            keys
+///  ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘
+///                                             Logical array
+///                                                Contents
+///           DictionaryArray
+///              length = 6
+/// ```
+///
 /// Example **with nullable** data:
 ///
 /// ```