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

Function assert_binary_json

arrow-json/src/writer/mod.rs:1817–1867  ·  view source on GitHub ↗
(batch: &RecordBatch)

Source from the content-addressed store, hash-verified

1815 }
1816
1817 fn assert_binary_json(batch: &RecordBatch) {
1818 // encode and check JSON with explicit nulls:
1819 {
1820 let mut buf = Vec::new();
1821 let json_value: Value = {
1822 let mut writer = WriterBuilder::new()
1823 .with_explicit_nulls(true)
1824 .build::<_, JsonArray>(&mut buf);
1825 writer.write(batch).unwrap();
1826 writer.close().unwrap();
1827 serde_json::from_slice(&buf).unwrap()
1828 };
1829
1830 assert_eq!(
1831 json!([
1832 {
1833 "bytes": "4e656420466c616e64657273"
1834 },
1835 {
1836 "bytes": null // the explicit null
1837 },
1838 {
1839 "bytes": "54726f79204d63436c757265"
1840 }
1841 ]),
1842 json_value,
1843 );
1844 }
1845
1846 // encode and check JSON with no explicit nulls:
1847 {
1848 let mut buf = Vec::new();
1849 let json_value: Value = {
1850 // explicit nulls are off by default, so we don't need
1851 // to set that when creating the writer:
1852 let mut writer = ArrayWriter::new(&mut buf);
1853 writer.write(batch).unwrap();
1854 writer.close().unwrap();
1855 serde_json::from_slice(&buf).unwrap()
1856 };
1857
1858 assert_eq!(
1859 json!([
1860 { "bytes": "4e656420466c616e64657273" },
1861 {},
1862 { "bytes": "54726f79204d63436c757265" }
1863 ]),
1864 json_value
1865 );
1866 }
1867 }
1868
1869 #[test]
1870 fn test_writer_binary() {

Callers 1

test_writer_binaryFunction · 0.70

Calls 4

from_sliceFunction · 0.85
with_explicit_nullsMethod · 0.45
writeMethod · 0.45
closeMethod · 0.45

Tested by 1

test_writer_binaryFunction · 0.56