Apply a WHERE predicate to filter rows.
(
rows: &[BindingRow],
predicate: &WherePredicate,
csr: &CsrIndex,
edge_store: &EdgeStore,
_frontier_bitmap: Option<&nodedb_types::SurrogateBitmap>,
)
| 9 | |
| 10 | /// Apply a WHERE predicate to filter rows. |
| 11 | pub(super) fn apply_predicate( |
| 12 | rows: &[BindingRow], |
| 13 | predicate: &WherePredicate, |
| 14 | csr: &CsrIndex, |
| 15 | edge_store: &EdgeStore, |
| 16 | _frontier_bitmap: Option<&nodedb_types::SurrogateBitmap>, |
| 17 | ) -> Result<Vec<BindingRow>, crate::Error> { |
| 18 | match predicate { |
| 19 | WherePredicate::Equals { |
| 20 | binding, |
| 21 | field, |
| 22 | value, |
| 23 | } => { |
| 24 | if field.is_empty() { |
| 25 | Ok(rows |
| 26 | .iter() |
| 27 | .filter(|row| row.get(binding).is_some_and(|v| v == value)) |
| 28 | .cloned() |
| 29 | .collect()) |
| 30 | } else { |
| 31 | Ok(rows |
| 32 | .iter() |
| 33 | .filter(|row| { |
| 34 | if let Some(node_id) = row.get(binding) { |
| 35 | check_property(edge_store, node_id, field, value) |
| 36 | } else { |
| 37 | false |
| 38 | } |
| 39 | }) |
| 40 | .cloned() |
| 41 | .collect()) |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | WherePredicate::Comparison { |
| 46 | binding, |
| 47 | field, |
| 48 | op, |
| 49 | value, |
| 50 | } => { |
| 51 | let _ = (binding, field, op, value); |
| 52 | Ok(rows.to_vec()) |
| 53 | } |
| 54 | |
| 55 | WherePredicate::NotExists { sub_pattern } => { |
| 56 | let mut result = Vec::new(); |
| 57 | // NOT EXISTS sub-patterns run in their own local state: any |
| 58 | // truncation inside the sub-query would make the anti-join |
| 59 | // unsound (a truncated "empty" isn't really empty), so we |
| 60 | // instead propagate truncation to the outer query via the |
| 61 | // top-level `ExecutionState` that the caller of |
| 62 | // `apply_predicate` already tracks. Here we keep a throwaway |
| 63 | // local state and inspect it. |
| 64 | for row in rows { |
| 65 | let mut sub_state = ExecutionState::default(); |
| 66 | // NOT EXISTS sub-patterns check structural connectivity |
| 67 | // against already-bound variables — no anchor enumeration |
| 68 | // occurs, so the frontier bitmap does not apply here. |
no test coverage detected