1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Copyright 2022 RisingLight Project Authors. Licensed under Apache-2.0.

use super::*;
use crate::array::{ArrayImpl, DataChunk};
use crate::v1::binder::BoundExpr;

/// The executor of a filter operation.
pub struct FilterExecutor {
    pub expr: BoundExpr,
    pub child: BoxedExecutor,
}

impl FilterExecutor {
    #[try_stream(boxed, ok = DataChunk, error = ExecutorError)]
    pub async fn execute(self) {
        #[for_await]
        for batch in self.child {
            let batch = batch?;
            let vis = match self.expr.eval(&batch)? {
                ArrayImpl::Bool(a) => a,
                _ => panic!("filters can only accept bool array"),
            };
            yield batch.filter(vis.true_array());
        }
    }
}