Initializes the benchmark by executing `load` and `init` queries. Registers any required tables or sets up state in the provided `SessionContext` before running queries. This method is idempotent: calling it multiple times on the same instance returns immediately after the first successful initialization. # Errors Returns an error if any `load` or `init` query fails, or if the benchmark file do
(&mut self, ctx: &SessionContext)
| 115 | /// Returns an error if any `load` or `init` query fails, or if the |
| 116 | /// benchmark file does not contain a `run` query. |
| 117 | pub async fn initialize(&mut self, ctx: &SessionContext) -> Result<()> { |
| 118 | if self.is_loaded { |
| 119 | return Ok(()); |
| 120 | } |
| 121 | |
| 122 | let path = self.benchmark_path.to_string_lossy().into_owned(); |
| 123 | |
| 124 | // validate there was a run query |
| 125 | if !self.queries.contains_key(&QueryDirective::Run) { |
| 126 | return Err(exec_datafusion_err!( |
| 127 | "Invalid benchmark file: no \"run\" query specified: {path}" |
| 128 | )); |
| 129 | } |
| 130 | |
| 131 | // display any echo's |
| 132 | self.echo.iter().for_each(|txt| println!("{txt}")); |
| 133 | |
| 134 | let load_queries = self.queries.get(&QueryDirective::Load); |
| 135 | |
| 136 | if let Some(queries) = load_queries { |
| 137 | for query in queries { |
| 138 | debug!("Executing load query {query}"); |
| 139 | ctx.sql(query).await?.collect().await?; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | let init_queries = self.queries.get(&QueryDirective::Init); |
| 144 | |
| 145 | if let Some(queries) = init_queries { |
| 146 | for query in queries { |
| 147 | debug!("Executing init query {query}"); |
| 148 | ctx.sql(query).await?.collect().await?; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | self.is_loaded = true; |
| 153 | |
| 154 | Ok(()) |
| 155 | } |
| 156 | |
| 157 | /// Executes the `assert` queries and compares actual results against |
| 158 | /// expected values. |
no test coverage detected