duongcongtoai commented on code in PR #16174:
URL: https://github.com/apache/datafusion/pull/16174#discussion_r2105713757


##########
datafusion/optimizer/src/create_dependent_join.rs:
##########
@@ -0,0 +1,163 @@
+// 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::tree_node::Transformed;
+use datafusion_common::{Result, ScalarValue};
+use datafusion_expr::{Expr, JoinType, LogicalPlan, LogicalPlanBuilder, 
Subquery};
+
+use crate::{ApplyOrder, OptimizerConfig, OptimizerRule};
+
+/// (temporary) OPtimizer rule for rewriting current plan with
+/// DependentJoin to jj
+#[derive(Default, Debug)]
+pub struct CreateDependentJoin {}
+
+impl CreateDependentJoin {
+    #[allow(missing_docs)]
+    pub fn new() -> Self {
+        Self::default()
+    }
+}
+
+impl OptimizerRule for CreateDependentJoin {
+    fn supports_rewrite(&self) -> bool {
+        true
+    }
+
+    fn name(&self) -> &str {
+        "create_dependent_join"
+    }
+
+    fn apply_order(&self) -> Option<ApplyOrder> {
+        Some(ApplyOrder::TopDown)
+    }
+
+    fn rewrite(
+        &self,
+        plan: LogicalPlan,
+        _config: &dyn OptimizerConfig,
+    ) -> Result<Transformed<LogicalPlan>> {
+        if let LogicalPlan::Filter(ref filter) = plan {
+            match &filter.predicate {

Review Comment:
   here are more cases i can think of:
   
   1. a predicate can be a complex expressions such as 
   ```
    where column1=(scalar_subquery) or column2=(exists_subquery)
   ```
   In this case 2 nested dependent join will be generated
   
   2. The scalar exprs sometimes is not the direct child of the predicate for 
example
   ```
   where column1 > 1 + (subquery)
   ```
   3. We can have 2 subqueries in the same binary expr
   ```
   where (subquery1) > (subquery2) + 1
   ```



-- 
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

Reply via email to