Skip to content

Commit

Permalink
fix: inconsistent types in array_agg_distinct merge_batch
Browse files Browse the repository at this point in the history
  • Loading branch information
korowa committed Aug 22, 2023
1 parent 6aa423b commit d899eb7
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions datafusion/physical-expr/src/aggregate/array_agg_distinct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ use std::collections::HashSet;
use crate::aggregate::utils::down_cast_any_ref;
use crate::expressions::format_state_name;
use crate::{AggregateExpr, PhysicalExpr};
use datafusion_common::Result;
use datafusion_common::ScalarValue;
use datafusion_common::{internal_err, DataFusionError, Result, ScalarValue};
use datafusion_expr::Accumulator;

/// Expression for a ARRAY_AGG(DISTINCT) aggregation.
Expand Down Expand Up @@ -147,11 +146,20 @@ impl Accumulator for DistinctArrayAggAccumulator {
return Ok(());
}

for array in states {
for j in 0..array.len() {
self.values.insert(ScalarValue::try_from_array(array, j)?);
assert!(
states.len() == 1,
"array_agg_distinct states must contain single array"
);
let state = &states[0];
(0..state.len()).try_for_each(|i| {
let scalar = ScalarValue::try_from_array(state, i)?;
if let ScalarValue::List(Some(values), _) = scalar {
self.values.extend(values);
Ok(())
} else {
internal_err!("array_agg_distinct state must be list")
}
}
})?;

Ok(())
}
Expand Down

0 comments on commit d899eb7

Please sign in to comment.