sochdb_query/executor/
filter.rs1use crate::sql::ast::Expr;
6use super::eval::eval_predicate;
7use super::node::PlanNode;
8use super::types::{Row, Schema};
9use sochdb_core::Result;
10
11pub struct FilterNode {
18 input: Box<dyn PlanNode>,
19 predicate: Expr,
20}
21
22impl FilterNode {
23 pub fn new(input: Box<dyn PlanNode>, predicate: Expr) -> Self {
24 Self { input, predicate }
25 }
26}
27
28impl PlanNode for FilterNode {
29 fn schema(&self) -> &Schema {
30 self.input.schema()
31 }
32
33 fn next(&mut self) -> Result<Option<Row>> {
34 loop {
35 match self.input.next()? {
36 Some(row) => {
37 if eval_predicate(&self.predicate, &row, self.input.schema())? {
38 return Ok(Some(row));
39 }
40 }
42 None => return Ok(None),
43 }
44 }
45 }
46
47 fn reset(&mut self) -> Result<()> {
48 self.input.reset()
49 }
50}