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


##########
datafusion/sql/src/planner.rs:
##########
@@ -615,6 +617,78 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
             })
     }
 
+    pub(crate) fn validate_expr_type(
+        &self,
+        expr: &Expr,
+        schema: &DFSchema,
+    ) -> Result<()> {
+        expr.apply(|expr| {
+            self.validate_expr_node_type(expr, schema)?;
+            Ok(TreeNodeRecursion::Continue)
+        })?;
+        Ok(())
+    }
+
+    pub(crate) fn validate_filter_predicate(
+        &self,
+        expr: &Expr,
+        schema: &DFSchema,
+    ) -> Result<()> {
+        self.validate_expr_type(expr, schema)?;
+        let predicate_type = expr.get_type(schema)?;
+        if !Self::is_allowed_predicate_type(&predicate_type) {
+            return plan_err!(
+                "Cannot create filter with non-boolean predicate '{expr}' 
returning {predicate_type}"

Review Comment:
   most DataFusion type validation happens during the Analyzer phase, not the 
sql planner (binding phase)
   
   I agree with @Acfboy s original statement that failing at physical planning 
time is probably too late, but trying to do this in sql is too early
   
   Among other things it means that this type checking will not apply to 
queries created via the DataFrame API



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