alamb commented on code in PR #24124:
URL: https://github.com/apache/datafusion/pull/24124#discussion_r3740557992
##########
datafusion/proto/src/logical_plan/mod.rs:
##########
@@ -115,6 +115,29 @@ pub trait AsLogicalPlan: Debug + Send + Sync + Clone {
Self: Sized;
}
+// In debug builds, keep each serializer arm's local temporaries out of the
Review Comment:
This is actually quite clever
I think we could also just split up the logical plan serializer into
separate functions (one for each arm) and let the compiler inline them in
release builds.
However, this is a very nice minimal change -- perhaps you can make a follow
on PR to split them into real functions as a follow on
##########
datafusion/proto/tests/cases/stack_safety.rs:
##########
@@ -0,0 +1,99 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::process::Command;
+use std::sync::Arc;
+
+use datafusion_common::DFSchema;
+use datafusion_expr::logical_plan::{EmptyRelation, LogicalPlan,
LogicalPlanBuilder};
+use datafusion_proto::bytes::logical_plan_to_bytes;
+
+const CHILD_ENV: &str = "DATAFUSION_PROTO_ISSUE_23823_CHILD";
+const ALIAS_DEPTH_ENV: &str = "DATAFUSION_PROTO_ISSUE_23823_ALIAS_DEPTH";
+const TWO_MIB_TEST_NAME: &str =
+ "cases::stack_safety::logical_plan_serialization_fits_a_two_mib_stack";
+#[cfg(feature = "recursive_protection")]
+const GROWABLE_STACK_TEST_NAME: &str =
+
"cases::stack_safety::deeply_nested_logical_plan_serialization_uses_a_growable_stack";
+
+fn deeply_aliased_plan(alias_depth: usize) -> LogicalPlan {
+ let mut plan = LogicalPlan::EmptyRelation(EmptyRelation {
+ produce_one_row: false,
+ schema: Arc::new(DFSchema::empty()),
+ });
+
+ for level in 0..alias_depth {
+ plan = LogicalPlanBuilder::from(plan)
+ .alias(format!("level_{level}"))
+ .unwrap()
+ .build()
+ .unwrap();
+ }
+
+ plan
+}
+
+fn serialize_on_two_mib_stack(alias_depth: usize) {
Review Comment:
this is also a clever pattern
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]