mingmwang commented on PR #6657:
URL: 
https://github.com/apache/arrow-datafusion/pull/6657#issuecomment-1607316427

   BTW, I had also tested the `enum_dispatch` macros, this can reduce about 
`300` lines of code in this PR,  but seems the performance is not as good as 
the handwriting version, so I give it up and keep the current handwriting 
version.
   
   ```rust
   #[enum_dispatch]
   pub trait RowAccumulator: Send + Sync + Debug {
       /// updates the accumulator's state from a vector of arrays.
       fn update_batch(&self, values: &[ArrayRef], accessor: &mut RowAccessor)
           -> Result<()>;
   
       /// updates the accumulator's state from rows with the specified indices.
       fn update_row_indices(
           &self,
           values: &[ArrayRef],
           filter: &Option<&BooleanArray>,
           row_indices: &[usize],
           accessor: &mut RowAccessor,
       ) -> Result<()>;
   
       /// updates the accumulator's state from a rust native value.
       fn update_value<N: RowAccumulatorNativeType>(
           &self,
           native_value: Option<N>,
           accessor: &mut RowAccessor,
       );
   
       /// updates the accumulator's state from a vector of states.
       fn merge_batch(
           &mut self,
           states: &[ArrayRef],
           accessor: &mut RowAccessor,
       ) -> Result<()>;
   
       /// returns its value based on its current state.
       fn evaluate(&self, accessor: &RowAccessor) -> Result<ScalarValue>;
   
       /// State's starting field index in the row.
       fn state_index(&self) -> usize;
   }
   
   /// Returns if `data_type` is supported with `RowAccumulator`
   pub fn is_row_accumulator_support_dtype(data_type: &DataType) -> bool {
       matches_all_supported_data_types!(data_type)
   }
   
   /// Enum to dispatch the RowAccumulator, RowAccumulator contains generic 
methods and can not be used as the trait objects
   #[derive(Debug)]
   #[enum_dispatch(RowAccumulator)]
   pub enum RowAccumulatorItem {
       AVG(AvgRowAccumulator),
       SUM(SumRowAccumulator),
       COUNT(CountRowAccumulator),
       MIN(MinRowAccumulator),
       MAX(MaxRowAccumulator),
       BITAND(BitAndRowAccumulator),
       BITOR(BitOrRowAccumulator),
       BITXOR(BitXorRowAccumulator),
       BOOLAND(BoolAndRowAccumulator),
       BOOLOR(BoolOrRowAccumulator),
   }
   ```


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

Reply via email to