vibesql_executor/select/iterator/
scan.rs

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