MCPcopy Create free account
hub / github.com/apache/datafusion / test_create_record_batch

Function test_create_record_batch

datafusion/common/src/test_util.rs:779–816  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

777
778 #[test]
779 fn test_create_record_batch() -> Result<()> {
780 use arrow::array::Array;
781
782 let batch = record_batch!(
783 ("a", Int32, vec![1, 2, 3, 4]),
784 ("b", Float64, vec![Some(4.0), None, Some(5.0), None]),
785 ("c", Utf8, vec!["alpha", "beta", "gamma", "delta"])
786 )?;
787
788 assert_eq!(3, batch.num_columns());
789 assert_eq!(4, batch.num_rows());
790
791 let values: Vec<_> = as_int32_array(batch.column(0))?
792 .values()
793 .iter()
794 .map(|v| v.to_owned())
795 .collect();
796 assert_eq!(values, vec![1, 2, 3, 4]);
797
798 let values: Vec<_> = as_float64_array(batch.column(1))?
799 .values()
800 .iter()
801 .map(|v| v.to_owned())
802 .collect();
803 assert_eq!(values, vec![4.0, 0.0, 5.0, 0.0]);
804
805 let nulls: Vec<_> = as_float64_array(batch.column(1))?
806 .nulls()
807 .unwrap()
808 .iter()
809 .collect();
810 assert_eq!(nulls, vec![true, false, true, false]);
811
812 let values: Vec<_> = as_string_array(batch.column(2))?.iter().flatten().collect();
813 assert_eq!(values, vec!["alpha", "beta", "gamma", "delta"]);
814
815 Ok(())
816 }
817}

Callers

nothing calls this directly

Calls 10

as_int32_arrayFunction · 0.85
as_float64_arrayFunction · 0.85
as_string_arrayFunction · 0.85
collectMethod · 0.80
columnMethod · 0.80
flattenMethod · 0.80
mapMethod · 0.45
iterMethod · 0.45
valuesMethod · 0.45
nullsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…