MCPcopy Create free account
hub / github.com/apache/datafusion / benchmark_query

Method benchmark_query

benchmarks/src/smj.rs:581–622  ·  view source on GitHub ↗
(
        &self,
        sql: &str,
        query_name: &str,
        expect_mark: bool,
        ctx: &SessionContext,
    )

Source from the content-addressed store, hash-verified

579 }
580
581 async fn benchmark_query(
582 &self,
583 sql: &str,
584 query_name: &str,
585 expect_mark: bool,
586 ctx: &SessionContext,
587 ) -> Result<Vec<QueryResult>> {
588 let mut query_results = vec![];
589
590 // Validate that the query plan includes a Sort Merge Join
591 let df = ctx.sql(sql).await?;
592 let physical_plan = df.create_physical_plan().await?;
593 let plan_string = format!("{physical_plan:#?}");
594
595 if !plan_string.contains("SortMergeJoinExec") {
596 return Err(exec_datafusion_err!(
597 "Query {query_name} does not use Sort Merge Join. Physical plan: {plan_string}"
598 ));
599 }
600
601 if expect_mark && !plan_string.contains("LeftMark") {
602 return Err(exec_datafusion_err!(
603 "Query {query_name} expected LeftMark join. Physical plan: {plan_string}"
604 ));
605 }
606
607 for i in 0..self.common.iterations {
608 let start = Instant::now();
609
610 let row_count = Self::execute_sql_without_result_buffering(sql, ctx).await?;
611
612 let elapsed = start.elapsed();
613
614 println!(
615 "Query {query_name} iteration {i} returned {row_count} rows in {elapsed:?}"
616 );
617
618 query_results.push(QueryResult { elapsed, row_count });
619 }
620
621 Ok(query_results)
622 }
623
624 /// Executes the SQL query and drops each result batch after evaluation, to
625 /// minimizes memory usage by not buffering results.

Callers 1

runMethod · 0.45

Calls 4

sqlMethod · 0.80
create_physical_planMethod · 0.45
containsMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected