zhuqi-lucas commented on code in PR #16196: URL: https://github.com/apache/datafusion/pull/16196#discussion_r2128032920
########## datafusion/physical-optimizer/src/wrap_leaves_cancellation.rs: ########## @@ -0,0 +1,138 @@ +// 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 crate::PhysicalOptimizerRule; +use datafusion_common::config::ConfigOptions; +use datafusion_common::tree_node::{Transformed, TreeNode, TreeNodeRecursion}; +use datafusion_common::Result; +use datafusion_physical_plan::execution_plan::EmissionType; +use datafusion_physical_plan::yield_stream::YieldStreamExec; +use datafusion_physical_plan::ExecutionPlan; +use std::fmt::{Debug, Formatter}; +use std::sync::Arc; + +/// WrapLeaves is a PhysicalOptimizerRule that finds every +/// pipelineābreaking node (emission_type == Final) and then +/// wraps all of its leaf children in YieldStreamExec. +pub struct WrapLeaves {} + +impl WrapLeaves { + pub fn new() -> Self { + Self {} + } + + /// This function is called on every plan node during transform_down(). + /// If the node is a leaf (no children), we wrap it in a new YieldStreamExec + /// and stop recursing further under that branch (TreeNodeRecursion::Jump). + fn wrap_leaves( + plan: Arc<dyn ExecutionPlan>, + yield_frequency: usize, + ) -> Result<Transformed<Arc<dyn ExecutionPlan>>> { + if plan.children().is_empty() { + // If the leaf node already has a built-in yielding variant: Review Comment: This is the logic which we support built-in checking and exclude to add a new YieldStreamExec. -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org