(&self, ctx: &SessionContext, sql: &str)
| 279 | } |
| 280 | |
| 281 | async fn execute_query(&self, ctx: &SessionContext, sql: &str) -> Result<usize> { |
| 282 | let debug = self.common.debug; |
| 283 | let plan = ctx.sql(sql).await?; |
| 284 | let (state, plan) = plan.into_parts(); |
| 285 | |
| 286 | if debug { |
| 287 | println!("=== Logical plan ===\n{plan}\n"); |
| 288 | } |
| 289 | |
| 290 | let plan = state.optimize(&plan)?; |
| 291 | if debug { |
| 292 | println!("=== Optimized logical plan ===\n{plan}\n"); |
| 293 | } |
| 294 | let physical_plan = state.create_physical_plan(&plan).await?; |
| 295 | if debug { |
| 296 | println!( |
| 297 | "=== Physical plan ===\n{}\n", |
| 298 | displayable(physical_plan.as_ref()).indent(true) |
| 299 | ); |
| 300 | } |
| 301 | |
| 302 | let mut row_count = 0; |
| 303 | |
| 304 | let mut stream = execute_stream(physical_plan.clone(), state.task_ctx())?; |
| 305 | while let Some(batch) = stream.next().await { |
| 306 | row_count += batch?.num_rows(); |
| 307 | } |
| 308 | |
| 309 | if debug { |
| 310 | println!( |
| 311 | "=== Physical plan with metrics ===\n{}\n", |
| 312 | DisplayableExecutionPlan::with_metrics(physical_plan.as_ref()) |
| 313 | .indent(true) |
| 314 | ); |
| 315 | } |
| 316 | |
| 317 | Ok(row_count) |
| 318 | } |
| 319 | |
| 320 | async fn get_table( |
| 321 | &self, |
no test coverage detected