MCPcopy Create free account
hub / github.com/apache/arrow-rs / test_projection_array_values

Function test_projection_array_values

arrow-ipc/src/reader.rs:2272–2307  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2270
2271 #[test]
2272 fn test_projection_array_values() {
2273 // define schema
2274 let schema = create_test_projection_schema();
2275
2276 // create record batch with test data
2277 let batch = create_test_projection_batch_data(&schema);
2278
2279 // write record batch in IPC format
2280 let mut buf = Vec::new();
2281 {
2282 let mut writer = crate::writer::FileWriter::try_new(&mut buf, &schema).unwrap();
2283 writer.write(&batch).unwrap();
2284 writer.finish().unwrap();
2285 }
2286
2287 // read record batch with projection
2288 for index in 0..12 {
2289 let projection = vec![index];
2290 let reader = FileReader::try_new(std::io::Cursor::new(buf.clone()), Some(projection));
2291 let read_batch = reader.unwrap().next().unwrap().unwrap();
2292 let projected_column = read_batch.column(0);
2293 let expected_column = batch.column(index);
2294
2295 // check the projected column equals the expected column
2296 assert_eq!(projected_column.as_ref(), expected_column.as_ref());
2297 }
2298
2299 {
2300 // read record batch with reversed projection
2301 let reader =
2302 FileReader::try_new(std::io::Cursor::new(buf.clone()), Some(vec![3, 2, 1]));
2303 let read_batch = reader.unwrap().next().unwrap().unwrap();
2304 let expected_batch = batch.project(&[3, 2, 1]).unwrap();
2305 assert_eq!(read_batch, expected_batch);
2306 }
2307 }
2308
2309 #[test]
2310 fn test_projection_duplicate_indices() {

Callers

nothing calls this directly

Calls 9

try_newFunction · 0.85
writeMethod · 0.45
finishMethod · 0.45
cloneMethod · 0.45
nextMethod · 0.45
columnMethod · 0.45
projectMethod · 0.45

Tested by

no test coverage detected