avantgardnerio commented on code in PR #2885:
URL: https://github.com/apache/arrow-datafusion/pull/2885#discussion_r919326668


##########
datafusion/optimizer/src/decorrelate_scalar_subquery.rs:
##########
@@ -0,0 +1,360 @@
+// 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::utils::{exprs_to_join_cols, find_join_exprs, split_conjunction};
+use crate::{utils, OptimizerConfig, OptimizerRule};
+use datafusion_common::Column;
+use datafusion_expr::logical_plan::{Filter, JoinType, Subquery};
+use datafusion_expr::{combine_filters, Expr, LogicalPlan, LogicalPlanBuilder, 
Operator};
+use std::sync::Arc;
+
+/// Optimizer rule for rewriting subquery filters to joins
+#[derive(Default)]
+pub struct DecorrelateScalarSubquery {}
+
+impl DecorrelateScalarSubquery {
+    #[allow(missing_docs)]
+    pub fn new() -> Self {
+        Self {}
+    }
+
+    /// Finds expressions that have a scalar subquery in them
+    ///
+    /// # Arguments
+    ///
+    /// * `predicate` - A conjunction to split and search
+    fn extract_subquery_exprs(
+        &self,
+        predicate: &Expr,
+        optimizer_config: &mut OptimizerConfig,
+    ) -> datafusion_common::Result<(Vec<SubqueryInfo>, Vec<Expr>)> {
+        let mut filters = vec![];
+        split_conjunction(predicate, &mut filters); // TODO: disjunctions
+
+        let mut subqueries = vec![];
+        let mut others = vec![];
+        for it in filters.iter() {
+            match it {
+                Expr::BinaryExpr { left, op, right } => {
+                    let l_query = match &**left {
+                        Expr::ScalarSubquery(subquery) => 
Some(subquery.clone()),
+                        _ => None,
+                    };
+                    let r_query = match &**right {
+                        Expr::ScalarSubquery(subquery) => 
Some(subquery.clone()),
+                        _ => None,
+                    };
+                    if l_query.is_none() && r_query.is_none() {
+                        others.push((*it).clone());
+                        continue;
+                    }
+                    for (idx, subquery) in vec![l_query, 
r_query].iter().enumerate() {

Review Comment:
   How does the new version look?



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

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

Reply via email to