zhuqi-lucas commented on code in PR #14572: URL: https://github.com/apache/datafusion/pull/14572#discussion_r1957116873
########## datafusion/core/tests/dataframe/mod.rs: ########## @@ -5274,3 +5274,61 @@ async fn register_non_parquet_file() { "1.json' does not match the expected extension '.parquet'" ); } + +// Test inserting into checking. +#[tokio::test] +async fn test_insert_into_checking() -> Result<()> { + // Create a new schema with one field called "a" of type Int64, and setting nullable to false + let schema = Arc::new(Schema::new(vec![Field::new("a", DataType::Int64, false)])); + + let session_ctx = SessionContext::new(); + + // Create and register the initial table with the provided schema and data + let initial_table = Arc::new(MemTable::try_new(schema.clone(), vec![vec![]])?); + session_ctx.register_table("t", initial_table.clone())?; + + // There are three cases we need to check + // 1. The len of the schema of the plan and the schema of the table should be the same + // 2. The datatype of the schema of the plan and the schema of the table should be the same + + // Test case 1: + let write_df = session_ctx.sql("values (1, 2), (3, 4)").await.unwrap(); + + match write_df + .write_table("t", DataFrameWriteOptions::new()) + .await + { + Ok(_) => {} + Err(e) => { + assert_contains!( + e.to_string(), + "Inserting query must have the same schema length as the table." + ); + } + } Review Comment: Good idea, thanks @alamb , addressed in latest PR. -- 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