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

Function test_coercing_primitive_into_string_decoder

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

Source from the content-addressed store, hash-verified

2862
2863 #[test]
2864 fn test_coercing_primitive_into_string_decoder() {
2865 let buf = &format!(
2866 r#"[{{"a": 1, "b": "A", "c": "T"}}, {{"a": 2, "b": "BB", "c": "F"}}, {{"a": {}, "b": 123, "c": false}}, {{"a": {}, "b": 789, "c": true}}]"#,
2867 (i32::MAX as i64 + 10),
2868 i64::MAX - 10
2869 );
2870 let schema = Schema::new(vec![
2871 Field::new("a", DataType::Float64, true),
2872 Field::new("b", DataType::Utf8, true),
2873 Field::new("c", DataType::Utf8, true),
2874 ]);
2875 let json_array: Vec<serde_json::Value> = serde_json::from_str(buf).unwrap();
2876 let schema_ref = Arc::new(schema);
2877
2878 // read record batches
2879 let reader = ReaderBuilder::new(schema_ref.clone()).with_coerce_primitive(true);
2880 let mut decoder = reader.build_decoder().unwrap();
2881 decoder.serialize(json_array.as_slice()).unwrap();
2882 let batch = decoder.flush().unwrap().unwrap();
2883 assert_eq!(
2884 batch,
2885 RecordBatch::try_new(
2886 schema_ref,
2887 vec![
2888 Arc::new(Float64Array::from(vec![
2889 1.0,
2890 2.0,
2891 (i32::MAX as i64 + 10) as f64,
2892 (i64::MAX - 10) as f64
2893 ])),
2894 Arc::new(StringArray::from(vec!["A", "BB", "123", "789"])),
2895 Arc::new(StringArray::from(vec!["T", "F", "false", "true"])),
2896 ]
2897 )
2898 .unwrap()
2899 );
2900 }
2901
2902 // Parse the given `row` in `struct_mode` as a type given by fields.
2903 //

Callers

nothing calls this directly

Calls 6

with_coerce_primitiveMethod · 0.80
cloneMethod · 0.45
build_decoderMethod · 0.45
serializeMethod · 0.45
as_sliceMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected