alamb commented on code in PR #9780:
URL: https://github.com/apache/arrow-datafusion/pull/9780#discussion_r1544595518
##########
datafusion/sqllogictest/test_files/subquery.slt:
##########
@@ -531,13 +531,13 @@ query TT
explain SELECT t0_id, t0_name FROM t0 WHERE EXISTS (SELECT 1 FROM t1 INNER
JOIN t2 ON(t1.t1_id = t2.t2_id and t1.t1_name = t0.t0_name))
----
logical_plan
-Filter: EXISTS (<subquery>)
---Subquery:
-----Projection: Int64(1)
-------Inner Join: Filter: t1.t1_id = t2.t2_id AND t1.t1_name =
outer_ref(t0.t0_name)
---------TableScan: t1
---------TableScan: t2
+LeftSemi Join: t0.t0_name = __correlated_sq_2.t1_name
Review Comment:
this actually seems like an improvement to me -- as the subquery expressions
are now properly visited by the rewriter
##########
datafusion-examples/examples/rewrite_expr.rs:
##########
@@ -59,7 +59,7 @@ pub fn main() -> Result<()> {
// then run the optimizer with our custom rule
let optimizer = Optimizer::with_rules(vec![Arc::new(MyOptimizerRule {})]);
- let optimized_plan = optimizer.optimize(&analyzed_plan, &config, observe)?;
+ let optimized_plan = optimizer.optimize(analyzed_plan, &config, observe)?;
Review Comment:
This is the only API change exposed to users -- `Optimizer::optimize` takes
an owned `LogicalPlan` rather than a `&LogicalPlan`. This is to avoid the need
to copy over and over again
##########
datafusion/expr/src/logical_plan/mutate.rs:
##########
@@ -0,0 +1,346 @@
+// 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 super::plan::*;
+use crate::expr::{Exists, InSubquery};
+use crate::{Expr, UserDefinedLogicalNode};
+use datafusion_common::tree_node::Transformed;
+use datafusion_common::{internal_err, Result};
+use datafusion_common::{Column, DFSchema, DFSchemaRef};
+use std::sync::{Arc, OnceLock};
+
+impl LogicalPlan {
+ /// applies `f` to each expression of this node, potentially rewriting it
in
Review Comment:
This file contains the implementation to allow rewriting the `LogialPlan` in
place. `rewrite_exprs` is needed initially to rewrite subquery references. I
also expect we will be able to use this to implement more performant optimizer
passes in the future (e.g. ExprSimplifier)
--
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]