baiguoname commented on issue #17899:
URL: https://github.com/apache/datafusion/issues/17899#issuecomment-3378314459
> Supporting retract batch is somewhat more complicated as that means the
accumulator needs to hold the entire window of values.
>
> I suggest you file a separate ticket to track supporting retract_batch
For test, I implement `MyTrivalFirstValueAccumulator` in the similar of
`TrivalFirstValueAccumulator` in this way:
```rust
#[derive(Debug, Default)]
pub struct MyTrivalFirstValueAccumulator {
window_values: VecDeque<ScalarValue>,
}
impl Accumulator for MyTrivalFirstValueAccumulator {
fn state(&mut self) -> Result<Vec<ScalarValue>> {
Ok(vec![ScalarValue::from(0), ScalarValue::from(true)])
}
fn update_batch(&mut self, values: &[ArrayRef]) -> Result<()> {
let now_value = get_row_at_idx(values, 0)?.remove(0);
self.window_values.push_back(now_value);
Ok(())
}
fn merge_batch(&mut self, _states: &[ArrayRef]) -> Result<()> {
unreachable!("not call");
}
fn retract_batch(&mut self, _values: &[ArrayRef]) -> Result<()> {
self.window_values.pop_front();
Ok(())
}
fn supports_retract_batch(&self) -> bool {
true
}
fn evaluate(&mut self) -> Result<ScalarValue> {
Ok(self.window_values[0].clone())
}
fn size(&self) -> usize {
size_of_val(self) - size_of_val(&self.window_values)
}
}
```
And their performance are close.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]