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

Function test_map

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

Source from the content-addressed store, hash-verified

1280
1281 #[test]
1282 fn test_map() {
1283 let buf = r#"
1284 {"map": {"a": ["foo", null]}}
1285 {"map": {"a": [null], "b": []}}
1286 {"map": {"c": null, "a": ["baz"]}}
1287 "#;
1288 let map = Field::new_map(
1289 "map",
1290 "entries",
1291 Field::new("key", DataType::Utf8, false),
1292 Field::new_list("value", Field::new("element", DataType::Utf8, true), true),
1293 false,
1294 true,
1295 );
1296
1297 let schema = Arc::new(Schema::new(vec![map]));
1298
1299 let batches = do_read(buf, 1024, false, false, schema);
1300 assert_eq!(batches.len(), 1);
1301
1302 let map = batches[0].column(0).as_map();
1303 let map_keys = map.keys().as_string::<i32>();
1304 let map_values = map.values().as_list::<i32>();
1305 assert_eq!(map.value_offsets(), &[0, 1, 3, 5]);
1306
1307 let k: Vec<_> = map_keys.iter().flatten().collect();
1308 assert_eq!(&k, &["a", "a", "b", "c", "a"]);
1309
1310 let list_values = map_values.values().as_string::<i32>();
1311 let lv: Vec<_> = list_values.iter().collect();
1312 assert_eq!(&lv, &[Some("foo"), None, None, Some("baz")]);
1313 assert_eq!(map_values.value_offsets(), &[0, 2, 3, 3, 3, 4]);
1314 assert_eq!(map_values.null_count(), 1);
1315 assert!(map_values.is_null(3));
1316
1317 let options = FormatOptions::default().with_null("null");
1318 let formatter = ArrayFormatter::try_new(map, &options).unwrap();
1319 assert_eq!(formatter.value(0).to_string(), "{a: [foo, null]}");
1320 assert_eq!(formatter.value(1).to_string(), "{a: [null], b: []}");
1321 assert_eq!(formatter.value(2).to_string(), "{c: null, a: [baz]}");
1322 }
1323
1324 #[test]
1325 fn test_not_coercing_primitive_into_string_without_flag() {

Callers

nothing calls this directly

Calls 11

do_readFunction · 0.85
defaultFunction · 0.85
try_newFunction · 0.85
as_mapMethod · 0.80
collectMethod · 0.80
flattenMethod · 0.80
columnMethod · 0.45
keysMethod · 0.45
valuesMethod · 0.45
iterMethod · 0.45
with_nullMethod · 0.45

Tested by

no test coverage detected