You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/01/26 18:50:59 UTC
[GitHub] [arrow-datafusion] alamb commented on a change in pull request #1681: refactor array_agg to not to have `update` and `merge`
alamb commented on a change in pull request #1681:
URL: https://github.com/apache/arrow-datafusion/pull/1681#discussion_r792940671
##########
File path: datafusion/src/physical_plan/expressions/array_agg.rs
##########
@@ -95,77 +95,60 @@ impl AggregateExpr for ArrayAgg {
#[derive(Debug)]
pub(crate) struct ArrayAggAccumulator {
- array: Vec<ScalarValue>,
+ values: Vec<ScalarValue>,
datatype: DataType,
}
impl ArrayAggAccumulator {
/// new array_agg accumulator based on given item data type
pub fn try_new(datatype: &DataType) -> Result<Self> {
Ok(Self {
- array: vec![],
+ values: vec![],
datatype: datatype.clone(),
})
}
-
- fn update(&mut self, values: &[ScalarValue]) -> Result<()> {
- let value = &values[0];
- self.array.push(value.clone());
-
- Ok(())
- }
-
- fn merge(&mut self, states: &[ScalarValue]) -> Result<()> {
- if states.is_empty() {
- return Ok(());
- };
-
- assert!(states.len() == 1, "states length should be 1!");
- match &states[0] {
- ScalarValue::List(Some(array), _) => {
- self.array.extend((&**array).clone());
- }
- _ => unreachable!(),
- }
- Ok(())
- }
}
impl Accumulator for ArrayAggAccumulator {
fn update_batch(&mut self, values: &[ArrayRef]) -> Result<()> {
if values.is_empty() {
return Ok(());
};
- (0..values[0].len()).try_for_each(|index| {
- let v = values
- .iter()
- .map(|array| ScalarValue::try_from_array(array, index))
- .collect::<Result<Vec<_>>>()?;
- self.update(&v)
+ assert!(values.len() == 1, "array_agg can only take 1 param!");
Review comment:
I like the new assert 👍
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org