vibesql_executor/select/iterator/
scan.rs

1//! Table scan iterator implementation
2
3use super::RowIterator;
4use crate::{errors::ExecutorError, schema::CombinedSchema};
5
6/// Iterator that scans rows from a materialized table
7///
8/// This is the simplest RowIterator - it wraps a `Vec<Row>` and produces
9/// rows one at a time. While the input is still materialized, this provides
10/// a uniform iterator interface for composition with other operators.
11///
12/// # Example
13///
14/// ```text
15/// let rows = vec![row1, row2, row3];
16/// let scan = TableScanIterator::new(schema, rows);
17/// for row in scan {
18///     println!("{:?}", row?);
19/// }
20/// ```
21pub struct TableScanIterator {
22    schema: CombinedSchema,
23    rows: std::vec::IntoIter<vibesql_storage::Row>,
24    #[allow(dead_code)]
25    total_count: usize,
26}
27
28impl TableScanIterator {
29    /// Create a new table scan iterator from a schema and materialized rows
30    ///
31    /// # Arguments
32    /// * `schema` - The schema describing the structure of rows
33    /// * `rows` - The rows to iterate over (consumed and moved)
34    pub fn new(schema: CombinedSchema, rows: Vec<vibesql_storage::Row>) -> Self {
35        let total_count = rows.len();
36        Self { schema, rows: rows.into_iter(), total_count }
37    }
38}
39
40impl Iterator for TableScanIterator {
41    type Item = Result<vibesql_storage::Row, ExecutorError>;
42
43    fn next(&mut self) -> Option<Self::Item> {
44        self.rows.next().map(Ok)
45    }
46
47    fn size_hint(&self) -> (usize, Option<usize>) {
48        self.rows.size_hint()
49    }
50}
51
52impl RowIterator for TableScanIterator {
53    fn schema(&self) -> &CombinedSchema {
54        &self.schema
55    }
56
57    fn row_size_hint(&self) -> (usize, Option<usize>) {
58        let (lower, upper) = self.size_hint();
59        (lower, upper)
60    }
61}