alamb commented on code in PR #7385:
URL: https://github.com/apache/arrow-datafusion/pull/7385#discussion_r1304375581
##########
datafusion/physical-expr/src/aggregate/array_agg_distinct.rs:
##########
@@ -135,23 +134,36 @@ impl Accumulator for DistinctArrayAggAccumulator {
fn update_batch(&mut self, values: &[ArrayRef]) -> Result<()> {
assert_eq!(values.len(), 1, "batch input should only include 1
column!");
- let arr = &values[0];
- for i in 0..arr.len() {
- self.values.insert(ScalarValue::try_from_array(arr, i)?);
- }
- Ok(())
+ let array = &values[0];
+ (0..array.len()).try_for_each(|i| {
+ if !array.is_null(i) {
+ self.values.insert(ScalarValue::try_from_array(array, i)?);
+ }
+ Ok(())
+ })
}
fn merge_batch(&mut self, states: &[ArrayRef]) -> Result<()> {
if states.is_empty() {
return Ok(());
}
- for array in states {
- for j in 0..array.len() {
- self.values.insert(ScalarValue::try_from_array(array, j)?);
+ assert_eq!(
+ states.len(),
+ 1,
+ "array_agg_distinct states must contain single array"
+ );
+
+ let array = &states[0];
+ (0..array.len()).try_for_each(|i| {
+ let scalar = ScalarValue::try_from_array(array, i)?;
+ if let ScalarValue::List(Some(values), _) = scalar {
+ self.values.extend(values);
Review Comment:
👍 extend should do the deduplication. 👍
##########
datafusion/physical-expr/src/aggregate/array_agg_distinct.rs:
##########
@@ -135,23 +134,36 @@ impl Accumulator for DistinctArrayAggAccumulator {
fn update_batch(&mut self, values: &[ArrayRef]) -> Result<()> {
assert_eq!(values.len(), 1, "batch input should only include 1
column!");
- let arr = &values[0];
- for i in 0..arr.len() {
- self.values.insert(ScalarValue::try_from_array(arr, i)?);
- }
- Ok(())
+ let array = &values[0];
+ (0..array.len()).try_for_each(|i| {
+ if !array.is_null(i) {
+ self.values.insert(ScalarValue::try_from_array(array, i)?);
+ }
+ Ok(())
+ })
}
fn merge_batch(&mut self, states: &[ArrayRef]) -> Result<()> {
if states.is_empty() {
return Ok(());
}
- for array in states {
- for j in 0..array.len() {
- self.values.insert(ScalarValue::try_from_array(array, j)?);
+ assert_eq!(
+ states.len(),
+ 1,
+ "array_agg_distinct states must contain single array"
+ );
+
+ let array = &states[0];
+ (0..array.len()).try_for_each(|i| {
+ let scalar = ScalarValue::try_from_array(array, i)?;
+ if let ScalarValue::List(Some(values), _) = scalar {
+ self.values.extend(values);
Review Comment:
👍 extend should do the deduplication. 👍
--
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]