Apache DataFusion SQL Query Engine
refine test in repartition.rs & coalesce_batches.rs (#1707)
xudong.w75c7578cd2d5
diff --git a/datafusion/src/physical_plan/coalesce_batches.rs b/datafusion/src/physical_plan/coalesce_batches.rsindex 586b05219b..ec238ad68c 100644--- a/datafusion/src/physical_plan/coalesce_batches.rs+++ b/datafusion/src/physical_plan/coalesce_batches.rs@@ -295,9 +295,8 @@ pub fn concat_batches(#[cfg(test)]mod tests {use super::*;- use crate::from_slice::FromSlice;use crate::physical_plan::{memory::MemoryExec, repartition::RepartitionExec};- use arrow::array::UInt32Array;+ use crate::test::create_vec_batches;use arrow::datatypes::{DataType, Field, Schema};#[tokio::test(flavor = "multi_thread")]@@ -325,23 +324,6 @@ mod tests {Arc::new(Schema::new(vec![Field::new("c0", DataType::UInt32, false)]))}- fn create_vec_batches(schema: &Arc<Schema>, num_batches: usize) -> Vec<RecordBatch> {- let batch = create_batch(schema);- let mut vec = Vec::with_capacity(num_batches);- for _ in 0..num_batches {- vec.push(batch.clone());- }- vec- }-- fn create_batch(schema: &Arc<Schema>) -> RecordBatch {- RecordBatch::try_new(- schema.clone(),- vec![Arc::new(UInt32Array::from_slice(&[1, 2, 3, 4, 5, 6, 7, 8]))],- )- .unwrap()- }-async fn coalesce_batches(schema: &SchemaRef,input_partitions: Vec<Vec<RecordBatch>>,diff --git a/datafusion/src/physical_plan/mod.rs b/datafusion/src/physical_plan/mod.rsindex 216d4a65e6..24aa6ad383 100644--- a/datafusion/src/physical_plan/mod.rs+++ b/datafusion/src/physical_plan/mod.rs@@ -59,7 +59,7 @@ pub type SendableRecordBatchStream = Pin<Box<dyn RecordBatchStream + Send + Sync/// EmptyRecordBatchStream can be used to create a RecordBatchStream/// that will produce no resultspub struct EmptyRecordBatchStream {- /// Schema+ /// Schema wrapped by Arcschema: SchemaRef,}@@ -384,9 +384,7 @@ impl Partitioning {pub fn partition_count(&self) -> usize {use Partitioning::*;match self {- RoundRobinBatch(n) => *n,- Hash(_, n) => *n,- UnknownPartitioning(n) => *n,+ RoundRobinBatch(n) | Hash(_, n) | UnknownPartitioning(n) => *n,}}}diff --git a/datafusion/src/physical_plan/planner.rs b/datafusion/src/physical_plan/planner.rsindex 2dcde9d113..226e3f3924 100644--- a/datafusion/src/physical_plan/planner.rs+++ b/datafusion/src/physical_plan/planner.rs@@ -226,9 +226,9 @@ pub trait PhysicalPlanner {////// `expr`: the expression to convert///- /// `input_dfschema`: the logical plan schema for evaluating `e`+ /// `input_dfschema`: the logical plan schema for evaluating `expr`///- /// `input_schema`: the physical schema for evaluating `e`+ /// `input_schema`: the physical schema for evaluating `expr`fn create_physical_expr(&self,expr: &Expr,diff --git a/datafusion/src/physical_plan/repartition.rs b/datafusion/src/physical_plan/repartition.rsindex 746075429a..86866728cd 100644--- a/datafusion/src/physical_plan/repartition.rs+++ b/datafusion/src/physical_plan/repartition.rs@@ -447,7 +447,7 @@ struct RepartitionStream {/// Number of input partitions that have finished sending batches to this output channelnum_input_partitions_processed: usize,- /// Schema+ /// Schema wrapped by Arcschema: SchemaRef,/// channel containing the repartitioned batches@@ -494,6 +494,7 @@ impl RecordBatchStream for RepartitionStream {mod tests {use super::*;use crate::from_slice::FromSlice;+ use crate::test::create_vec_batches;use crate::{assert_batches_sorted_eq,physical_plan::{collect, expressions::col, memory::MemoryExec},@@ -508,7 +509,7 @@ mod tests {use arrow::datatypes::{DataType, Field, Schema};use arrow::record_batch::RecordBatch;use arrow::{- array::{ArrayRef, StringArray, UInt32Array},+ array::{ArrayRef, StringArray},error::ArrowError,};use futures::FutureExt;@@ -601,23 +602,6 @@ mod tests {Arc::new(Schema::new(vec![Field::new("c0", DataType::UInt32, false)]))}- fn create_vec_batches(schema: &Arc<Schema>, n: usize) -> Vec<RecordBatch> {- let batch = create_batch(schema);- let mut vec = Vec::with_capacity(n);- for _ in 0..n {- vec.push(batch.clone());- }- vec- }-- fn create_batch(schema: &Arc<Schema>) -> RecordBatch {- RecordBatch::try_new(- schema.clone(),- vec![Arc::new(UInt32Array::from_slice(&[1, 2, 3, 4, 5, 6, 7, 8]))],- )- .unwrap()- }-async fn repartition(schema: &SchemaRef,input_partitions: Vec<Vec<RecordBatch>>,diff --git a/datafusion/src/test/mod.rs b/datafusion/src/test/mod.rsindex 497bfe59e1..cebd9ee02d 100644--- a/datafusion/src/test/mod.rs+++ b/datafusion/src/test/mod.rs@@ -17,6 +17,7 @@//! Common unit test utility methods+use crate::arrow::array::UInt32Array;use crate::datasource::object_store::local::local_unpartitioned_file;use crate::datasource::{MemTable, PartitionedFile, TableProvider};use crate::error::Result;@@ -212,6 +213,25 @@ pub fn assert_is_pending<'a, T>(fut: &mut Pin<Box<dyn Future<Output = T> + Sendassert!(poll.is_pending());}+/// Create vector batches+pub fn create_vec_batches(schema: &Arc<Schema>, n: usize) -> Vec<RecordBatch> {+ let batch = create_batch(schema);+ let mut vec = Vec::with_capacity(n);+ for _ in 0..n {+ vec.push(batch.clone());+ }+ vec+}++/// Create batch+fn create_batch(schema: &Arc<Schema>) -> RecordBatch {+ RecordBatch::try_new(+ schema.clone(),+ vec![Arc::new(UInt32Array::from_slice(&[1, 2, 3, 4, 5, 6, 7, 8]))],+ )+ .unwrap()+}+pub mod exec;pub mod object_store;pub mod user_defined;