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

Function test_complex

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

Source from the content-addressed store, hash-verified

1150
1151 #[test]
1152 fn test_complex() {
1153 let buf = r#"
1154 {"list": [], "nested": {"a": 1, "b": 2}, "nested_list": {"list2": [{"c": 3}, {"c": 4}]}}
1155 {"list": [5, 6], "nested": {"a": 7}, "nested_list": {"list2": []}}
1156 {"list": null, "nested": {"a": null}}
1157 "#;
1158
1159 let schema = Arc::new(Schema::new(vec![
1160 Field::new_list("list", Field::new("element", DataType::Int32, false), true),
1161 Field::new_struct(
1162 "nested",
1163 vec![
1164 Field::new("a", DataType::Int32, true),
1165 Field::new("b", DataType::Int32, true),
1166 ],
1167 true,
1168 ),
1169 Field::new_struct(
1170 "nested_list",
1171 vec![Field::new_list(
1172 "list2",
1173 Field::new_struct(
1174 "element",
1175 vec![Field::new("c", DataType::Int32, false)],
1176 false,
1177 ),
1178 true,
1179 )],
1180 true,
1181 ),
1182 ]));
1183
1184 let batches = do_read(buf, 1024, false, false, schema);
1185 assert_eq!(batches.len(), 1);
1186
1187 let list = batches[0].column(0).as_list::<i32>();
1188 assert_eq!(list.len(), 3);
1189 assert_eq!(list.value_offsets(), &[0, 0, 2, 2]);
1190 assert_eq!(list.null_count(), 1);
1191 assert!(list.is_null(2));
1192 let list_values = list.values().as_primitive::<Int32Type>();
1193 assert_eq!(list_values.values(), &[5, 6]);
1194
1195 let nested = batches[0].column(1).as_struct();
1196 let a = nested.column(0).as_primitive::<Int32Type>();
1197 assert_eq!(list.null_count(), 1);
1198 assert_eq!(a.values(), &[1, 7, 0]);
1199 assert!(list.is_null(2));
1200
1201 let b = nested.column(1).as_primitive::<Int32Type>();
1202 assert_eq!(b.null_count(), 2);
1203 assert_eq!(b.len(), 3);
1204 assert_eq!(b.value(0), 2);
1205 assert!(b.is_null(1));
1206 assert!(b.is_null(2));
1207
1208 let nested_list = batches[0].column(2).as_struct();
1209 assert_eq!(nested_list.len(), 3);

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