jonahgao commented on code in PR #14572:
URL: https://github.com/apache/datafusion/pull/14572#discussion_r1954582396


##########
datafusion/common/src/dfschema.rs:
##########
@@ -1028,21 +1028,41 @@ impl SchemaExt for Schema {
             })
     }
 
-    fn logically_equivalent_names_and_types(&self, other: &Self) -> bool {
+    fn logically_equivalent_names_and_types(&self, other: &Self) -> Result<()> 
{
         if self.fields().len() != other.fields().len() {
-            return false;
+            _plan_err!(
+                "Inserting query must have the same schema length as the 
table. \
+            Expected table schema length: {}, got: {}",
+                self.fields().len(),
+                other.fields().len()
+            )
+        } else {
+            self.fields()
+                .iter()
+                .zip(other.fields().iter())
+                .try_for_each(|(f1, f2)| {
+                    // only check the case when the table field is not 
nullable and the insert data field is nullable
+                    if !f1.is_nullable() && f2.is_nullable() {

Review Comment:
   I'm not sure if it's necessary to ensure that the schema of output batches 
has the same nullability. This issue exists not only with inserts but also with 
other queries like UNION.
   ```sh
   DataFusion CLI v45.0.0
   > create table t1(a int not null) as values(1);
   0 row(s) fetched.
   Elapsed 0.009 seconds.
   
   > create table t2(a int) as values(2);
   0 row(s) fetched.
   Elapsed 0.011 seconds.
   
   > select * from t1 union all select * from t2;
   batch schema: Schema { fields: [Field { name: "a", data_type: Int32, 
nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }], metadata: 
{} }
   batch schema: Schema { fields: [Field { name: "a", data_type: Int32, 
nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }], metadata: 
{} }
   +---+
   | a |
   +---+
   | 1 |
   | 2 |
   +---+
   2 row(s) fetched.
   Elapsed 0.007 seconds.
   ```



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

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to