Skip to content

Apache DataFusion SQL Query Engine

ARROW-10854: [Rust] [DataFusion] Simplify logical plan scans

Jorge C. Leitaoc52ea0347ddb
diff --git a/rust/datafusion/benches/aggregate_query_sql.rs b/rust/datafusion/benches/aggregate_query_sql.rs
index 3309b0ceb0..0c6b1cf7b0 100644
--- a/rust/datafusion/benches/aggregate_query_sql.rs
+++ b/rust/datafusion/benches/aggregate_query_sql.rs
@@ -149,7 +149,7 @@ fn create_context(
let mut ctx = ExecutionContext::new();
// declare a table in memory. In spark API, this corresponds to createDataFrame(...).
- let provider = MemTable::new(schema, partitions)?;
+ let provider = MemTable::try_new(schema, partitions)?;
ctx.register_table("t", Box::new(provider));
Ok(Arc::new(Mutex::new(ctx)))
diff --git a/rust/datafusion/benches/filter_query_sql.rs b/rust/datafusion/benches/filter_query_sql.rs
index 7c7f6f887c..d6d61e4f51 100644
--- a/rust/datafusion/benches/filter_query_sql.rs
+++ b/rust/datafusion/benches/filter_query_sql.rs
@@ -61,7 +61,7 @@ fn create_context(array_len: usize, batch_size: usize) -> Result<ExecutionContex
let mut ctx = ExecutionContext::new();
// declare a table in memory. In spark API, this corresponds to createDataFrame(...).
- let provider = MemTable::new(schema, vec![batches])?;
+ let provider = MemTable::try_new(schema, vec![batches])?;
ctx.register_table("t", Box::new(provider));
Ok(ctx)
diff --git a/rust/datafusion/benches/math_query_sql.rs b/rust/datafusion/benches/math_query_sql.rs
index 65f613b6cd..04ed29c7fe 100644
--- a/rust/datafusion/benches/math_query_sql.rs
+++ b/rust/datafusion/benches/math_query_sql.rs
@@ -71,7 +71,7 @@ fn create_context(
let mut ctx = ExecutionContext::new();
// declare a table in memory. In spark API, this corresponds to createDataFrame(...).
- let provider = MemTable::new(schema, vec![batches])?;
+ let provider = MemTable::try_new(schema, vec![batches])?;
ctx.register_table("t", Box::new(provider));
Ok(Arc::new(Mutex::new(ctx)))
diff --git a/rust/datafusion/examples/dataframe_in_memory.rs b/rust/datafusion/examples/dataframe_in_memory.rs
index 5f5a3d272e..6923b808f8 100644
--- a/rust/datafusion/examples/dataframe_in_memory.rs
+++ b/rust/datafusion/examples/dataframe_in_memory.rs
@@ -49,7 +49,7 @@ async fn main() -> Result<()> {
let mut ctx = ExecutionContext::new();
// declare a table in memory. In spark API, this corresponds to createDataFrame(...).
- let provider = MemTable::new(schema, vec![vec![batch]])?;
+ let provider = MemTable::try_new(schema, vec![vec![batch]])?;
ctx.register_table("t", Box::new(provider));
let df = ctx.table("t")?;
diff --git a/rust/datafusion/examples/simple_udaf.rs b/rust/datafusion/examples/simple_udaf.rs
index c615653fa3..f5ec4bebb7 100644
--- a/rust/datafusion/examples/simple_udaf.rs
+++ b/rust/datafusion/examples/simple_udaf.rs
@@ -47,7 +47,7 @@ fn create_context() -> Result<ExecutionContext> {
let mut ctx = ExecutionContext::new();
// declare a table in memory. In spark API, this corresponds to createDataFrame(...).
- let provider = MemTable::new(schema, vec![vec![batch1], vec![batch2]])?;
+ let provider = MemTable::try_new(schema, vec![vec![batch1], vec![batch2]])?;
ctx.register_table("t", Box::new(provider));
Ok(ctx)
}
diff --git a/rust/datafusion/examples/simple_udf.rs b/rust/datafusion/examples/simple_udf.rs
index c0d4a04bd1..e753105f22 100644
--- a/rust/datafusion/examples/simple_udf.rs
+++ b/rust/datafusion/examples/simple_udf.rs
@@ -49,7 +49,7 @@ fn create_context() -> Result<ExecutionContext> {
let mut ctx = ExecutionContext::new();
// declare a table in memory. In spark API, this corresponds to createDataFrame(...).
- let provider = MemTable::new(schema, vec![vec![batch]])?;
+ let provider = MemTable::try_new(schema, vec![vec![batch]])?;
ctx.register_table("t", Box::new(provider));
Ok(ctx)
}
diff --git a/rust/datafusion/src/datasource/memory.rs b/rust/datafusion/src/datasource/memory.rs
index a62b79c9ce..5b4f9fd730 100644
--- a/rust/datafusion/src/datasource/memory.rs
+++ b/rust/datafusion/src/datasource/memory.rs
@@ -41,7 +41,7 @@ pub struct MemTable {
impl MemTable {
/// Create a new in-memory table from the provided schema and record batches
- pub fn new(schema: SchemaRef, partitions: Vec<Vec<RecordBatch>>) -> Result<Self> {
+ pub fn try_new(schema: SchemaRef, partitions: Vec<Vec<RecordBatch>>) -> Result<Self> {
if partitions.iter().all(|partition| {
partition
.iter()
@@ -84,7 +84,7 @@ impl MemTable {
data.push(result);
}
- MemTable::new(schema.clone(), data)
+ MemTable::try_new(schema.clone(), data)
}
}
@@ -165,7 +165,7 @@ mod tests {
],
)?;
- let provider = MemTable::new(schema, vec![vec![batch]])?;
+ let provider = MemTable::try_new(schema, vec![vec![batch]])?;
// scan with projection
let exec = provider.scan(&Some(vec![2, 1]), 1024)?;
@@ -196,7 +196,7 @@ mod tests {
],
)?;
- let provider = MemTable::new(schema, vec![vec![batch]])?;
+ let provider = MemTable::try_new(schema, vec![vec![batch]])?;
let exec = provider.scan(&None, 1024)?;
let mut it = exec.execute(0).await?;
@@ -224,7 +224,7 @@ mod tests {
],
)?;
- let provider = MemTable::new(schema, vec![vec![batch]])?;
+ let provider = MemTable::try_new(schema, vec![vec![batch]])?;
let projection: Vec<usize> = vec![0, 4];
@@ -261,7 +261,7 @@ mod tests {
],
)?;
- match MemTable::new(schema2, vec![vec![batch]]) {
+ match MemTable::try_new(schema2, vec![vec![batch]]) {
Err(DataFusionError::Plan(e)) => assert_eq!(
"\"Mismatch between schema and batches\"",
format!("{:?}", e)
diff --git a/rust/datafusion/src/execution/context.rs b/rust/datafusion/src/execution/context.rs
index 91f80cb90d..8e62ac392c 100644
--- a/rust/datafusion/src/execution/context.rs
+++ b/rust/datafusion/src/execution/context.rs
@@ -206,37 +206,17 @@ impl ExecutionContext {
filename: &str,
options: CsvReadOptions,
) -> Result<Arc<dyn DataFrame>> {
- let csv = CsvFile::try_new(filename, options)?;
-
- let table_scan = LogicalPlan::CsvScan {
- path: filename.to_string(),
- schema: csv.schema(),
- has_header: options.has_header,
- delimiter: Some(options.delimiter),
- projection: None,
- projected_schema: Arc::new(DFSchema::from(&csv.schema())?),
- };
-
Ok(Arc::new(DataFrameImpl::new(
self.state.clone(),
- &LogicalPlanBuilder::from(&table_scan).build()?,
+ &LogicalPlanBuilder::scan_csv(&filename, options, None)?.build()?,
)))
}
/// Creates a DataFrame for reading a Parquet data source.
pub fn read_parquet(&mut self, filename: &str) -> Result<Arc<dyn DataFrame>> {
- let parquet = ParquetTable::try_new(filename)?;
-
- let table_scan = LogicalPlan::ParquetScan {
- path: filename.to_string(),
- schema: parquet.schema(),
- projection: None,
- projected_schema: Arc::new(DFSchema::from(&parquet.schema())?),
- };
-
Ok(Arc::new(DataFrameImpl::new(
self.state.clone(),
- &LogicalPlanBuilder::from(&table_scan).build()?,
+ &LogicalPlanBuilder::scan_parquet(&filename, None)?.build()?,
)))
}
@@ -747,33 +727,31 @@ mod tests {
Field::new("c", DataType::Int32, false),
]);
let schema = SchemaRef::new(schema);
- let plan = LogicalPlanBuilder::from(&LogicalPlan::InMemoryScan {
- data: vec![vec![RecordBatch::try_new(
- schema.clone(),
- vec![
- Arc::new(Int32Array::from(vec![1, 10, 10, 100])),
- Arc::new(Int32Array::from(vec![2, 12, 12, 120])),
- Arc::new(Int32Array::from(vec![3, 12, 12, 120])),
- ],
- )?]],
- schema: schema.clone(),
- projection: None,
- projected_schema: DFSchemaRef::new(DFSchema::from(&schema)?),
- })
- .project(vec![col("b")])?
- .build()?;
+
+ let partitions = vec![vec![RecordBatch::try_new(
+ schema.clone(),
+ vec![
+ Arc::new(Int32Array::from(vec![1, 10, 10, 100])),
+ Arc::new(Int32Array::from(vec![2, 12, 12, 120])),
+ Arc::new(Int32Array::from(vec![3, 12, 12, 120])),
+ ],
+ )?]];
+
+ let plan = LogicalPlanBuilder::scan_memory(partitions, schema, None)?
+ .project(vec![col("b")])?
+ .build()?;
assert_fields_eq(&plan, vec!["b"]);
let ctx = ExecutionContext::new();
let optimized_plan = ctx.optimize(&plan)?;
match &optimized_plan {
LogicalPlan::Projection { input, .. } => match &**input {
- LogicalPlan::InMemoryScan {
- schema,
+ LogicalPlan::TableScan {
+ table_schema,
projected_schema,
..
} => {
- assert_eq!(schema.fields().len(), 3);
+ assert_eq!(table_schema.fields().len(), 3);
assert_eq!(projected_schema.fields().len(), 1);
}
_ => assert!(false, "input to projection should be InMemoryScan"),
@@ -782,7 +760,7 @@ mod tests {
}
let expected = "Projection: #b\
- \n InMemoryScan: projection=Some([1])";
+ \n TableScan: projection=Some([1])";
assert_eq!(format!("{:?}", optimized_plan), expected);
let physical_plan = ctx.create_physical_plan(&optimized_plan)?;
@@ -1334,7 +1312,7 @@ mod tests {
let mut ctx = ExecutionContext::new();
- let provider = MemTable::new(Arc::new(schema), vec![vec![batch]])?;
+ let provider = MemTable::try_new(Arc::new(schema), vec![vec![batch]])?;
ctx.register_table("t", Box::new(provider));
let myfunc: ScalarFunctionImplementation = Arc::new(|args: &[ArrayRef]| {
@@ -1424,7 +1402,8 @@ mod tests {
let mut ctx = ExecutionContext::new();
- let provider = MemTable::new(Arc::new(schema), vec![vec![batch1], vec![batch2]])?;
+ let provider =
+ MemTable::try_new(Arc::new(schema), vec![vec![batch1], vec![batch2]])?;
ctx.register_table("t", Box::new(provider));
let result = collect(&mut ctx, "SELECT AVG(a) FROM t").await?;
@@ -1460,7 +1439,8 @@ mod tests {
let mut ctx = ExecutionContext::new();
- let provider = MemTable::new(Arc::new(schema), vec![vec![batch1], vec![batch2]])?;
+ let provider =
+ MemTable::try_new(Arc::new(schema), vec![vec![batch1], vec![batch2]])?;
ctx.register_table("t", Box::new(provider));
// define a udaf, using a DataFusion's accumulator
diff --git a/rust/datafusion/src/logical_plan/builder.rs b/rust/datafusion/src/logical_plan/builder.rs
index 57ef80cd83..f20feb0cae 100644
--- a/rust/datafusion/src/logical_plan/builder.rs
+++ b/rust/datafusion/src/logical_plan/builder.rs
@@ -19,12 +19,17 @@
use std::{collections::HashMap, sync::Arc};
-use arrow::datatypes::{Schema, SchemaRef};
+use arrow::{
+ datatypes::{Schema, SchemaRef},
+ record_batch::RecordBatch,
+};
-use crate::datasource::csv::{CsvFile, CsvReadOptions};
-use crate::datasource::parquet::ParquetTable;
use crate::datasource::TableProvider;
use crate::error::{DataFusionError, Result};
+use crate::{
+ datasource::{parquet::ParquetTable, CsvFile, MemTable},
+ prelude::CsvReadOptions,
+};
use super::{
col, exprlist_to_fields, Expr, JoinType, LogicalPlan, PlanType, StringifiedPlan,
@@ -54,14 +59,36 @@ impl LogicalPlanBuilder {
})
}
+ /// Scan a memory data source
+ pub fn scan_memory(
+ partitions: Vec<Vec<RecordBatch>>,
+ schema: SchemaRef,
+ projection: Option<Vec<usize>>,
+ ) -> Result<Self> {
+ let provider = Arc::new(MemTable::try_new(schema.clone(), partitions)?);
+
+ let projected_schema = projection
+ .map(|p| Schema::new(p.iter().map(|i| schema.field(*i).clone()).collect()));
+ let projected_schema = projected_schema.map_or(schema.clone(), SchemaRef::new);
+ let projected_schema = DFSchemaRef::new(DFSchema::from(&projected_schema)?);
+
+ let table_scan = LogicalPlan::TableScan {
+ schema_name: "".to_string(),
+ source: TableSource::FromProvider(provider),
+ table_schema: schema,
+ projected_schema,
+ projection: None,
+ };
+
+ Ok(Self::from(&table_scan))
+ }
+
/// Scan a CSV data source
pub fn scan_csv(
path: &str,
options: CsvReadOptions,
projection: Option<Vec<usize>>,
) -> Result<Self> {
- let has_header = options.has_header;
- let delimiter = options.delimiter;
let schema: Schema = match options.schema {
Some(s) => s.to_owned(),
None => CsvFile::try_new(path, options)?
@@ -71,37 +98,44 @@ impl LogicalPlanBuilder {
};
let projected_schema = projection
- .clone()
.map(|p| Schema::new(p.iter().map(|i| schema.field(*i).clone()).collect()))
- .or(Some(schema.clone()))
+ .or(Some(schema))
.unwrap();
+ let projected_schema = DFSchemaRef::new(DFSchema::from(&projected_schema)?);
- Ok(Self::from(&LogicalPlan::CsvScan {
- path: path.to_owned(),
- schema: SchemaRef::new(schema),
- has_header,
- delimiter: Some(delimiter),
- projection,
- projected_schema: DFSchemaRef::new(DFSchema::from(&projected_schema)?),
- }))
+ let provider = Arc::new(CsvFile::try_new(path, options)?);
+ let schema = provider.schema();
+
+ let table_scan = LogicalPlan::TableScan {
+ schema_name: "".to_string(),
+ source: TableSource::FromProvider(provider),
+ table_schema: schema,
+ projected_schema,
+ projection: None,
+ };
+
+ Ok(Self::from(&table_scan))
}
/// Scan a Parquet data source
pub fn scan_parquet(path: &str, projection: Option<Vec<usize>>) -> Result<Self> {
- let p = ParquetTable::try_new(path)?;
- let schema = p.schema();
+ let provider = Arc::new(ParquetTable::try_new(path)?);
+ let schema = provider.schema();
let projected_schema = projection
- .clone()
.map(|p| Schema::new(p.iter().map(|i| schema.field(*i).clone()).collect()));
let projected_schema = projected_schema.map_or(schema.clone(), SchemaRef::new);
+ let projected_schema = DFSchemaRef::new(DFSchema::from(&projected_schema)?);
+
+ let table_scan = LogicalPlan::TableScan {
+ schema_name: "".to_string(),
+ source: TableSource::FromProvider(provider),
+ table_schema: schema,
+ projected_schema,
+ projection: None,
+ };
- Ok(Self::from(&LogicalPlan::ParquetScan {
- path: path.to_owned(),
- schema,
- projection,
- projected_schema: DFSchemaRef::new(DFSchema::from(&projected_schema)?),
- }))
+ Ok(Self::from(&table_scan))
}
/// Scan a data source
@@ -358,26 +392,6 @@ mod tests {
Ok(())
}
- #[test]
- fn plan_builder_csv() -> Result<()> {
- let plan = LogicalPlanBuilder::scan_csv(
- "employee.csv",
- CsvReadOptions::new().schema(&employee_schema()),
- Some(vec![0, 3]),
- )?
- .filter(col("state").eq(lit("CO")))?
- .project(vec![col("id")])?
- .build()?;
-
- let expected = "Projection: #id\
- \n Filter: #state Eq Utf8(\"CO\")\
- \n CsvScan: employee.csv projection=Some([0, 3])";
-
- assert_eq!(expected, format!("{:?}", plan));
-
- Ok(())
- }
-
#[test]
fn plan_builder_aggregate() -> Result<()> {
let plan = LogicalPlanBuilder::scan(
diff --git a/rust/datafusion/src/logical_plan/plan.rs b/rust/datafusion/src/logical_plan/plan.rs
index 79a1fb07d6..76c6d02d69 100644
--- a/rust/datafusion/src/logical_plan/plan.rs
+++ b/rust/datafusion/src/logical_plan/plan.rs
@@ -23,7 +23,6 @@ use std::{
};
use arrow::datatypes::{DataType, Field, Schema, SchemaRef};
-use arrow::record_batch::RecordBatch;
use crate::datasource::TableProvider;
use crate::sql::parser::FileType;
@@ -132,43 +131,6 @@ pub enum LogicalPlan {
/// The schema description of the output
projected_schema: DFSchemaRef,
},
- /// Produces rows that come from a `Vec` of in memory `RecordBatch`es
- InMemoryScan {
- /// Record batch partitions
- data: Vec<Vec<RecordBatch>>,
- /// The schema of the record batches
- schema: SchemaRef,
- /// Optional column indices to use as a projection
- projection: Option<Vec<usize>>,
- /// The schema description of the output
- projected_schema: DFSchemaRef,
- },
- /// Produces rows by scanning Parquet file(s)
- ParquetScan {
- /// The path to the files
- path: String,
- /// The schema of the Parquet file(s)
- schema: SchemaRef,
- /// Optional column indices to use as a projection
- projection: Option<Vec<usize>>,
- /// The schema description of the output
- projected_schema: DFSchemaRef,
- },
- /// Produces rows by scanning a CSV file(s)
- CsvScan {
- /// The path to the files
- path: String,
- /// The underlying table schema
- schema: SchemaRef,
- /// Whether the CSV file(s) have a header containing column names
- has_header: bool,
- /// An optional column delimiter. Defaults to `b','`
- delimiter: Option<u8>,
- /// Optional column indices to use as a projection
- projection: Option<Vec<usize>>,
- /// The schema description of the output
- projected_schema: DFSchemaRef,
- },
/// Produces no rows: An empty relation with an empty schema
EmptyRelation {
/// Whether to produce a placeholder row
@@ -220,15 +182,6 @@ impl LogicalPlan {
pub fn schema(&self) -> &DFSchemaRef {
match self {
LogicalPlan::EmptyRelation { schema, .. } => &schema,
- LogicalPlan::InMemoryScan {
- projected_schema, ..
- } => &projected_schema,
- LogicalPlan::CsvScan {
- projected_schema, ..
- } => &projected_schema,
- LogicalPlan::ParquetScan {
- projected_schema, ..
- } => &projected_schema,
LogicalPlan::TableScan {
projected_schema, ..
} => &projected_schema,
@@ -332,9 +285,6 @@ impl LogicalPlan {
}
// plans without inputs
LogicalPlan::TableScan { .. }
- | LogicalPlan::InMemoryScan { .. }
- | LogicalPlan::ParquetScan { .. }
- | LogicalPlan::CsvScan { .. }
| LogicalPlan::EmptyRelation { .. }
| LogicalPlan::CreateExternalTable { .. }
| LogicalPlan::Explain { .. } => true,
@@ -538,19 +488,6 @@ impl LogicalPlan {
write!(f, "TableScan: projection={:?}", projection)
}
},
- LogicalPlan::InMemoryScan { ref projection, .. } => {
- write!(f, "InMemoryScan: projection={:?}", projection)
- }
- LogicalPlan::CsvScan {
- ref path,
- ref projection,
- ..
- } => write!(f, "CsvScan: {} projection={:?}", path, projection),
- LogicalPlan::ParquetScan {
- ref path,
- ref projection,
- ..
- } => write!(f, "ParquetScan: {} projection={:?}", path, projection),
LogicalPlan::Projection { ref expr, .. } => {
write!(f, "Projection: ")?;
for i in 0..expr.len() {
diff --git a/rust/datafusion/src/optimizer/projection_push_down.rs b/rust/datafusion/src/optimizer/projection_push_down.rs
index f2df7e1cba..e4571e71bc 100644
--- a/rust/datafusion/src/optimizer/projection_push_down.rs
+++ b/rust/datafusion/src/optimizer/projection_push_down.rs
@@ -269,69 +269,6 @@ fn optimize_plan(
projected_schema,
})
}
- LogicalPlan::InMemoryScan {
- data,
- schema,
- projection,
- ..
- } => {
- let (projection, projected_schema) = get_projected_schema(
- &schema,
- projection,
- required_columns,
- has_projection,
- )?;
- Ok(LogicalPlan::InMemoryScan {
- data: data.clone(),
- schema: schema.clone(),
- projection: Some(projection),
- projected_schema,
- })
- }
- LogicalPlan::CsvScan {
- path,
- has_header,
- delimiter,
- schema,
- projection,
- ..
- } => {
- let (projection, projected_schema) = get_projected_schema(
- &schema,
- projection,
- required_columns,
- has_projection,
- )?;
-
- Ok(LogicalPlan::CsvScan {
- path: path.to_owned(),
- has_header: *has_header,
- schema: schema.clone(),
- delimiter: *delimiter,
- projection: Some(projection),
- projected_schema,
- })
- }
- LogicalPlan::ParquetScan {
- path,
- schema,
- projection,
- ..
- } => {
- let (projection, projected_schema) = get_projected_schema(
- &schema,
- projection,
- required_columns,
- has_projection,
- )?;
-
- Ok(LogicalPlan::ParquetScan {
- path: path.to_owned(),
- schema: schema.clone(),
- projection: Some(projection),
- projected_schema,
- })
- }
LogicalPlan::Explain {
verbose,
plan,
diff --git a/rust/datafusion/src/optimizer/utils.rs b/rust/datafusion/src/optimizer/utils.rs
index 436f8fb599..7248f4c955 100644
--- a/rust/datafusion/src/optimizer/utils.rs
+++ b/rust/datafusion/src/optimizer/utils.rs
@@ -156,9 +156,6 @@ pub fn expressions(plan: &LogicalPlan) -> Vec<Expr> {
LogicalPlan::Extension { node } => node.expressions(),
// plans without expressions
LogicalPlan::TableScan { .. }
- | LogicalPlan::InMemoryScan { .. }
- | LogicalPlan::ParquetScan { .. }
- | LogicalPlan::CsvScan { .. }
| LogicalPlan::EmptyRelation { .. }
| LogicalPlan::Limit { .. }
| LogicalPlan::CreateExternalTable { .. }
@@ -178,9 +175,6 @@ pub fn inputs(plan: &LogicalPlan) -> Vec<&LogicalPlan> {
LogicalPlan::Extension { node } => node.inputs(),
// plans without inputs
LogicalPlan::TableScan { .. }
- | LogicalPlan::InMemoryScan { .. }
- | LogicalPlan::ParquetScan { .. }
- | LogicalPlan::CsvScan { .. }
| LogicalPlan::EmptyRelation { .. }
| LogicalPlan::CreateExternalTable { .. }
| LogicalPlan::Explain { .. } => vec![],
@@ -236,9 +230,6 @@ pub fn from_plan(
}),
LogicalPlan::EmptyRelation { .. }
| LogicalPlan::TableScan { .. }
- | LogicalPlan::InMemoryScan { .. }
- | LogicalPlan::ParquetScan { .. }
- | LogicalPlan::CsvScan { .. }
| LogicalPlan::CreateExternalTable { .. }
| LogicalPlan::Explain { .. } => Ok(plan.clone()),
}
diff --git a/rust/datafusion/src/physical_plan/planner.rs b/rust/datafusion/src/physical_plan/planner.rs
index 118e277833..046744e8ad 100644
--- a/rust/datafusion/src/physical_plan/planner.rs
+++ b/rust/datafusion/src/physical_plan/planner.rs
@@ -26,7 +26,6 @@ use crate::logical_plan::{
DFSchema, Expr, LogicalPlan, Operator, PlanType, StringifiedPlan, TableSource,
UserDefinedLogicalNode,
};
-use crate::physical_plan::csv::{CsvExec, CsvReadOptions};
use crate::physical_plan::explain::ExplainExec;
use crate::physical_plan::expressions::{CaseExpr, Column, Literal, PhysicalSortExpr};
use crate::physical_plan::filter::FilterExec;
@@ -34,9 +33,7 @@ use crate::physical_plan::hash_aggregate::{AggregateMode, HashAggregateExec};
use crate::physical_plan::hash_join::HashJoinExec;
use crate::physical_plan::hash_utils;
use crate::physical_plan::limit::{GlobalLimitExec, LocalLimitExec};
-use crate::physical_plan::memory::MemoryExec;
use crate::physical_plan::merge::MergeExec;
-use crate::physical_plan::parquet::ParquetExec;
use crate::physical_plan::projection::ProjectionExec;
use crate::physical_plan::sort::SortExec;
use crate::physical_plan::udf;
@@ -156,32 +153,6 @@ impl DefaultPhysicalPlanner {
provider.scan(projection, batch_size)
}
},
- LogicalPlan::InMemoryScan {
- data,
- projection,
- projected_schema,
- ..
- } => Ok(Arc::new(MemoryExec::try_new(
- data,
- projected_schema.as_ref().to_owned().into(),
- projection.to_owned(),
- )?)),
- LogicalPlan::CsvScan {
- path,
- schema,
- has_header,
- delimiter,
- projection,
- ..
- } => Ok(Arc::new(CsvExec::try_new(
- path,
- CsvReadOptions::new()
- .schema(schema.as_ref())
- .delimiter_option(*delimiter)
- .has_header(*has_header),
- projection.to_owned(),
- batch_size,
- )?)),
LogicalPlan::Aggregate {
input,
group_expr,
@@ -241,13 +212,6 @@ impl DefaultPhysicalPlanner {
initial_aggr,
)?))
}
- LogicalPlan::ParquetScan {
- path, projection, ..
- } => Ok(Arc::new(ParquetExec::try_new(
- path,
- projection.to_owned(),
- batch_size,
- )?)),
LogicalPlan::Projection { input, expr, .. } => {
let input_exec = self.create_physical_plan(input, ctx_state)?;
let input_schema = input.as_ref().schema();
diff --git a/rust/datafusion/src/test/mod.rs b/rust/datafusion/src/test/mod.rs
index eccbbf8c4a..bfa931d162 100644
--- a/rust/datafusion/src/test/mod.rs
+++ b/rust/datafusion/src/test/mod.rs
@@ -45,7 +45,7 @@ pub fn create_table_dual() -> Box<dyn TableProvider + Send + Sync> {
],
)
.unwrap();
- let provider = MemTable::new(dual_schema, vec![vec![batch]]).unwrap();
+ let provider = MemTable::try_new(dual_schema, vec![vec![batch]]).unwrap();
Box::new(provider)
}
diff --git a/rust/datafusion/tests/sql.rs b/rust/datafusion/tests/sql.rs
index 072ad25d11..57cb8c4625 100644
--- a/rust/datafusion/tests/sql.rs
+++ b/rust/datafusion/tests/sql.rs
@@ -1040,7 +1040,7 @@ fn create_case_context() -> Result<ExecutionContext> {
None,
]))],
)?;
- let table = MemTable::new(schema, vec![vec![data]])?;
+ let table = MemTable::try_new(schema, vec![vec![data]])?;
ctx.register_table("t1", Box::new(table));
Ok(ctx)
}
@@ -1190,7 +1190,7 @@ fn create_join_context(
])),
],
)?;
- let t1_table = MemTable::new(t1_schema, vec![vec![t1_data]])?;
+ let t1_table = MemTable::try_new(t1_schema, vec![vec![t1_data]])?;
ctx.register_table("t1", Box::new(t1_table));
let t2_schema = Arc::new(Schema::new(vec![
@@ -1209,7 +1209,7 @@ fn create_join_context(
])),
],
)?;
- let t2_table = MemTable::new(t2_schema, vec![vec![t2_data]])?;
+ let t2_table = MemTable::try_new(t2_schema, vec![vec![t2_data]])?;
ctx.register_table("t2", Box::new(t2_table));
Ok(ctx)
@@ -1411,7 +1411,7 @@ async fn generic_query_length<T: 'static + Array + From<Vec<&'static str>>>(
vec![Arc::new(T::from(vec!["", "a", "aa", "aaa"]))],
)?;
- let table = MemTable::new(schema, vec![vec![data]])?;
+ let table = MemTable::try_new(schema, vec![vec![data]])?;
let mut ctx = ExecutionContext::new();
ctx.register_table("test", Box::new(table));
@@ -1445,7 +1445,7 @@ async fn query_not() -> Result<()> {
]))],
)?;
- let table = MemTable::new(schema, vec![vec![data]])?;
+ let table = MemTable::try_new(schema, vec![vec![data]])?;
let mut ctx = ExecutionContext::new();
ctx.register_table("test", Box::new(table));
@@ -1471,7 +1471,7 @@ async fn query_concat() -> Result<()> {
],
)?;
- let table = MemTable::new(schema, vec![vec![data]])?;
+ let table = MemTable::try_new(schema, vec![vec![data]])?;
let mut ctx = ExecutionContext::new();
ctx.register_table("test", Box::new(table));
@@ -1502,7 +1502,7 @@ async fn query_array() -> Result<()> {
],
)?;
- let table = MemTable::new(schema, vec![vec![data]])?;
+ let table = MemTable::try_new(schema, vec![vec![data]])?;
let mut ctx = ExecutionContext::new();
ctx.register_table("test", Box::new(table));
@@ -1591,7 +1591,7 @@ fn make_timestamp_nano_table() -> Result<Box<MemTable>> {
Arc::new(Int32Array::from(vec![Some(1), Some(2), Some(3)])),
],
)?;
- let table = MemTable::new(schema, vec![vec![data]])?;
+ let table = MemTable::try_new(schema, vec![vec![data]])?;
Ok(Box::new(table))
}
@@ -1621,7 +1621,7 @@ async fn query_is_null() -> Result<()> {
]))],
)?;
- let table = MemTable::new(schema, vec![vec![data]])?;
+ let table = MemTable::try_new(schema, vec![vec![data]])?;
let mut ctx = ExecutionContext::new();
ctx.register_table("test", Box::new(table));
@@ -1645,7 +1645,7 @@ async fn query_is_not_null() -> Result<()> {
]))],
)?;
- let table = MemTable::new(schema, vec![vec![data]])?;
+ let table = MemTable::try_new(schema, vec![vec![data]])?;
let mut ctx = ExecutionContext::new();
ctx.register_table("test", Box::new(table));
@@ -1672,7 +1672,7 @@ async fn query_count_distinct() -> Result<()> {
]))],
)?;
- let table = MemTable::new(schema, vec![vec![data]])?;
+ let table = MemTable::try_new(schema, vec![vec![data]])?;
let mut ctx = ExecutionContext::new();
ctx.register_table("test", Box::new(table));
@@ -1702,7 +1702,7 @@ async fn query_on_string_dictionary() -> Result<()> {
let data = RecordBatch::try_new(schema.clone(), vec![array])?;
- let table = MemTable::new(schema, vec![vec![data]])?;
+ let table = MemTable::try_new(schema, vec![vec![data]])?;
let mut ctx = ExecutionContext::new();
ctx.register_table("test", Box::new(table));
@@ -1772,7 +1772,7 @@ async fn query_scalar_minus_array() -> Result<()> {
]))],
)?;
- let table = MemTable::new(schema, vec![vec![data]])?;
+ let table = MemTable::try_new(schema, vec![vec![data]])?;
let mut ctx = ExecutionContext::new();
ctx.register_table("test", Box::new(table));