LiaCastaneda commented on code in PR #21589:
URL: https://github.com/apache/datafusion/pull/21589#discussion_r3109671277


##########
datafusion/physical-plan/src/aggregates/group_values/single_group_by/dictionary.rs:
##########


Review Comment:
   Do you think it's worth adding a diagram explaining how the two-phase 
grouping works? It took me a while to understand it and a diagram helped a lot
   
   ```
   Input batch: DictionaryArray
     values = ["ap-south", "us-east"]   (d=2)
     keys   = [0, 1, 0, 0, 1]          (n=5)
   
   Pre-step: hash all d values once
     value_hashes = [h("ap-south"), h("us-east")]
   
   Pass 1 — d iterations (build key_to_group from persistent cache)
     unique_dict_value_mapping: {h("ap-south") -> (group_id=0), ...}
                                         │
     for each value in values array ─────┘
       lookup in map → key_to_group[0] = Some(0)
                       key_to_group[1] = Some(1)
   
   Pass 2 — n iterations (assign group ids to every row)
     for each key in keys array:
       key=0 → key_to_group[0] = Some(0) → groups.push(0)
       key=1 → key_to_group[1] = Some(1) → groups.push(1)
       key=0 → key_to_group[0] = Some(0) → groups.push(0)
       key=0 → key_to_group[0] = Some(0) → groups.push(0)
       key=1 → key_to_group[1] = Some(1) → groups.push(1)
   
   Output: groups = [0, 1, 0, 0, 1]
   ```



##########
datafusion/physical-plan/src/aggregates/group_values/single_group_by/dictionary.rs:
##########


Review Comment:
   Do you think it's worth adding a diagram explaining how the two-phase 
grouping works? It took me a while to understand it and a diagram claude made 
helped a lot
   
   ```
   Input batch: DictionaryArray
     values = ["ap-south", "us-east"]   (d=2)
     keys   = [0, 1, 0, 0, 1]          (n=5)
   
   Pre-step: hash all d values once
     value_hashes = [h("ap-south"), h("us-east")]
   
   Pass 1 — d iterations (build key_to_group from persistent cache)
     unique_dict_value_mapping: {h("ap-south") -> (group_id=0), ...}
                                         │
     for each value in values array ─────┘
       lookup in map → key_to_group[0] = Some(0)
                       key_to_group[1] = Some(1)
   
   Pass 2 — n iterations (assign group ids to every row)
     for each key in keys array:
       key=0 → key_to_group[0] = Some(0) → groups.push(0)
       key=1 → key_to_group[1] = Some(1) → groups.push(1)
       key=0 → key_to_group[0] = Some(0) → groups.push(0)
       key=0 → key_to_group[0] = Some(0) → groups.push(0)
       key=1 → key_to_group[1] = Some(1) → groups.push(1)
   
   Output: groups = [0, 1, 0, 0, 1]
   ```



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to