| 979 | |
| 980 | #[test] |
| 981 | fn test_string() { |
| 982 | let buf = r#" |
| 983 | {"a": "1", "b": "2"} |
| 984 | {"a": "hello", "b": "shoo"} |
| 985 | {"b": "\t😁foo", "a": "\nfoobar\ud83d\ude00\u0061\u0073\u0066\u0067\u00FF"} |
| 986 | |
| 987 | {"b": null} |
| 988 | {"b": "", "a": null} |
| 989 | |
| 990 | "#; |
| 991 | let schema = Arc::new(Schema::new(vec![ |
| 992 | Field::new("a", DataType::Utf8, true), |
| 993 | Field::new("b", DataType::LargeUtf8, true), |
| 994 | ])); |
| 995 | |
| 996 | let batches = do_read(buf, 1024, false, false, schema); |
| 997 | assert_eq!(batches.len(), 1); |
| 998 | |
| 999 | let col1 = batches[0].column(0).as_string::<i32>(); |
| 1000 | assert_eq!(col1.null_count(), 2); |
| 1001 | assert_eq!(col1.value(0), "1"); |
| 1002 | assert_eq!(col1.value(1), "hello"); |
| 1003 | assert_eq!(col1.value(2), "\nfoobar😀asfgÿ"); |
| 1004 | assert!(col1.is_null(3)); |
| 1005 | assert!(col1.is_null(4)); |
| 1006 | |
| 1007 | let col2 = batches[0].column(1).as_string::<i64>(); |
| 1008 | assert_eq!(col2.null_count(), 1); |
| 1009 | assert_eq!(col2.value(0), "2"); |
| 1010 | assert_eq!(col2.value(1), "shoo"); |
| 1011 | assert_eq!(col2.value(2), "\t😁foo"); |
| 1012 | assert!(col2.is_null(3)); |
| 1013 | assert_eq!(col2.value(4), ""); |
| 1014 | } |
| 1015 | |
| 1016 | #[test] |
| 1017 | fn test_long_string_view_allocation() { |