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

Function normalize_simple

arrow-array/src/record_batch.rs:1425–1474  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1423
1424 #[test]
1425 fn normalize_simple() {
1426 let animals: ArrayRef = Arc::new(StringArray::from(vec!["Parrot", ""]));
1427 let n_legs: ArrayRef = Arc::new(Int64Array::from(vec![Some(2), Some(4)]));
1428 let year: ArrayRef = Arc::new(Int64Array::from(vec![None, Some(2022)]));
1429
1430 let animals_field = Arc::new(Field::new("animals", DataType::Utf8, true));
1431 let n_legs_field = Arc::new(Field::new("n_legs", DataType::Int64, true));
1432 let year_field = Arc::new(Field::new("year", DataType::Int64, true));
1433
1434 let a = Arc::new(StructArray::from(vec![
1435 (animals_field.clone(), Arc::new(animals.clone()) as ArrayRef),
1436 (n_legs_field.clone(), Arc::new(n_legs.clone()) as ArrayRef),
1437 (year_field.clone(), Arc::new(year.clone()) as ArrayRef),
1438 ]));
1439
1440 let month = Arc::new(Int64Array::from(vec![Some(4), Some(6)]));
1441
1442 let schema = Schema::new(vec![
1443 Field::new(
1444 "a",
1445 DataType::Struct(Fields::from(vec![animals_field, n_legs_field, year_field])),
1446 false,
1447 ),
1448 Field::new("month", DataType::Int64, true),
1449 ]);
1450
1451 let normalized =
1452 RecordBatch::try_new(Arc::new(schema.clone()), vec![a.clone(), month.clone()])
1453 .expect("valid conversion")
1454 .normalize(".", Some(0))
1455 .expect("valid normalization");
1456
1457 let expected = RecordBatch::try_from_iter_with_nullable(vec![
1458 ("a.animals", animals.clone(), true),
1459 ("a.n_legs", n_legs.clone(), true),
1460 ("a.year", year.clone(), true),
1461 ("month", month.clone(), true),
1462 ])
1463 .expect("valid conversion");
1464
1465 assert_eq!(expected, normalized);
1466
1467 // check 0 and None have the same effect
1468 let normalized = RecordBatch::try_new(Arc::new(schema), vec![a, month.clone()])
1469 .expect("valid conversion")
1470 .normalize(".", None)
1471 .expect("valid normalization");
1472
1473 assert_eq!(expected, normalized);
1474 }
1475
1476 #[test]
1477 fn normalize_nested() {

Callers

nothing calls this directly

Calls 3

try_newFunction · 0.85
normalizeMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected