tustvold commented on code in PR #7351:
URL: https://github.com/apache/arrow-datafusion/pull/7351#discussion_r1300480450
##########
datafusion/physical-expr/src/aggregate/bit_and_or_xor.rs:
##########
@@ -678,34 +611,39 @@ impl PartialEq<dyn Any> for DistinctBitXor {
}
}
-#[derive(Debug)]
-struct DistinctBitXorAccumulator {
- hash_values: HashSet<ScalarValue, RandomState>,
- data_type: DataType,
+struct DistinctBitXorAccumulator<T: ArrowNumericType> {
+ values: HashSet<T::Native, RandomState>,
+}
+
+impl<T: ArrowNumericType> std::fmt::Debug for DistinctBitXorAccumulator<T> {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "DistinctBitXorAccumulator({})", T::DATA_TYPE)
+ }
}
-impl DistinctBitXorAccumulator {
- pub fn try_new(data_type: &DataType) -> Result<Self> {
- Ok(Self {
- hash_values: HashSet::default(),
- data_type: data_type.clone(),
- })
+impl<T: ArrowNumericType> Default for DistinctBitXorAccumulator<T> {
+ fn default() -> Self {
+ Self {
+ values: HashSet::default(),
+ }
}
}
-impl Accumulator for DistinctBitXorAccumulator {
+impl<T: ArrowNumericType> Accumulator for DistinctBitXorAccumulator<T>
+where
+ T::Native: std::ops::BitXor<Output = T::Native> + std::hash::Hash + Eq,
+{
fn state(&self) -> Result<Vec<ScalarValue>> {
// 1. Stores aggregate state in `ScalarValue::List`
// 2. Constructs `ScalarValue::List` state from distinct numeric
stored in hash set
let state_out = {
- let mut distinct_values = Vec::new();
- self.hash_values
+ let values = self
+ .values
.iter()
- .for_each(|distinct_value|
distinct_values.push(distinct_value.clone()));
- vec![ScalarValue::new_list(
- Some(distinct_values),
- self.data_type.clone(),
- )]
+ .map(|x| ScalarValue::new_primitive::<T>(Some(*x),
&T::DATA_TYPE))
Review Comment:
Created https://github.com/apache/arrow-datafusion/issues/7352
--
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]