Skip to content

Apache DataFusion SQL Query Engine

perf(proto): avoid re-normalizing logical plans (#25297)

Anurag Tryambak Raut37744ba97f1c
diff --git a/datafusion/proto/src/logical_plan/mod.rs b/datafusion/proto/src/logical_plan/mod.rs
index 3de9237f06..a1890b05c6 100644
--- a/datafusion/proto/src/logical_plan/mod.rs
+++ b/datafusion/proto/src/logical_plan/mod.rs
@@ -68,8 +68,8 @@ use datafusion_expr::{
logical_plan::{
Aggregate, AsOfJoin, AsOfMatch, CreateCatalog, CreateCatalogSchema,
CreateExternalTable, CreateView, DdlStatement, Distinct, EmptyRelation,
- Extension, Join, Prepare, Projection, Repartition, Sort, SubqueryAlias,
- TableScan, TableScanBuilder, Values, Window, builder::project,
+ Extension, Filter, Join, Prepare, Projection, Repartition, Sort, SubqueryAlias,
+ TableScan, TableScanBuilder, Values, Window,
},
};
use datafusion_proto_common::protobuf_common;
@@ -536,7 +536,8 @@ impl AsLogicalPlan for LogicalPlanNode {
let expr: Vec<Expr> =
from_proto::parse_exprs(&projection.expr, ctx, extension_codec)?;
- let new_proj = project(input, expr)?;
+ let new_proj =
+ LogicalPlan::Projection(Projection::try_new(expr, Arc::new(input))?);
match projection.optional_alias.as_ref() {
Some(a) => match a {
protobuf::projection_node::OptionalAlias::Alias(alias) => {
@@ -558,14 +559,17 @@ impl AsLogicalPlan for LogicalPlanNode {
.map(|expr| from_proto::parse_expr(expr, ctx, extension_codec))
.transpose()?
.ok_or_else(|| proto_error("expression required"))?;
- LogicalPlanBuilder::from(input).filter(expr)?.build()
+ Ok(LogicalPlan::Filter(Filter::try_new(expr, Arc::new(input))?))
}
LogicalPlanType::Window(window) => {
let input: LogicalPlan =
into_logical_plan!(window.input, ctx, extension_codec)?;
let window_expr =
from_proto::parse_exprs(&window.window_expr, ctx, extension_codec)?;
- LogicalPlanBuilder::from(input).window(window_expr)?.build()
+ Ok(LogicalPlan::Window(Window::try_new(
+ window_expr,
+ Arc::new(input),
+ )?))
}
LogicalPlanType::Aggregate(aggregate) => {
let input: LogicalPlan =
@@ -574,9 +578,11 @@ impl AsLogicalPlan for LogicalPlanNode {
from_proto::parse_exprs(&aggregate.group_expr, ctx, extension_codec)?;
let aggr_expr =
from_proto::parse_exprs(&aggregate.aggr_expr, ctx, extension_codec)?;
- LogicalPlanBuilder::from(input)
- .aggregate(group_expr, aggr_expr)?
- .build()
+ Ok(LogicalPlan::Aggregate(Aggregate::try_new(
+ Arc::new(input),
+ group_expr,
+ aggr_expr,
+ )?))
}
LogicalPlanType::ListingScan(scan) => {
let schema: Schema = convert_required!(scan.schema)?;
@@ -750,9 +756,11 @@ impl AsLogicalPlan for LogicalPlanNode {
let fetch = (sort.fetch >= 0)
.then(|| usize_from_wire(sort.fetch, "Sort", "fetch"))
.transpose()?;
- LogicalPlanBuilder::from(input)
- .sort_with_limit(sort_expr, fetch)?
- .build()
+ Ok(LogicalPlan::Sort(Sort {
+ expr: sort_expr,
+ input: Arc::new(input),
+ fetch,
+ }))
}
LogicalPlanType::Repartition(repartition) => {
use datafusion_expr::Partitioning;