Build the configured [`FileStream`].
(self)
| 95 | |
| 96 | /// Build the configured [`FileStream`]. |
| 97 | pub fn build(self) -> Result<FileStream> { |
| 98 | let Self { |
| 99 | config, |
| 100 | partition, |
| 101 | morselizer, |
| 102 | metrics, |
| 103 | on_error, |
| 104 | shared_work_source, |
| 105 | } = self; |
| 106 | |
| 107 | let Some(partition) = partition else { |
| 108 | return internal_err!("FileStreamBuilder missing required partition"); |
| 109 | }; |
| 110 | let Some(morselizer) = morselizer else { |
| 111 | return internal_err!("FileStreamBuilder missing required morselizer"); |
| 112 | }; |
| 113 | let Some(metrics) = metrics else { |
| 114 | return internal_err!("FileStreamBuilder missing required metrics"); |
| 115 | }; |
| 116 | let projected_schema = config.projected_schema()?; |
| 117 | let Some(file_group) = config.file_groups.get(partition).cloned() else { |
| 118 | return internal_err!( |
| 119 | "FileStreamBuilder invalid partition index: {partition}" |
| 120 | ); |
| 121 | }; |
| 122 | let work_source = match shared_work_source { |
| 123 | Some(shared) => WorkSource::Shared(shared), |
| 124 | None => WorkSource::Local(file_group.into_inner().into()), |
| 125 | }; |
| 126 | |
| 127 | let file_stream_metrics = FileStreamMetrics::new(metrics, partition); |
| 128 | let scan_state = Box::new(ScanState::new( |
| 129 | work_source, |
| 130 | config.limit, |
| 131 | morselizer, |
| 132 | on_error, |
| 133 | file_stream_metrics, |
| 134 | )); |
| 135 | |
| 136 | Ok(FileStream { |
| 137 | projected_schema, |
| 138 | state: FileStreamState::Scan { scan_state }, |
| 139 | baseline_metrics: BaselineMetrics::new(metrics, partition), |
| 140 | }) |
| 141 | } |
| 142 | } |