alamb commented on code in PR #11423:
URL: https://github.com/apache/datafusion/pull/11423#discussion_r1676334942


##########
datafusion/sqllogictest/test_files/join.slt:
##########
@@ -998,11 +997,22 @@ CREATE TABLE t2 (v0 DOUBLE) AS VALUES (-1.663563947387);
 statement ok
 CREATE TABLE t3 (v0 DOUBLE) AS VALUES (0.05112015193508901);
 
+# Test issue: https://github.com/apache/datafusion/issues/11269
 query RR
 SELECT t3.v0, t2.v0 FROM t1,t2,t3 WHERE t3.v0 >= t1.v0;
 ----
 0.051120151935 -1.663563947387
 
+# Test issue: https://github.com/apache/datafusion/issues/11414
+query IRR
+SELECT * FROM t1 INNER JOIN t2 ON NULL RIGHT JOIN t3 ON TRUE;
+----
+NULL NULL 0.051120151935
+
+# ON expression must be boolean type
+query error DataFusion error: Error during planning: ON expression must be 
boolean, but got Utf8
+SELECT * FROM t1 INNER JOIN t2 ON 'TRUE'

Review Comment:
   I think the structure you have now implemented (in the analyzer) makes it 
pretty easy to support if desired 



##########
datafusion/optimizer/src/analyzer/type_coercion.rs:
##########
@@ -151,9 +151,27 @@ impl<'a> TypeCoercionRewriter<'a> {
             })
             .collect::<Result<Vec<_>>>()?;
 
+        // Join filter must be boolean
+        join.filter = join
+            .filter
+            .map(|expr| self.coerce_join_filter(expr))
+            .transpose()?;
+
         Ok(LogicalPlan::Join(join))
     }
 
+    fn coerce_join_filter(&self, expr: Expr) -> Result<Expr> {
+        let expr_type = expr.get_type(self.schema)?;
+        match expr_type {
+            DataType::Boolean => Ok(expr),
+            DataType::Null => Ok(Expr::Cast(expr::Cast::new(
+                Box::new(expr),
+                DataType::Boolean,
+            ))),

Review Comment:
   I think this could be more concise if we used `Expr::cast_to, like this: 
   
   ```suggestion
               DataType::Null => expr.cast_to(&DataType::Boolean, self.schema),
   ```



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to