You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/11/13 12:37:22 UTC

[GitHub] [arrow-datafusion] mingmwang commented on a diff in pull request #4192: add `propagate_empty_relation` optimizer rule

mingmwang commented on code in PR #4192:
URL: https://github.com/apache/arrow-datafusion/pull/4192#discussion_r1020895687


##########
datafusion/optimizer/src/propagate_empty_relation.rs:
##########
@@ -0,0 +1,178 @@
+// 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 datafusion_common::Result;
+use datafusion_expr::logical_plan::LogicalPlan;
+use datafusion_expr::EmptyRelation;
+
+use crate::{utils, OptimizerConfig, OptimizerRule};
+
+/// Optimization rule that bottom-up to eliminate plan by propagating empty_relation.
+#[derive(Default)]
+pub struct PropagateEmptyRelation;
+
+impl PropagateEmptyRelation {
+    #[allow(missing_docs)]
+    pub fn new() -> Self {
+        Self {}
+    }
+}
+
+impl OptimizerRule for PropagateEmptyRelation {
+    fn optimize(
+        &self,
+        plan: &LogicalPlan,
+        optimizer_config: &mut OptimizerConfig,
+    ) -> Result<LogicalPlan> {
+        // optimize child plans first
+        let optimized_children_plan =
+            utils::optimize_children(self, plan, optimizer_config)?;
+        let optimized_plan_opt = match &optimized_children_plan {
+            LogicalPlan::Projection(_)
+            | LogicalPlan::Filter(_)
+            | LogicalPlan::Window(_)
+            | LogicalPlan::Sort(_)
+            | LogicalPlan::Join(_)

Review Comment:
   For Join, we need to be careful:
   For Inner join, if either side is empty, the Join is empty.
   For LeftOuter/LeftSemi/LeftAnti Join, only the left side is empty, the Join result is empty.
   For RightOuter/RightSemi/RightAnti Join, only the right side is empty, the Join result is empty.
   For Full Join, only both sides are empty, the Join result is empty.
   



-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org