| 94 | } |
| 95 | |
| 96 | async fn scan( |
| 97 | &self, |
| 98 | _state: &dyn Session, |
| 99 | projection: Option<&Vec<usize>>, |
| 100 | _filters: &[Expr], |
| 101 | _limit: Option<usize>, |
| 102 | ) -> Result<Arc<dyn ExecutionPlan>> { |
| 103 | let batches = if let Some(max_return_lines) = self.limit { |
| 104 | // get max return rows from self.batches |
| 105 | let mut batches = vec![]; |
| 106 | let mut lines = 0; |
| 107 | for batch in &self.batches { |
| 108 | let batch_lines = batch.num_rows(); |
| 109 | if lines + batch_lines > max_return_lines { |
| 110 | let batch_lines = max_return_lines - lines; |
| 111 | batches.push(batch.slice(0, batch_lines)); |
| 112 | break; |
| 113 | } else { |
| 114 | batches.push(batch.clone()); |
| 115 | lines += batch_lines; |
| 116 | } |
| 117 | } |
| 118 | batches |
| 119 | } else { |
| 120 | self.batches.clone() |
| 121 | }; |
| 122 | Ok(MemorySourceConfig::try_new_exec( |
| 123 | &[batches], |
| 124 | TableProvider::schema(self), |
| 125 | projection.cloned(), |
| 126 | )?) |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | #[derive(Debug)] |