()
| 6374 | // Test inserting into checking. |
| 6375 | #[tokio::test] |
| 6376 | async fn test_insert_into_checking() -> Result<()> { |
| 6377 | // Create a new schema with one field called "a" of type Int64, and setting nullable to false |
| 6378 | let schema = Arc::new(Schema::new(vec![Field::new("a", DataType::Int64, false)])); |
| 6379 | |
| 6380 | let session_ctx = SessionContext::new(); |
| 6381 | |
| 6382 | // Create and register the initial table with the provided schema and data |
| 6383 | let initial_table = Arc::new(MemTable::try_new(schema.clone(), vec![vec![]])?); |
| 6384 | session_ctx.register_table("t", initial_table.clone())?; |
| 6385 | |
| 6386 | // There are two cases we need to check |
| 6387 | // 1. The len of the schema of the plan and the schema of the table should be the same |
| 6388 | // 2. The datatype of the schema of the plan and the schema of the table should be the same |
| 6389 | |
| 6390 | // Test case 1: |
| 6391 | let write_df = session_ctx.sql("values (1, 2), (3, 4)").await.unwrap(); |
| 6392 | |
| 6393 | let e = write_df |
| 6394 | .write_table("t", DataFrameWriteOptions::new()) |
| 6395 | .await |
| 6396 | .unwrap_err(); |
| 6397 | |
| 6398 | assert_contains!( |
| 6399 | e.to_string(), |
| 6400 | "Inserting query must have the same schema length as the table." |
| 6401 | ); |
| 6402 | |
| 6403 | // Setting nullable to true |
| 6404 | // Make sure the nullable check go through |
| 6405 | let schema = Arc::new(Schema::new(vec![Field::new("a", DataType::Int64, true)])); |
| 6406 | |
| 6407 | let session_ctx = SessionContext::new(); |
| 6408 | |
| 6409 | // Create and register the initial table with the provided schema and data |
| 6410 | let initial_table = Arc::new(MemTable::try_new(schema.clone(), vec![vec![]])?); |
| 6411 | session_ctx.register_table("t", initial_table.clone())?; |
| 6412 | |
| 6413 | // Test case 2: |
| 6414 | let write_df = session_ctx.sql("values ('a123'), ('b456')").await.unwrap(); |
| 6415 | |
| 6416 | let e = write_df |
| 6417 | .write_table("t", DataFrameWriteOptions::new()) |
| 6418 | .await |
| 6419 | .unwrap_err(); |
| 6420 | |
| 6421 | assert_contains!( |
| 6422 | e.to_string(), |
| 6423 | "Inserting query schema mismatch: Expected table field 'a' with type Int64, but got 'column1' with type Utf8" |
| 6424 | ); |
| 6425 | |
| 6426 | Ok(()) |
| 6427 | } |
| 6428 | |
| 6429 | async fn create_null_table() -> Result<DataFrame> { |
| 6430 | // create a DataFrame with null values |
nothing calls this directly
no test coverage detected
searching dependent graphs…