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

Function test_basic

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

Source from the content-addressed store, hash-verified

912
913 #[test]
914 fn test_basic() {
915 let buf = r#"
916 {"a": 1, "b": 2, "c": true, "d": 1}
917 {"a": 2E0, "b": 4, "c": false, "d": 2, "e": 254}
918
919 {"b": 6, "a": 2.0, "d": 45}
920 {"b": "5", "a": 2}
921 {"b": 4e0}
922 {"b": 7, "a": null}
923 "#;
924
925 let schema = Arc::new(Schema::new(vec![
926 Field::new("a", DataType::Int64, true),
927 Field::new("b", DataType::Int32, true),
928 Field::new("c", DataType::Boolean, true),
929 Field::new("d", DataType::Date32, true),
930 Field::new("e", DataType::Date64, true),
931 ]));
932
933 let mut decoder = ReaderBuilder::new(schema.clone()).build_decoder().unwrap();
934 assert!(decoder.is_empty());
935 assert_eq!(decoder.len(), 0);
936 assert!(!decoder.has_partial_record());
937 assert_eq!(decoder.decode(buf.as_bytes()).unwrap(), 221);
938 assert!(!decoder.is_empty());
939 assert_eq!(decoder.len(), 6);
940 assert!(!decoder.has_partial_record());
941 let batch = decoder.flush().unwrap().unwrap();
942 assert_eq!(batch.num_rows(), 6);
943 assert!(decoder.is_empty());
944 assert_eq!(decoder.len(), 0);
945 assert!(!decoder.has_partial_record());
946
947 let batches = do_read(buf, 1024, false, false, schema);
948 assert_eq!(batches.len(), 1);
949
950 let col1 = batches[0].column(0).as_primitive::<Int64Type>();
951 assert_eq!(col1.null_count(), 2);
952 assert_eq!(col1.values(), &[1, 2, 2, 2, 0, 0]);
953 assert!(col1.is_null(4));
954 assert!(col1.is_null(5));
955
956 let col2 = batches[0].column(1).as_primitive::<Int32Type>();
957 assert_eq!(col2.null_count(), 0);
958 assert_eq!(col2.values(), &[2, 4, 6, 5, 4, 7]);
959
960 let col3 = batches[0].column(2).as_boolean();
961 assert_eq!(col3.null_count(), 4);
962 assert!(col3.value(0));
963 assert!(!col3.is_null(0));
964 assert!(!col3.value(1));
965 assert!(!col3.is_null(1));
966
967 let col4 = batches[0].column(3).as_primitive::<Date32Type>();
968 assert_eq!(col4.null_count(), 3);
969 assert!(col4.is_null(3));
970 assert_eq!(col4.values(), &[1, 2, 45, 0, 0, 0]);
971

Callers

nothing calls this directly

Calls 6

do_readFunction · 0.85
build_decoderMethod · 0.45
cloneMethod · 0.45
flushMethod · 0.45
columnMethod · 0.45
as_booleanMethod · 0.45

Tested by

no test coverage detected