jackwener commented on code in PR #8271:
URL: https://github.com/apache/arrow-datafusion/pull/8271#discussion_r1473855859


##########
datafusion/optimizer/src/decorrelate_predicate_subquery.rs:
##########
@@ -249,6 +249,38 @@ fn build_join(
                 .map(Option::Some)
         })?;
 
+    // build a predicate for comparing the left and right expressions of a 
given pair of outer/subquery rows
+    // from an IN or NOT IN predicate
+    let build_in_predicate = |left: Box<Expr>, right: Box<Expr>| -> 
Result<Expr> {
+        let right_col = create_col_from_scalar_expr(right.deref(), 
subquery_alias)?;
+        let eq_predicate =
+            Expr::eq(left.deref().clone(), Expr::Column(right_col.clone()));
+        if !query_info.negated {
+            // early exit if this is an IN predicate
+            return Ok(eq_predicate);
+        }
+
+        match left.nullable(outer_query.schema())? {
+            true => {
+                // left expression is nullable; we know the predicate must 
take the form `left = right IS NOT FALSE`
+                return Ok(eq_predicate.is_not_false());
+            }
+            false => {}
+        }
+        let subquery_col = query_info
+            .query
+            .subquery
+            .schema()
+            .field_with_unqualified_name(right_col.name.as_str())?;
+
+        match subquery_col.is_nullable() {
+            // add "IS NOT FALSE" to a NOT IN equality predicate whose 
subquery expression is nullable
+            // so that an unknown result is treated as a (possible) match
+            true => Ok(eq_predicate.is_not_false()),
+            false => Ok(eq_predicate),
+        }
+    };
+

Review Comment:
   I suggest use these code to get a flag `null_equal_null`.



##########
datafusion/optimizer/src/decorrelate_predicate_subquery.rs:
##########
@@ -282,7 +312,7 @@ fn build_join(
             true => JoinType::LeftAnti,
             false => JoinType::LeftSemi,
         };
-        let new_plan = LogicalPlanBuilder::from(left.clone())
+        let new_plan = LogicalPlanBuilder::from(outer_query.clone())
             .join_on(sub_query_alias, join_type, Some(join_filter))?

Review Comment:
   ```suggestion
      .join_detailed(
                   sub_query_alias,
                   join_type,
                   (Vec::<Column>::new(), Vec::<Column>::new()),
                   Some(join_filter),
                   null_equal_null,
               )```



##########
datafusion/optimizer/src/decorrelate_predicate_subquery.rs:
##########
@@ -282,7 +312,7 @@ fn build_join(
             true => JoinType::LeftAnti,
             false => JoinType::LeftSemi,
         };
-        let new_plan = LogicalPlanBuilder::from(left.clone())
+        let new_plan = LogicalPlanBuilder::from(outer_query.clone())
             .join_on(sub_query_alias, join_type, Some(join_filter))?

Review Comment:
   After we get `null_equal_null `, we fill it here.



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

Reply via email to