Rachelint opened a new pull request, #15591:
URL: https://github.com/apache/datafusion/pull/15591

   ## Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and 
enhancements and this helps us generate change logs for our releases. You can 
link an issue to this PR using the GitHub syntax. For example `Closes #123` 
indicates that this PR will close issue #123.
   -->
   
   - Part of #7065 
   
   ## Rationale for this change
   
   As mentioned in #7065 , we use a single `Vec` to manage `aggregation 
intermediate results` both in `GroupAccumulator` and `GroupValues`.
   
   It is simple but not efficient enough in high-cardinality aggregation, 
because when `Vec` is not large enough, we need to allocate a new `Vec` and 
copy all data from the old one.
   - Copying a large amount of data(due to high-cardinality) is obviously 
expansive
   - And it is also not friendly to cpu (will refresh cache and tlb)
   
   So this pr introduces a `blocked approach` to manage the `aggregation 
intermediate results`. We will never resize the `Vec` in the approach, and 
instead we split the data to blocks, when the capacity is not enough, we just 
allocate a new block. Detail can see #7065 
   
   
   <!--
    Why are you proposing this change? If this is already explained clearly in 
the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your 
changes and offer better suggestions for fixes.  
   -->
   
   ## What changes are included in this PR?
   
   - Implement the sketch for blocked approach
   - Implement blocked groups supporting `PrimitiveGroupsAccumulator` and 
`GroupValuesPrimitive` as the example
   
   <!--
   There is no need to duplicate the description in the issue here but it is 
sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   ## Are these changes tested?
   Test by exist tests. And new unit tests, new fuzzy tests.
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are 
they covered by existing tests)?
   -->
   
   ## Are there any user-facing changes?
   Two functions are added to `GroupValues` and `GroupAccumulator` trait.
   
   But as you can see, there are default implementations for them, and users 
can choose to really support the blocked approach when wanting a better 
performance for their `udaf`s.
   
   ```
       /// Returns `true` if this accumulator supports blocked groups.
       fn supports_blocked_groups(&self) -> bool {
           false
       }
   
       /// Alter the block size in the accumulator
       ///
       /// If the target block size is `None`, it will use a single big
       /// block(can think it a `Vec`) to manage the state.
       ///
       /// If the target block size` is `Some(blk_size)`, it will try to
       /// set the block size to `blk_size`, and the try will only success
       /// when the accumulator has supported blocked mode.
       ///
       /// NOTICE: After altering block size, all data in previous will be 
cleared.
       ///
       fn alter_block_size(&mut self, block_size: Option<usize>) -> Result<()> {
           if block_size.is_some() {
               return Err(DataFusionError::NotImplemented(
                   "this accumulator doesn't support blocked mode 
yet".to_string(),
               ));
           }
   
           Ok(())
       }
   ```
   <!--
   If there are user-facing changes then we may require documentation to be 
updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api 
change` label.
   -->
   


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