2010YOUY01 commented on code in PR #22729:
URL: https://github.com/apache/datafusion/pull/22729#discussion_r3363075182


##########
datafusion/physical-plan/src/aggregates/hash_table.rs:
##########
@@ -0,0 +1,615 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::collections::HashMap;
+use std::marker::PhantomData;
+use std::sync::Arc;
+
+use arrow::array::{ArrayRef, AsArray, BooleanArray, new_null_array};
+use arrow::datatypes::SchemaRef;
+use arrow::record_batch::RecordBatch;
+use datafusion_common::{Result, internal_err};
+use datafusion_execution::memory_pool::proxy::VecAllocExt;
+use datafusion_expr::{EmitTo, GroupsAccumulator};
+
+use super::group_values::{GroupByMetrics, GroupValues, new_group_values};
+use super::order::GroupOrdering;
+use super::row_hash::create_group_accumulator;
+use super::{
+    AggregateExec, PhysicalGroupBy, aggregate_expressions, evaluate_group_by,
+    group_id_array, max_duplicate_ordinal,
+};
+use crate::PhysicalExpr;
+use crate::metrics::{MetricBuilder, MetricCategory};
+
+/// Marker for raw rows -> partial state aggregation.
+pub(super) struct Partial;
+/// Marker for partial state -> final value aggregation.
+pub(super) struct Final;
+
+/// Grouped hash table shared by the initial-partial and partial-final paths.
+///
+/// While building, it consumes input batches and updates group / accumulator
+/// state. While outputting, it incrementally output the materialized batches.
+///
+/// # Marker Type
+/// `AggrMode` is a zero-sized marker type used with `PhantomData` to keep the
+/// initial-partial and partial-final update logic in separate impl blocks. 
Different
+/// stages has different semantics and applicable optimizations, this makes the
+/// implementation easier to follow.
+pub(super) struct AggregateHashTable<AggrMode> {

Review Comment:
   It is intentionally unused, this is like compile time boolean flag to choose 
the implementation
   ```rs
   // semantically equivalent to
   fn aggregate_batch() {
       if self.is_partial_aggregate {
           self.aggregate_batch_partial()
       } else {
           self.aggregate_batch_final()
       }
   }
   ```
   The benefits are
   - Comparing with shared struct, less verbose
   - Comparing with using runtime flag. Since two variants have different 
semantics (i.e. input schema), this approach is more explicit.
   
   I am aware this is a not common pattern, I'll add more comments.



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