neilconway commented on code in PR #24534:
URL: https://github.com/apache/datafusion/pull/24534#discussion_r3826582377


##########
datafusion/physical-expr/src/planner.rs:
##########
@@ -538,8 +538,9 @@ pub fn create_physical_expr(
                     let dt = schema.field(0).data_type().clone();
                     Ok(Arc::new(ScalarSubqueryExpr::new(
                         dt,
-                        // A scalar subquery may return no rows and evaluate 
to NULL.
-                        true,
+                        // Defer to the logical nullability rule, which 
accounts
+                        // for subqueries guaranteed to produce at least one 
row.

Review Comment:
   nit: I found this comment to be confusingly worded; I'd probably just remove 
it.



##########
datafusion/expr/src/expr_schema.rs:
##########
@@ -369,9 +369,8 @@ impl ExprSchemable for Expr {
 
                 Ok(expr_nullable | subquery_nullable)
             }
-            // A scalar subquery may return no rows, in which case it 
evaluates to NULL
-            // regardless of the nullability of its projected field.
-            Expr::ScalarSubquery(_) => Ok(true),
+            Expr::ScalarSubquery(subquery) => Ok(subquery.subquery.min_rows() 
== 0
+                || subquery.subquery.schema().field(0).is_nullable()),

Review Comment:
   nit: We have the same code (albeit the operands are in a different order) 
below (~line 520). Might be worth refactoring into a helper.



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