Dandandan opened a new pull request, #21332: URL: https://github.com/apache/datafusion/pull/21332
## 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. --> Closes #. ## 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. Providing context helps reviewers understand the broader picture and offer better suggestions. --> In multi-column GROUP BY, `ByteViewGroupValueBuilder` stores every non-inline string value (>12 bytes) by copying the full bytes into its buffer, even when the same value has already been stored. For columns with low cardinality (e.g., `state`, `country`), this leads to significant memory waste. ## What changes are included in this PR? <!-- 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. --> Adds a per-builder hash-based dedup map (`HashMap<u64, u128>`) that maps value hashes to their views. In the vectorized append path (the hot path), before copying bytes for a non-inline value, we check if a value with the same hash was already appended. If so, we reuse the existing view — skipping the byte copy entirely. Key details: - Only affects the vectorized append path (single-row `append_val` is unchanged) - Only deduplicates values > 12 bytes (inline values have no buffer cost) - The dedup map persists across batches for cross-batch dedup - Cleared on `take_n` since buffer indices shift - Extracted shared `append_value_to_buffer()` helper to avoid code duplication ## Are these changes tested? <!-- 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, if the change is a minor refactor of existing code, tests may not be needed. --> Yes — added `test_byte_view_vectorized_append_dedup` which verifies: - Duplicate long strings within a batch share buffer storage - Cross-batch dedup works (same string in batch 2 doesn't grow the buffer) - Output correctness is preserved ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> No — this is an internal optimization. Query results are unchanged. 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
