Skip to content

Apache DataFusion SQL Query Engine

ARROW-10215: [Rust] [DataFusion] Renamed Source to SendableRecordBatchReader.

Jorge C. Leitao5fa26048842d
diff --git a/rust/datafusion/src/physical_plan/common.rs b/rust/datafusion/src/physical_plan/common.rs
index a59bcc8256..2b1e76a6b3 100644
--- a/rust/datafusion/src/physical_plan/common.rs
+++ b/rust/datafusion/src/physical_plan/common.rs
@@ -21,7 +21,7 @@ use std::fs;
use std::fs::metadata;
use std::sync::Arc;
-use super::Source;
+use super::SendableRecordBatchReader;
use crate::error::{ExecutionError, Result};
use array::{
@@ -75,7 +75,7 @@ impl RecordBatchReader for RecordBatchIterator {
}
/// Create a vector of record batches from an iterator
-pub fn collect(it: Source) -> Result<Vec<RecordBatch>> {
+pub fn collect(it: SendableRecordBatchReader) -> Result<Vec<RecordBatch>> {
it.into_iter()
.collect::<ArrowResult<Vec<_>>>()
.map_err(|e| ExecutionError::from(e))
diff --git a/rust/datafusion/src/physical_plan/csv.rs b/rust/datafusion/src/physical_plan/csv.rs
index 4356417b89..32b7c26eb1 100644
--- a/rust/datafusion/src/physical_plan/csv.rs
+++ b/rust/datafusion/src/physical_plan/csv.rs
@@ -29,7 +29,7 @@ use arrow::datatypes::{Schema, SchemaRef};
use arrow::error::Result as ArrowResult;
use arrow::record_batch::{RecordBatch, RecordBatchReader};
-use super::Source;
+use super::SendableRecordBatchReader;
use async_trait::async_trait;
/// CSV file read option
@@ -218,7 +218,7 @@ impl ExecutionPlan for CsvExec {
}
}
- async fn execute(&self, partition: usize) -> Result<Source> {
+ async fn execute(&self, partition: usize) -> Result<SendableRecordBatchReader> {
Ok(Box::new(CsvIterator::try_new(
&self.filenames[partition],
self.schema.clone(),
diff --git a/rust/datafusion/src/physical_plan/empty.rs b/rust/datafusion/src/physical_plan/empty.rs
index 27c3fdc441..7e7019b878 100644
--- a/rust/datafusion/src/physical_plan/empty.rs
+++ b/rust/datafusion/src/physical_plan/empty.rs
@@ -25,7 +25,7 @@ use crate::physical_plan::memory::MemoryIterator;
use crate::physical_plan::{Distribution, ExecutionPlan, Partitioning};
use arrow::datatypes::SchemaRef;
-use super::Source;
+use super::SendableRecordBatchReader;
use async_trait::async_trait;
@@ -78,7 +78,7 @@ impl ExecutionPlan for EmptyExec {
}
}
- async fn execute(&self, partition: usize) -> Result<Source> {
+ async fn execute(&self, partition: usize) -> Result<SendableRecordBatchReader> {
// GlobalLimitExec has a single output partition
if 0 != partition {
return Err(ExecutionError::General(format!(
diff --git a/rust/datafusion/src/physical_plan/explain.rs b/rust/datafusion/src/physical_plan/explain.rs
index b5d92a5feb..34b824dbd5 100644
--- a/rust/datafusion/src/physical_plan/explain.rs
+++ b/rust/datafusion/src/physical_plan/explain.rs
@@ -29,7 +29,7 @@ use arrow::{array::StringBuilder, datatypes::SchemaRef, record_batch::RecordBatc
use crate::physical_plan::Partitioning;
-use super::Source;
+use super::SendableRecordBatchReader;
use async_trait::async_trait;
/// Explain execution plan operator. This operator contains the string
@@ -89,7 +89,7 @@ impl ExecutionPlan for ExplainExec {
}
}
- async fn execute(&self, partition: usize) -> Result<Source> {
+ async fn execute(&self, partition: usize) -> Result<SendableRecordBatchReader> {
if 0 != partition {
return Err(ExecutionError::General(format!(
"ExplainExec invalid partition {}",
diff --git a/rust/datafusion/src/physical_plan/filter.rs b/rust/datafusion/src/physical_plan/filter.rs
index 5c7f638420..b1e443aea2 100644
--- a/rust/datafusion/src/physical_plan/filter.rs
+++ b/rust/datafusion/src/physical_plan/filter.rs
@@ -21,7 +21,7 @@
use std::any::Any;
use std::sync::Arc;
-use super::Source;
+use super::SendableRecordBatchReader;
use crate::error::{ExecutionError, Result};
use crate::physical_plan::{ExecutionPlan, Partitioning, PhysicalExpr};
use arrow::array::BooleanArray;
@@ -98,7 +98,7 @@ impl ExecutionPlan for FilterExec {
}
}
- async fn execute(&self, partition: usize) -> Result<Source> {
+ async fn execute(&self, partition: usize) -> Result<SendableRecordBatchReader> {
Ok(Box::new(FilterExecIter {
schema: self.input.schema().clone(),
predicate: self.predicate.clone(),
@@ -115,7 +115,7 @@ struct FilterExecIter {
/// The expression to filter on. This expression must evaluate to a boolean value.
predicate: Arc<dyn PhysicalExpr>,
/// The input partition to filter.
- input: Source,
+ input: SendableRecordBatchReader,
}
impl Iterator for FilterExecIter {
diff --git a/rust/datafusion/src/physical_plan/hash_aggregate.rs b/rust/datafusion/src/physical_plan/hash_aggregate.rs
index adda633ff7..5f4fe9876b 100644
--- a/rust/datafusion/src/physical_plan/hash_aggregate.rs
+++ b/rust/datafusion/src/physical_plan/hash_aggregate.rs
@@ -40,7 +40,9 @@ use arrow::{
use fnv::FnvHashMap;
-use super::{common, expressions::Column, group_scalar::GroupByScalar, Source};
+use super::{
+ common, expressions::Column, group_scalar::GroupByScalar, SendableRecordBatchReader,
+};
use async_trait::async_trait;
@@ -145,7 +147,7 @@ impl ExecutionPlan for HashAggregateExec {
self.input.output_partitioning()
}
- async fn execute(&self, partition: usize) -> Result<Source> {
+ async fn execute(&self, partition: usize) -> Result<SendableRecordBatchReader> {
let input = self.input.execute(partition).await?;
let group_expr = self.group_expr.iter().map(|x| x.0.clone()).collect();
@@ -215,7 +217,7 @@ struct GroupedHashAggregateIterator {
schema: SchemaRef,
group_expr: Vec<Arc<dyn PhysicalExpr>>,
aggr_expr: Vec<Arc<dyn AggregateExpr>>,
- input: Source,
+ input: SendableRecordBatchReader,
finished: bool,
}
@@ -320,7 +322,7 @@ impl GroupedHashAggregateIterator {
schema: SchemaRef,
group_expr: Vec<Arc<dyn PhysicalExpr>>,
aggr_expr: Vec<Arc<dyn AggregateExpr>>,
- input: Source,
+ input: SendableRecordBatchReader,
) -> Self {
GroupedHashAggregateIterator {
mode,
@@ -463,7 +465,7 @@ struct HashAggregateIterator {
mode: AggregateMode,
schema: SchemaRef,
aggr_expr: Vec<Arc<dyn AggregateExpr>>,
- input: Source,
+ input: SendableRecordBatchReader,
finished: bool,
}
@@ -473,7 +475,7 @@ impl HashAggregateIterator {
mode: AggregateMode,
schema: SchemaRef,
aggr_expr: Vec<Arc<dyn AggregateExpr>>,
- input: Source,
+ input: SendableRecordBatchReader,
) -> Self {
HashAggregateIterator {
mode,
diff --git a/rust/datafusion/src/physical_plan/limit.rs b/rust/datafusion/src/physical_plan/limit.rs
index e10805c3d4..8c0e563b03 100644
--- a/rust/datafusion/src/physical_plan/limit.rs
+++ b/rust/datafusion/src/physical_plan/limit.rs
@@ -28,7 +28,7 @@ use arrow::compute::limit;
use arrow::datatypes::SchemaRef;
use arrow::record_batch::RecordBatch;
-use super::Source;
+use super::SendableRecordBatchReader;
use async_trait::async_trait;
@@ -94,7 +94,7 @@ impl ExecutionPlan for GlobalLimitExec {
}
}
- async fn execute(&self, partition: usize) -> Result<Source> {
+ async fn execute(&self, partition: usize) -> Result<SendableRecordBatchReader> {
// GlobalLimitExec has a single output partition
if 0 != partition {
return Err(ExecutionError::General(format!(
@@ -167,7 +167,7 @@ impl ExecutionPlan for LocalLimitExec {
}
}
- async fn execute(&self, _: usize) -> Result<Source> {
+ async fn execute(&self, _: usize) -> Result<SendableRecordBatchReader> {
let mut it = self.input.execute(0).await?;
Ok(Box::new(MemoryIterator::try_new(
collect_with_limit(&mut it, self.limit)?,
@@ -190,7 +190,10 @@ pub fn truncate_batch(batch: &RecordBatch, n: usize) -> Result<RecordBatch> {
}
/// Create a vector of record batches from an iterator
-fn collect_with_limit(reader: &mut Source, limit: usize) -> Result<Vec<RecordBatch>> {
+fn collect_with_limit(
+ reader: &mut SendableRecordBatchReader,
+ limit: usize,
+) -> Result<Vec<RecordBatch>> {
let mut count = 0;
let mut results: Vec<RecordBatch> = vec![];
loop {
diff --git a/rust/datafusion/src/physical_plan/memory.rs b/rust/datafusion/src/physical_plan/memory.rs
index 79f213231f..6219eb3139 100644
--- a/rust/datafusion/src/physical_plan/memory.rs
+++ b/rust/datafusion/src/physical_plan/memory.rs
@@ -26,7 +26,7 @@ use arrow::datatypes::SchemaRef;
use arrow::error::Result as ArrowResult;
use arrow::record_batch::{RecordBatch, RecordBatchReader};
-use super::Source;
+use super::SendableRecordBatchReader;
use async_trait::async_trait;
/// Execution plan for reading in-memory batches of data
@@ -72,7 +72,7 @@ impl ExecutionPlan for MemoryExec {
)))
}
- async fn execute(&self, partition: usize) -> Result<Source> {
+ async fn execute(&self, partition: usize) -> Result<SendableRecordBatchReader> {
Ok(Box::new(MemoryIterator::try_new(
self.partitions[partition].clone(),
self.schema.clone(),
diff --git a/rust/datafusion/src/physical_plan/merge.rs b/rust/datafusion/src/physical_plan/merge.rs
index 1a2357e543..02243bc7cc 100644
--- a/rust/datafusion/src/physical_plan/merge.rs
+++ b/rust/datafusion/src/physical_plan/merge.rs
@@ -29,7 +29,7 @@ use crate::physical_plan::{common, ExecutionPlan};
use arrow::datatypes::SchemaRef;
use arrow::record_batch::RecordBatch;
-use super::Source;
+use super::SendableRecordBatchReader;
use async_trait::async_trait;
use tokio::task::{self, JoinHandle};
@@ -89,7 +89,7 @@ impl ExecutionPlan for MergeExec {
}
}
- async fn execute(&self, partition: usize) -> Result<Source> {
+ async fn execute(&self, partition: usize) -> Result<SendableRecordBatchReader> {
// MergeExec produces a single partition
if 0 != partition {
return Err(ExecutionError::General(format!(
diff --git a/rust/datafusion/src/physical_plan/mod.rs b/rust/datafusion/src/physical_plan/mod.rs
index 79696f83b7..ac33c67f6a 100644
--- a/rust/datafusion/src/physical_plan/mod.rs
+++ b/rust/datafusion/src/physical_plan/mod.rs
@@ -31,7 +31,7 @@ use arrow::record_batch::{RecordBatch, RecordBatchReader};
use arrow::{array::ArrayRef, datatypes::Field};
use async_trait::async_trait;
-type Source = Box<dyn RecordBatchReader + Send>;
+type SendableRecordBatchReader = Box<dyn RecordBatchReader + Send>;
/// Physical query planner that converts a `LogicalPlan` to an
/// `ExecutionPlan` suitable for execution.
@@ -70,7 +70,7 @@ pub trait ExecutionPlan: Debug + Send + Sync {
) -> Result<Arc<dyn ExecutionPlan>>;
/// creates an iterator
- async fn execute(&self, partition: usize) -> Result<Source>;
+ async fn execute(&self, partition: usize) -> Result<SendableRecordBatchReader>;
}
/// Partitioning schemes supported by operators.
diff --git a/rust/datafusion/src/physical_plan/parquet.rs b/rust/datafusion/src/physical_plan/parquet.rs
index 6b6d475160..b15c5a36f3 100644
--- a/rust/datafusion/src/physical_plan/parquet.rs
+++ b/rust/datafusion/src/physical_plan/parquet.rs
@@ -35,7 +35,7 @@ use crossbeam::channel::{bounded, Receiver, RecvError, Sender};
use fmt::Debug;
use parquet::arrow::{ArrowReader, ParquetFileArrowReader};
-use super::Source;
+use super::SendableRecordBatchReader;
use async_trait::async_trait;
/// Execution plan for scanning a Parquet file
@@ -125,7 +125,7 @@ impl ExecutionPlan for ParquetExec {
}
}
- async fn execute(&self, partition: usize) -> Result<Source> {
+ async fn execute(&self, partition: usize) -> Result<SendableRecordBatchReader> {
// because the parquet implementation is not thread-safe, it is necessary to execute
// on a thread and communicate with channels
let (response_tx, response_rx): (
diff --git a/rust/datafusion/src/physical_plan/planner.rs b/rust/datafusion/src/physical_plan/planner.rs
index 663d756695..bdaf79c7b2 100644
--- a/rust/datafusion/src/physical_plan/planner.rs
+++ b/rust/datafusion/src/physical_plan/planner.rs
@@ -556,7 +556,7 @@ mod tests {
use crate::physical_plan::{csv::CsvReadOptions, expressions, Partitioning};
use crate::{
logical_plan::{col, lit, sum, LogicalPlanBuilder},
- physical_plan::Source,
+ physical_plan::SendableRecordBatchReader,
};
use crate::{prelude::ExecutionConfig, test::arrow_testdata_path};
use arrow::datatypes::{DataType, Field, SchemaRef};
@@ -807,7 +807,7 @@ mod tests {
unimplemented!("NoOpExecutionPlan::with_new_children");
}
- async fn execute(&self, _partition: usize) -> Result<Source> {
+ async fn execute(&self, _partition: usize) -> Result<SendableRecordBatchReader> {
unimplemented!("NoOpExecutionPlan::execute");
}
}
diff --git a/rust/datafusion/src/physical_plan/projection.rs b/rust/datafusion/src/physical_plan/projection.rs
index dc3e0799d1..bb8f853a29 100644
--- a/rust/datafusion/src/physical_plan/projection.rs
+++ b/rust/datafusion/src/physical_plan/projection.rs
@@ -29,7 +29,7 @@ use arrow::datatypes::{Field, Schema, SchemaRef};
use arrow::error::Result as ArrowResult;
use arrow::record_batch::{RecordBatch, RecordBatchReader};
-use super::Source;
+use super::SendableRecordBatchReader;
use async_trait::async_trait;
/// Execution plan for a projection
@@ -108,7 +108,7 @@ impl ExecutionPlan for ProjectionExec {
}
}
- async fn execute(&self, partition: usize) -> Result<Source> {
+ async fn execute(&self, partition: usize) -> Result<SendableRecordBatchReader> {
Ok(Box::new(ProjectionIterator {
schema: self.schema.clone(),
expr: self.expr.iter().map(|x| x.0.clone()).collect(),
@@ -121,7 +121,7 @@ impl ExecutionPlan for ProjectionExec {
struct ProjectionIterator {
schema: SchemaRef,
expr: Vec<Arc<dyn PhysicalExpr>>,
- input: Source,
+ input: SendableRecordBatchReader,
}
impl Iterator for ProjectionIterator {
diff --git a/rust/datafusion/src/physical_plan/sort.rs b/rust/datafusion/src/physical_plan/sort.rs
index 0eb3b08894..3ddfa18311 100644
--- a/rust/datafusion/src/physical_plan/sort.rs
+++ b/rust/datafusion/src/physical_plan/sort.rs
@@ -31,7 +31,7 @@ use crate::physical_plan::common::RecordBatchIterator;
use crate::physical_plan::expressions::PhysicalSortExpr;
use crate::physical_plan::{common, Distribution, ExecutionPlan, Partitioning};
-use super::Source;
+use super::SendableRecordBatchReader;
use async_trait::async_trait;
/// Sort execution plan
@@ -100,7 +100,7 @@ impl ExecutionPlan for SortExec {
}
}
- async fn execute(&self, partition: usize) -> Result<Source> {
+ async fn execute(&self, partition: usize) -> Result<SendableRecordBatchReader> {
if 0 != partition {
return Err(ExecutionError::General(format!(
"SortExec invalid partition {}",