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

Function test_json_basic_schema

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

Source from the content-addressed store, hash-verified

1984
1985 #[test]
1986 fn test_json_basic_schema() {
1987 let schema = Schema::new(vec![
1988 Field::new("a", DataType::Int64, true),
1989 Field::new("b", DataType::Float32, false),
1990 Field::new("c", DataType::Boolean, false),
1991 Field::new("d", DataType::Utf8, false),
1992 ]);
1993
1994 let mut reader = read_file("test/data/basic.json", Some(schema.clone()));
1995 let reader_schema = reader.schema();
1996 assert_eq!(reader_schema.as_ref(), &schema);
1997 let batch = reader.next().unwrap().unwrap();
1998
1999 assert_eq!(4, batch.num_columns());
2000 assert_eq!(12, batch.num_rows());
2001
2002 let schema = batch.schema();
2003
2004 let a = schema.column_with_name("a").unwrap();
2005 assert_eq!(&DataType::Int64, a.1.data_type());
2006 let b = schema.column_with_name("b").unwrap();
2007 assert_eq!(&DataType::Float32, b.1.data_type());
2008 let c = schema.column_with_name("c").unwrap();
2009 assert_eq!(&DataType::Boolean, c.1.data_type());
2010 let d = schema.column_with_name("d").unwrap();
2011 assert_eq!(&DataType::Utf8, d.1.data_type());
2012
2013 let aa = batch.column(a.0).as_primitive::<Int64Type>();
2014 assert_eq!(1, aa.value(0));
2015 assert_eq!(100000000000000, aa.value(11));
2016 let bb = batch.column(b.0).as_primitive::<Float32Type>();
2017 assert_eq!(2.0, bb.value(0));
2018 assert_eq!(-3.5, bb.value(1));
2019 }
2020
2021 #[test]
2022 fn test_json_basic_schema_projection() {

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected