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

Function make_struct

arrow/tests/array_equal.rs:1339–1372  ·  view source on GitHub ↗
(elements: Vec<Option<(Option<&'static str>, Option<i32>)>>)

Source from the content-addressed store, hash-verified

1337}
1338
1339fn make_struct(elements: Vec<Option<(Option<&'static str>, Option<i32>)>>) -> StructArray {
1340 let mut builder = StructBuilder::new(
1341 vec![
1342 Field::new("f1", DataType::Utf8, true),
1343 Field::new("f2", DataType::Int32, true),
1344 ],
1345 vec![
1346 Box::new(StringBuilder::new()),
1347 Box::new(Int32Builder::new()),
1348 ],
1349 );
1350
1351 for element in elements {
1352 match element.and_then(|e| e.0) {
1353 None => builder
1354 .field_builder::<StringBuilder>(0)
1355 .unwrap()
1356 .append_null(),
1357 Some(s) => builder
1358 .field_builder::<StringBuilder>(0)
1359 .unwrap()
1360 .append_value(s),
1361 };
1362
1363 builder
1364 .field_builder::<Int32Builder>(1)
1365 .unwrap()
1366 .append_option(element.and_then(|e| e.1));
1367
1368 builder.append(element.is_some());
1369 }
1370
1371 builder.finish()
1372}
1373
1374#[test]
1375fn test_struct_equal_slice() {

Callers 1

test_struct_equal_sliceFunction · 0.85

Calls 6

and_thenMethod · 0.80
append_nullMethod · 0.45
append_valueMethod · 0.45
append_optionMethod · 0.45
appendMethod · 0.45
finishMethod · 0.45

Tested by

no test coverage detected