refactor AccGenericColumn for better data type inference and memory usage statistics.#997
Merged
refactor AccGenericColumn for better data type inference and memory usage statistics.#997
Conversation
df29dab to
258dce3
Compare
258dce3 to
bdf1dc0
Compare
lihao712
approved these changes
May 23, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
Refactors the generic accumulator column into specialized column types to improve data type inference and uninitialized memory allocation, and updates aggregation implementations accordingly.
- Introduce
UninitializedInitfor zero-cost buffer allocation in file readers and batch serde. - Replace the monolithic
AccGenericColumnwithAccPrimColumn,AccBooleanColumn,AccBytesColumn, andAccScalarValueColumn, plus helper functionscreate_acc_generic_columnandacc_generic_column_to_array. - Update all
Aggimplementations (sum, maxmin, first, count, collect, bloom_filter, avg, spark_udaf_wrapper) to use the new column structs and removeunwrap()on downcasts.
Reviewed Changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| native-engine/datafusion-ext-plans/src/scan/internal_file_reader.rs | Use uninitialized-init buffer allocation in read_fully. |
| native-engine/datafusion-ext-plans/src/agg/sum.rs | Migrate sum to AccPrimColumn and helper APIs. |
| native-engine/datafusion-ext-plans/src/agg/spark_udaf_wrapper.rs | Use Vec::uninitialized_init for JVM byte arrays and ? on downcasts. |
| native-engine/datafusion-ext-plans/src/agg/maxmin.rs | Refactor max/min to specialized Acc*Column types. |
| native-engine/datafusion-ext-plans/src/agg/first_ignores_null.rs | Swap out AccGenericColumn for concrete column types. |
| native-engine/datafusion-ext-plans/src/agg/first.rs | Introduce separate flags column and new accumulator helpers. |
| native-engine/datafusion-ext-plans/src/agg/count.rs | Replace unwrap() on downcasts with error propagation ?. |
| native-engine/datafusion-ext-plans/src/agg/collect.rs | Add guard for small-to-huge conversion and refactor collection. |
| native-engine/datafusion-ext-plans/src/agg/bloom_filter.rs | Switch to specialized columns and remove panicking unwraps. |
| native-engine/datafusion-ext-plans/src/agg/avg.rs | Update AVG to use new column creation and merge patterns. |
| native-engine/datafusion-ext-plans/src/agg/acc.rs | Overhaul AccGenericColumn into concrete column structs and APIs. |
| native-engine/datafusion-ext-commons/src/lib.rs | Add UninitializedInit trait for Vec and SmallVec. |
| native-engine/datafusion-ext-commons/src/io/batch_serde.rs | Apply uninitialized-init to raw batch serialization buffers. |
| native-engine/datafusion-ext-commons/Cargo.toml | Add smallvec dependency for UninitializedInit support. |
Comments suppressed due to low confidence (2)
native-engine/datafusion-ext-plans/src/agg/first.rs:157
- For a
Binarydata type you must downcast toBinaryArray, notStringArray. Please usedowncast_any!(partial_arg, BinaryArray)?.
DataType::Utf8 => handle_bytes!(downcast_any!(partial_arg, StringArray)?),
native-engine/datafusion-ext-plans/src/agg/collect.rs:514
- The
if letwith&&is invalid syntax. To add a guard, useif let Self::Small(s) = self if s.len() >= 4 { ... }or nest anif.
&& s.len() >= 4
| DataType::Utf8 => handle_bytes!(String), | ||
| DataType::Binary => handle_bytes!(Binary), | ||
| DataType::Utf8 => handle_bytes!(downcast_any!(partial_arg, StringArray)?), | ||
| DataType::Binary => handle_bytes!(downcast_any!(partial_arg, StringArray)?), |
There was a problem hiding this comment.
Binary arrays should be downcast to BinaryArray, not StringArray. Update to downcast_any!(partial_arg, BinaryArray)?.
Suggested change
| DataType::Binary => handle_bytes!(downcast_any!(partial_arg, StringArray)?), | |
| DataType::Binary => handle_bytes!(downcast_any!(partial_arg, BinaryArray)?), |
| fn convert_to_huge_if_needed(&mut self, list: &mut AccList) { | ||
| if let Self::Small(s) = self { | ||
| if let Self::Small(s) = self | ||
| && s.len() >= 4 |
There was a problem hiding this comment.
[nitpick] The threshold 4 is a magic number. Consider extracting it into a named constant to clarify its purpose.
Suggested change
| && s.len() >= 4 | |
| && s.len() >= SMALL_TO_HUGE_THRESHOLD |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.