| 105 | |
| 106 | #[tokio::test] |
| 107 | async fn test_invalid_projection() -> Result<()> { |
| 108 | let session_ctx = SessionContext::new(); |
| 109 | |
| 110 | let schema = Arc::new(Schema::new(vec![ |
| 111 | Field::new("a", DataType::Int32, false), |
| 112 | Field::new("b", DataType::Int32, false), |
| 113 | Field::new("c", DataType::Int32, false), |
| 114 | ])); |
| 115 | |
| 116 | let batch = RecordBatch::try_new( |
| 117 | schema.clone(), |
| 118 | vec![ |
| 119 | Arc::new(Int32Array::from(vec![1, 2, 3])), |
| 120 | Arc::new(Int32Array::from(vec![4, 5, 6])), |
| 121 | Arc::new(Int32Array::from(vec![7, 8, 9])), |
| 122 | ], |
| 123 | )?; |
| 124 | |
| 125 | let provider = MemTable::try_new(schema, vec![vec![batch]])?; |
| 126 | |
| 127 | let projection: Vec<usize> = vec![0, 4]; |
| 128 | |
| 129 | match provider |
| 130 | .scan(&session_ctx.state(), Some(&projection), &[], None) |
| 131 | .await |
| 132 | { |
| 133 | Err(DataFusionError::ArrowError(err, _)) => match err.as_ref() { |
| 134 | ArrowError::SchemaError(e) => { |
| 135 | assert_eq!( |
| 136 | "\"project index 4 out of bounds, max field 3\"", |
| 137 | format!("{e:?}") |
| 138 | ) |
| 139 | } |
| 140 | _ => panic!("unexpected error"), |
| 141 | }, |
| 142 | res => panic!("Scan should failed on invalid projection, got {res:?}"), |
| 143 | }; |
| 144 | |
| 145 | Ok(()) |
| 146 | } |
| 147 | |
| 148 | #[test] |
| 149 | fn test_schema_validation_incompatible_column() -> Result<()> { |