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

Function test_projection

arrow-json/src/reader/mod.rs:1226–1279  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1224
1225 #[test]
1226 fn test_projection() {
1227 let buf = r#"
1228 {"list": [], "nested": {"a": 1, "b": 2}, "nested_list": {"list2": [{"c": 3, "d": 5}, {"c": 4}]}}
1229 {"list": [5, 6], "nested": {"a": 7}, "nested_list": {"list2": []}}
1230 "#;
1231
1232 let schema = Arc::new(Schema::new(vec![
1233 Field::new_struct(
1234 "nested",
1235 vec![Field::new("a", DataType::Int32, false)],
1236 true,
1237 ),
1238 Field::new_struct(
1239 "nested_list",
1240 vec![Field::new_list(
1241 "list2",
1242 Field::new_struct(
1243 "element",
1244 vec![Field::new("d", DataType::Int32, true)],
1245 false,
1246 ),
1247 true,
1248 )],
1249 true,
1250 ),
1251 ]));
1252
1253 let batches = do_read(buf, 1024, false, false, schema);
1254 assert_eq!(batches.len(), 1);
1255
1256 let nested = batches[0].column(0).as_struct();
1257 assert_eq!(nested.num_columns(), 1);
1258 let a = nested.column(0).as_primitive::<Int32Type>();
1259 assert_eq!(a.null_count(), 0);
1260 assert_eq!(a.values(), &[1, 7]);
1261
1262 let nested_list = batches[0].column(1).as_struct();
1263 assert_eq!(nested_list.num_columns(), 1);
1264 assert_eq!(nested_list.null_count(), 0);
1265
1266 let list2 = nested_list.column(0).as_list::<i32>();
1267 assert_eq!(list2.value_offsets(), &[0, 2, 2]);
1268 assert_eq!(list2.null_count(), 0);
1269
1270 let child = list2.values().as_struct();
1271 assert_eq!(child.num_columns(), 1);
1272 assert_eq!(child.len(), 2);
1273 assert_eq!(child.null_count(), 0);
1274
1275 let c = child.column(0).as_primitive::<Int32Type>();
1276 assert_eq!(c.values(), &[5, 0]);
1277 assert_eq!(c.null_count(), 1);
1278 assert!(c.is_null(1));
1279 }
1280
1281 #[test]
1282 fn test_map() {

Callers

nothing calls this directly

Calls 4

do_readFunction · 0.85
as_structMethod · 0.80
columnMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected