Rich-T-kid opened a new pull request, #21765: URL: https://github.com/apache/datafusion/pull/21765
## Which issue does this PR close? This PR make an effort towards https://github.com/apache/datafusion/issues/7000 & closing https://github.com/apache/datafusion/issues/7647 + https://github.com/apache/datafusion/issues/21466 This PR aim to close half of https://github.com/apache/datafusion/issues/7647 **A separate follow up PR aims to close the multi-column + dictionary column case** <!-- 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. --> - Closes #7647. ## Rationale for this change <!-- 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. --> Issue #7647 ([Materialize Dictionaries in Group Keys](https://github.com/apache/datafusion/issues/7647)) identified that DataFusion was not taking advantage of dictionary encoding during hash aggregation, instead of operating on the compact dictionary representation, it was deserializing dictionary arrays into a generic row-based format, throwing away all the encoding benefits. An initial attempt was made to fix this but it caused regressions and was ultimately rolled back. ### This PR This PR takes a different approach. Rather than materializing the dictionary into a generic representation, it introduces GroupValuesDictionary, a specialized implementation that operates directly on the dictionary's structure. The key insight is that dictionary encoded columns have inherently low cardinality by design, meaning the same values repeat frequently across rows. Instead of hashing and comparing every row independently, we maintain a mapping of unique value hashes to group IDs so that repeated values are resolved in O(1) after the first encounter. Null values are similarly cached so that subsequent null rows never pay the lookup cost again. For a more detailed explanation of the implementation see[ this design doc](https://docs.google.com/document/d/13mEwd08jKzgw3Dcu4-B0ARSpFsZKPUEwrSBMm1VlRzo/edit?tab=t.ulp2jcmea65z). ## What changes are included in this PR? Update the match statement in new_group_values to include a custom dictionary encoding branch that works for single fields that are of type Dictionary array <!-- 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? Yes, about half of the code in this PR is about testing edge cases. <!-- 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? No <!-- 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]
