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

Function test_json_basic

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

Source from the content-addressed store, hash-verified

1896
1897 #[test]
1898 fn test_json_basic() {
1899 let mut reader = read_file("test/data/basic.json", None);
1900 let batch = reader.next().unwrap().unwrap();
1901
1902 assert_eq!(8, batch.num_columns());
1903 assert_eq!(12, batch.num_rows());
1904
1905 let schema = reader.schema();
1906 let batch_schema = batch.schema();
1907 assert_eq!(schema, batch_schema);
1908
1909 let a = schema.column_with_name("a").unwrap();
1910 assert_eq!(0, a.0);
1911 assert_eq!(&DataType::Int64, a.1.data_type());
1912 let b = schema.column_with_name("b").unwrap();
1913 assert_eq!(1, b.0);
1914 assert_eq!(&DataType::Float64, b.1.data_type());
1915 let c = schema.column_with_name("c").unwrap();
1916 assert_eq!(2, c.0);
1917 assert_eq!(&DataType::Boolean, c.1.data_type());
1918 let d = schema.column_with_name("d").unwrap();
1919 assert_eq!(3, d.0);
1920 assert_eq!(&DataType::Utf8, d.1.data_type());
1921
1922 let aa = batch.column(a.0).as_primitive::<Int64Type>();
1923 assert_eq!(1, aa.value(0));
1924 assert_eq!(-10, aa.value(1));
1925 let bb = batch.column(b.0).as_primitive::<Float64Type>();
1926 assert_eq!(2.0, bb.value(0));
1927 assert_eq!(-3.5, bb.value(1));
1928 let cc = batch.column(c.0).as_boolean();
1929 assert!(!cc.value(0));
1930 assert!(cc.value(10));
1931 let dd = batch.column(d.0).as_string::<i32>();
1932 assert_eq!("4", dd.value(0));
1933 assert_eq!("text", dd.value(8));
1934 }
1935
1936 #[test]
1937 fn test_json_empty_projection() {

Callers

nothing calls this directly

Calls 6

column_with_nameMethod · 0.80
read_fileFunction · 0.70
nextMethod · 0.45
schemaMethod · 0.45
columnMethod · 0.45
as_booleanMethod · 0.45

Tested by

no test coverage detected