Skip to content

Commit 8632cc0

Browse files
committed
chore(cube): Further reduce debug build stack usage in datafusion-proto logical plan conversion
1 parent 7d15be6 commit 8632cc0

File tree

2 files changed

+99
-90
lines changed

2 files changed

+99
-90
lines changed

datafusion/proto/src/logical_plan/mod.rs

Lines changed: 61 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ impl AsLogicalPlan for LogicalPlanNode {
379379
.aggregate(group_expr, aggr_expr)?
380380
.build()
381381
}
382-
LogicalPlanType::ListingScan(scan) => {
382+
LogicalPlanType::ListingScan(scan) => (|scan: &protobuf::ListingTableScanNode, extension_codec: &dyn LogicalExtensionCodec| {
383383
let schema: Schema = convert_required!(scan.schema)?;
384384

385385
let mut projection = None;
@@ -495,7 +495,7 @@ impl AsLogicalPlan for LogicalPlanNode {
495495
filters,
496496
)?
497497
.build()
498-
}
498+
})(scan, extension_codec),
499499
LogicalPlanType::CustomScan(scan) => {
500500
let schema: Schema = convert_required!(scan.schema)?;
501501
let schema = Arc::new(schema);
@@ -571,7 +571,7 @@ impl AsLogicalPlan for LogicalPlanNode {
571571
LogicalPlanType::EmptyRelation(empty_relation) => {
572572
LogicalPlanBuilder::empty(empty_relation.produce_one_row).build()
573573
}
574-
LogicalPlanType::CreateExternalTable(create_extern_table) => {
574+
LogicalPlanType::CreateExternalTable(create_extern_table) => (|create_extern_table: &protobuf::CreateExternalTableNode, extension_codec: &dyn LogicalExtensionCodec| {
575575
let pb_schema = (create_extern_table.schema.clone()).ok_or_else(|| {
576576
DataFusionError::Internal(String::from(
577577
"Protobuf deserialization error, CreateExternalTableNode was missing required field schema."
@@ -632,7 +632,7 @@ impl AsLogicalPlan for LogicalPlanNode {
632632
column_defaults,
633633
},
634634
)))
635-
}
635+
})(create_extern_table, extension_codec),
636636
LogicalPlanType::CreateView(create_view) => {
637637
let plan = create_view
638638
.input.clone().ok_or_else(|| DataFusionError::Internal(String::from(
@@ -719,7 +719,7 @@ impl AsLogicalPlan for LogicalPlanNode {
719719

720720
LogicalPlanBuilder::from(input).limit(skip, fetch)?.build()
721721
}
722-
LogicalPlanType::Join(join) => {
722+
LogicalPlanType::Join(join) => (|join: &Box<protobuf::JoinNode>, extension_codec: &dyn LogicalExtensionCodec| {
723723
let left_keys: Vec<Expr> =
724724
from_proto::parse_exprs(&join.left_join_key, ctx, extension_codec)?;
725725
let right_keys: Vec<Expr> =
@@ -778,7 +778,7 @@ impl AsLogicalPlan for LogicalPlanNode {
778778
};
779779

780780
builder.build()
781-
}
781+
})(join, extension_codec),
782782
LogicalPlanType::Union(union) => {
783783
if union.inputs.len() < 2 {
784784
return Err( DataFusionError::Internal(String::from(
@@ -839,7 +839,7 @@ impl AsLogicalPlan for LogicalPlanNode {
839839
.distinct_on(on_expr, select_expr, sort_expr)?
840840
.build()
841841
}
842-
LogicalPlanType::ViewScan(scan) => {
842+
LogicalPlanType::ViewScan(scan) => (|scan: &Box<protobuf::ViewTableScanNode>, extension_codec: &dyn LogicalExtensionCodec| {
843843
let schema: Schema = convert_required!(scan.schema)?;
844844

845845
let mut projection = None;
@@ -872,7 +872,7 @@ impl AsLogicalPlan for LogicalPlanNode {
872872
projection,
873873
)?
874874
.build()
875-
}
875+
})(scan, extension_codec),
876876
LogicalPlanType::Prepare(prepare) => {
877877
let input: LogicalPlan =
878878
into_logical_plan!(prepare.input, ctx, extension_codec)?;
@@ -1177,7 +1177,8 @@ impl AsLogicalPlan for LogicalPlanNode {
11771177
Ok(node)
11781178
}
11791179
})(table_name, source, filters, projection, extension_codec),
1180-
LogicalPlan::Projection(Projection { expr, input, .. }) => {
1180+
LogicalPlan::Projection(projection) => (|projection: &Projection, extension_codec: &dyn LogicalExtensionCodec| {
1181+
let Projection { expr, input, .. } = projection;
11811182
Ok(LogicalPlanNode {
11821183
logical_plan_type: Some(LogicalPlanType::Projection(Box::new(
11831184
protobuf::ProjectionNode {
@@ -1192,8 +1193,8 @@ impl AsLogicalPlan for LogicalPlanNode {
11921193
},
11931194
))),
11941195
})
1195-
}
1196-
LogicalPlan::Filter(filter) => {
1196+
})(projection, extension_codec),
1197+
LogicalPlan::Filter(filter) => (|filter: &datafusion_expr::Filter, extension_codec: &dyn LogicalExtensionCodec| {
11971198
let input: LogicalPlanNode = LogicalPlanNode::try_from_logical_plan(
11981199
filter.input.as_ref(),
11991200
extension_codec,
@@ -1209,7 +1210,7 @@ impl AsLogicalPlan for LogicalPlanNode {
12091210
},
12101211
))),
12111212
})
1212-
}
1213+
})(filter, extension_codec),
12131214
LogicalPlan::Distinct(Distinct::All(input)) => {
12141215
let input: LogicalPlanNode = LogicalPlanNode::try_from_logical_plan(
12151216
input.as_ref(),
@@ -1223,13 +1224,14 @@ impl AsLogicalPlan for LogicalPlanNode {
12231224
))),
12241225
})
12251226
}
1226-
LogicalPlan::Distinct(Distinct::On(DistinctOn {
1227-
on_expr,
1228-
select_expr,
1229-
sort_expr,
1230-
input,
1231-
..
1232-
})) => {
1227+
LogicalPlan::Distinct(Distinct::On(distinct_on)) => (|distinct_on: &DistinctOn, extension_codec: &dyn LogicalExtensionCodec| {
1228+
let DistinctOn {
1229+
on_expr,
1230+
select_expr,
1231+
sort_expr,
1232+
input,
1233+
..
1234+
} = distinct_on;
12331235
let input: LogicalPlanNode = LogicalPlanNode::try_from_logical_plan(
12341236
input.as_ref(),
12351237
extension_codec,
@@ -1248,7 +1250,7 @@ impl AsLogicalPlan for LogicalPlanNode {
12481250
},
12491251
))),
12501252
})
1251-
}
1253+
})(distinct_on, extension_codec),
12521254
LogicalPlan::Window(Window {
12531255
input, window_expr, ..
12541256
}) => {
@@ -1285,16 +1287,17 @@ impl AsLogicalPlan for LogicalPlanNode {
12851287
))),
12861288
})
12871289
}
1288-
LogicalPlan::Join(Join {
1289-
left,
1290-
right,
1291-
on,
1292-
filter,
1293-
join_type,
1294-
join_constraint,
1295-
null_equals_null,
1296-
..
1297-
}) => {
1290+
LogicalPlan::Join(join) => (|join: &Join, extension_codec: &dyn LogicalExtensionCodec| {
1291+
let Join {
1292+
left,
1293+
right,
1294+
on,
1295+
filter,
1296+
join_type,
1297+
join_constraint,
1298+
null_equals_null,
1299+
..
1300+
} = join;
12981301
let left: LogicalPlanNode = LogicalPlanNode::try_from_logical_plan(
12991302
left.as_ref(),
13001303
extension_codec,
@@ -1335,7 +1338,7 @@ impl AsLogicalPlan for LogicalPlanNode {
13351338
},
13361339
))),
13371340
})
1338-
}
1341+
})(join, extension_codec),
13391342
LogicalPlan::Subquery(_) => {
13401343
not_impl_err!("LogicalPlan serde is not yet implemented for subqueries")
13411344
}
@@ -1353,7 +1356,7 @@ impl AsLogicalPlan for LogicalPlanNode {
13531356
))),
13541357
})
13551358
}
1356-
LogicalPlan::Limit(limit) => {
1359+
LogicalPlan::Limit(limit) => (|limit: &datafusion_expr::Limit, extension_codec: &dyn LogicalExtensionCodec| {
13571360
let input: LogicalPlanNode = LogicalPlanNode::try_from_logical_plan(
13581361
limit.input.as_ref(),
13591362
extension_codec,
@@ -1378,8 +1381,9 @@ impl AsLogicalPlan for LogicalPlanNode {
13781381
},
13791382
))),
13801383
})
1381-
}
1382-
LogicalPlan::Sort(Sort { input, expr, fetch }) => {
1384+
})(limit, extension_codec),
1385+
LogicalPlan::Sort(sort) => (|sort: &Sort, extension_codec: &dyn LogicalExtensionCodec| {
1386+
let Sort { input, expr, fetch } = sort;
13831387
let input: LogicalPlanNode = LogicalPlanNode::try_from_logical_plan(
13841388
input.as_ref(),
13851389
extension_codec,
@@ -1395,11 +1399,12 @@ impl AsLogicalPlan for LogicalPlanNode {
13951399
},
13961400
))),
13971401
})
1398-
}
1399-
LogicalPlan::Repartition(Repartition {
1400-
input,
1401-
partitioning_scheme,
1402-
}) => {
1402+
})(sort, extension_codec),
1403+
LogicalPlan::Repartition(repartition) => (|repartition: &Repartition, extension_codec: &dyn LogicalExtensionCodec| {
1404+
let Repartition {
1405+
input,
1406+
partitioning_scheme,
1407+
} = repartition;
14031408
use datafusion::logical_expr::Partitioning;
14041409
let input: LogicalPlanNode = LogicalPlanNode::try_from_logical_plan(
14051410
input.as_ref(),
@@ -1433,7 +1438,7 @@ impl AsLogicalPlan for LogicalPlanNode {
14331438
},
14341439
))),
14351440
})
1436-
}
1441+
})(repartition, extension_codec),
14371442
LogicalPlan::EmptyRelation(EmptyRelation {
14381443
produce_one_row, ..
14391444
}) => Ok(LogicalPlanNode {
@@ -1443,8 +1448,8 @@ impl AsLogicalPlan for LogicalPlanNode {
14431448
},
14441449
)),
14451450
}),
1446-
LogicalPlan::Ddl(DdlStatement::CreateExternalTable(
1447-
CreateExternalTable {
1451+
LogicalPlan::Ddl(DdlStatement::CreateExternalTable(create_external_table)) => (|create_external_table: &CreateExternalTable, extension_codec: &dyn LogicalExtensionCodec| {
1452+
let CreateExternalTable {
14481453
name,
14491454
location,
14501455
file_type,
@@ -1458,8 +1463,8 @@ impl AsLogicalPlan for LogicalPlanNode {
14581463
constraints,
14591464
column_defaults,
14601465
temporary,
1461-
},
1462-
)) => {
1466+
} = create_external_table;
1467+
14631468
let mut converted_order_exprs: Vec<SortExprNodeCollection> = vec![];
14641469
for order in order_exprs {
14651470
let temp = SortExprNodeCollection {
@@ -1494,7 +1499,7 @@ impl AsLogicalPlan for LogicalPlanNode {
14941499
},
14951500
)),
14961501
})
1497-
}
1502+
})(create_external_table, extension_codec),
14981503
LogicalPlan::Ddl(DdlStatement::CreateView(CreateView {
14991504
name,
15001505
input,
@@ -1620,15 +1625,16 @@ impl AsLogicalPlan for LogicalPlanNode {
16201625
))),
16211626
})
16221627
}
1623-
LogicalPlan::Unnest(Unnest {
1624-
input,
1625-
exec_columns,
1626-
list_type_columns,
1627-
struct_type_columns,
1628-
dependency_indices,
1629-
schema,
1630-
options,
1631-
}) => {
1628+
LogicalPlan::Unnest(unnest) => (|unnest: &Unnest, extension_codec: &dyn LogicalExtensionCodec| {
1629+
let Unnest {
1630+
input,
1631+
exec_columns,
1632+
list_type_columns,
1633+
struct_type_columns,
1634+
dependency_indices,
1635+
schema,
1636+
options,
1637+
} = unnest;
16321638
let input =
16331639
LogicalPlanNode::try_from_logical_plan(input, extension_codec)?;
16341640
let proto_unnest_list_items = list_type_columns
@@ -1663,7 +1669,7 @@ impl AsLogicalPlan for LogicalPlanNode {
16631669
},
16641670
))),
16651671
})
1666-
}
1672+
})(unnest, extension_codec),
16671673
LogicalPlan::Ddl(DdlStatement::CreateMemoryTable(_)) => Err(proto_error(
16681674
"LogicalPlan serde is not yet implemented for CreateMemoryTable",
16691675
)),

0 commit comments

Comments
 (0)