Apache DataFusion SQL Query Engine
ARROW-11476: [Rust][DataFusion] Test running of TPCH benchmarks in CI
Heres, Daniel3e8ecd74104e
diff --git a/rust/benchmarks/src/bin/tpch.rs b/rust/benchmarks/src/bin/tpch.rsindex 593d75c9c9..90b7de5827 100644--- a/rust/benchmarks/src/bin/tpch.rs+++ b/rust/benchmarks/src/bin/tpch.rs@@ -179,7 +179,6 @@ async fn benchmark(opt: BenchmarkOpt) -> Result<Vec<arrow::record_batch::RecordBfn create_logical_plan(ctx: &mut ExecutionContext, query: usize) -> Result<LogicalPlan> {match query {-// original// 1 => ctx.create_logical_plan(// "select@@ -271,7 +270,7 @@ fn create_logical_plan(ctx: &mut ExecutionContext, query: usize) -> Result<Logics_acctbal desc,n_name,s_name,- p_partkey;"+ p_partkey;",),3 => ctx.create_logical_plan(@@ -296,7 +295,7 @@ fn create_logical_plan(ctx: &mut ExecutionContext, query: usize) -> Result<Logico_shippriorityorder byrevenue desc,- o_orderdate;"+ o_orderdate;",),4 => ctx.create_logical_plan(@@ -320,7 +319,7 @@ fn create_logical_plan(ctx: &mut ExecutionContext, query: usize) -> Result<Logicgroup byo_orderpriorityorder by- o_orderpriority;"+ o_orderpriority;",),// original@@ -374,7 +373,7 @@ fn create_logical_plan(ctx: &mut ExecutionContext, query: usize) -> Result<Logicgroup byn_nameorder by- revenue desc;"+ revenue desc;",),// original@@ -398,7 +397,7 @@ fn create_logical_plan(ctx: &mut ExecutionContext, query: usize) -> Result<Logicl_shipdate >= date '1994-01-01'and l_shipdate < date '1995-01-01'and l_discount between 0.06 - 0.01 and 0.06 + 0.01- and l_quantity < 24;"+ and l_quantity < 24;",),7 => ctx.create_logical_plan(@@ -440,7 +439,7 @@ fn create_logical_plan(ctx: &mut ExecutionContext, query: usize) -> Result<Logicorder bysupp_nation,cust_nation,- l_year;"+ l_year;",),8 => ctx.create_logical_plan(@@ -480,7 +479,7 @@ fn create_logical_plan(ctx: &mut ExecutionContext, query: usize) -> Result<Logicgroup byo_yearorder by- o_year;"+ o_year;",),9 => ctx.create_logical_plan(@@ -515,7 +514,7 @@ fn create_logical_plan(ctx: &mut ExecutionContext, query: usize) -> Result<Logico_yearorder bynation,- o_year desc;"+ o_year desc;",),// 10 => ctx.create_logical_plan(@@ -582,7 +581,7 @@ fn create_logical_plan(ctx: &mut ExecutionContext, query: usize) -> Result<Logicc_address,c_commentorder by- revenue desc;"+ revenue desc;",),11 => ctx.create_logical_plan(@@ -612,7 +611,7 @@ fn create_logical_plan(ctx: &mut ExecutionContext, query: usize) -> Result<Logicand n_name = 'GERMANY')order by- value desc;"+ value desc;",),// original@@ -676,7 +675,7 @@ fn create_logical_plan(ctx: &mut ExecutionContext, query: usize) -> Result<Logicgroup byl_shipmodeorder by- l_shipmode;"+ l_shipmode;",),13 => ctx.create_logical_plan(@@ -699,7 +698,7 @@ fn create_logical_plan(ctx: &mut ExecutionContext, query: usize) -> Result<Logicc_countorder bycustdist desc,- c_count desc;"+ c_count desc;",),14 => ctx.create_logical_plan(@@ -715,7 +714,7 @@ fn create_logical_plan(ctx: &mut ExecutionContext, query: usize) -> Result<Logicwherel_partkey = p_partkeyand l_shipdate >= date '1995-09-01'- and l_shipdate < date '1995-10-01';"+ and l_shipdate < date '1995-10-01';",),15 => ctx.create_logical_plan(@@ -751,7 +750,7 @@ fn create_logical_plan(ctx: &mut ExecutionContext, query: usize) -> Result<Logicorder bys_suppkey;- drop view revenue0;"+ drop view revenue0;",),16 => ctx.create_logical_plan(@@ -784,7 +783,7 @@ fn create_logical_plan(ctx: &mut ExecutionContext, query: usize) -> Result<Logicsupplier_cnt desc,p_brand,p_type,- p_size;"+ p_size;",),17 => ctx.create_logical_plan(@@ -804,7 +803,7 @@ fn create_logical_plan(ctx: &mut ExecutionContext, query: usize) -> Result<Logiclineitemwherel_partkey = p_partkey- );"+ );",),18 => ctx.create_logical_plan(@@ -839,7 +838,7 @@ fn create_logical_plan(ctx: &mut ExecutionContext, query: usize) -> Result<Logico_totalpriceorder byo_totalprice desc,- o_orderdate;"+ o_orderdate;",),19 => ctx.create_logical_plan(@@ -877,7 +876,7 @@ fn create_logical_plan(ctx: &mut ExecutionContext, query: usize) -> Result<Logicand p_size between 1 and 15and l_shipmode in ('AIR', 'AIR REG')and l_shipinstruct = 'DELIVER IN PERSON'- );"+ );",),20 => ctx.create_logical_plan(@@ -917,7 +916,7 @@ fn create_logical_plan(ctx: &mut ExecutionContext, query: usize) -> Result<Logicand s_nationkey = n_nationkeyand n_name = 'CANADA'order by- s_name;"+ s_name;",),21 => ctx.create_logical_plan(@@ -959,7 +958,7 @@ fn create_logical_plan(ctx: &mut ExecutionContext, query: usize) -> Result<Logics_nameorder bynumwait desc,- s_name;"+ s_name;",),22 => ctx.create_logical_plan(@@ -999,7 +998,7 @@ fn create_logical_plan(ctx: &mut ExecutionContext, query: usize) -> Result<Logicgroup bycntrycodeorder by- cntrycode;"+ cntrycode;",),_ => unimplemented!("invalid query. Expected value between 1 and 22"),@@ -1351,6 +1350,41 @@ mod tests {verify_query(22).await}+ #[tokio::test]+ async fn run_q1() -> Result<()> {+ run_query(1).await+ }++ #[tokio::test]+ async fn run_q3() -> Result<()> {+ run_query(3).await+ }++ #[tokio::test]+ async fn run_q5() -> Result<()> {+ run_query(5).await+ }++ #[tokio::test]+ async fn run_q6() -> Result<()> {+ run_query(6).await+ }++ #[tokio::test]+ async fn run_q10() -> Result<()> {+ run_query(10).await+ }++ #[tokio::test]+ async fn run_q12() -> Result<()> {+ run_query(12).await+ }++ #[tokio::test]+ async fn run_q14() -> Result<()> {+ run_query(14).await+ }+/// Specialised String representationfn col_str(column: &ArrayRef, row_index: usize) -> String {if column.is_null(row_index) {@@ -1562,6 +1596,29 @@ mod tests {)}+ async fn run_query(n: usize) -> Result<()> {+ // Tests running query with empty tables, to see whether they run succesfully.++ let config = ExecutionConfig::new()+ .with_concurrency(1)+ .with_batch_size(10);+ let mut ctx = ExecutionContext::with_config(config);++ for &table in TABLES {+ let schema = get_schema(table);+ let batch = RecordBatch::new_empty(Arc::new(schema.to_owned()));++ let provider = MemTable::try_new(Arc::new(schema), vec![vec![batch]])?;++ ctx.register_table(table, Box::new(provider));+ }++ let plan = create_logical_plan(&mut ctx, n)?;+ execute_query(&mut ctx, &plan, false).await?;++ Ok(())+ }+async fn verify_query(n: usize) -> Result<()> {if let Ok(path) = env::var("TPCH_DATA") {// load expected answers from tpch-dbgendiff --git a/rust/datafusion/src/physical_plan/coalesce_batches.rs b/rust/datafusion/src/physical_plan/coalesce_batches.rsindex 812a80477c..472b10a6a8 100644--- a/rust/datafusion/src/physical_plan/coalesce_batches.rs+++ b/rust/datafusion/src/physical_plan/coalesce_batches.rs@@ -210,6 +210,9 @@ pub fn concat_batches(batches: &[RecordBatch],row_count: usize,) -> ArrowResult<RecordBatch> {+ if batches.is_empty() {+ return Ok(RecordBatch::new_empty(schema.clone()));+ }let mut arrays = Vec::with_capacity(schema.fields().len());for i in 0..schema.fields().len() {let array = concat(diff --git a/rust/datafusion/src/physical_plan/hash_join.rs b/rust/datafusion/src/physical_plan/hash_join.rsindex ef1f450619..abec10d7fc 100644--- a/rust/datafusion/src/physical_plan/hash_join.rs+++ b/rust/datafusion/src/physical_plan/hash_join.rs@@ -261,7 +261,7 @@ impl ExecutionPlan for HashJoinExec {// Merge all batches into a single batch, so we// can directly index into the arrayslet single_batch =- concat_batches(&batches[0].schema(), &batches, num_rows)?;+ concat_batches(&self.left.schema(), &batches, num_rows)?;let left_side = Arc::new((hashmap, single_batch));