MCPcopy Create free account
hub / github.com/apache/datafusion / test_ndjson_partitioned

Function test_ndjson_partitioned

datafusion/datasource-json/src/source.rs:877–932  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

875
876 #[tokio::test]
877 async fn test_ndjson_partitioned() -> Result<()> {
878 // Build an NDJSON file with a known number of rows.
879 let num_rows: usize = 20;
880 let mut ndjson = String::new();
881 for i in 0..num_rows {
882 ndjson.push_str(&format!("{{\"id\": {i}, \"name\": \"user{i}\"}}\n"));
883 }
884 let ndjson_bytes = Bytes::from(ndjson);
885 let file_size = ndjson_bytes.len() as u64;
886
887 for &cs in CHUNK_SIZES {
888 let (store, path) = make_chunked_store(&ndjson_bytes, cs).await;
889
890 for num_partitions in get_partition_splits() {
891 let batches = collect_partitioned_batches(
892 Arc::clone(&store),
893 &path,
894 file_size,
895 num_partitions,
896 )
897 .await?;
898
899 let total: usize = batches.iter().map(|b| b.num_rows()).sum();
900 assert_eq!(
901 total, num_rows,
902 "Expected {num_rows} rows with {num_partitions} partitions"
903 );
904
905 let result = concat_and_sort_by_id(&batches)?;
906 let ids = result
907 .column(0)
908 .as_any()
909 .downcast_ref::<Int64Array>()
910 .unwrap();
911 let names = result
912 .column(1)
913 .as_any()
914 .downcast_ref::<StringArray>()
915 .unwrap();
916 for i in 0..num_rows {
917 assert_eq!(
918 ids.value(i),
919 i as i64,
920 "id mismatch at row {i} with {num_partitions} partitions"
921 );
922 assert_eq!(
923 names.value(i),
924 format!("user{i}"),
925 "name mismatch at row {i} with {num_partitions} partitions"
926 );
927 }
928 }
929 }
930
931 Ok(())
932 }
933
934 #[tokio::test]

Callers

nothing calls this directly

Calls 11

newFunction · 0.85
make_chunked_storeFunction · 0.85
get_partition_splitsFunction · 0.85
concat_and_sort_by_idFunction · 0.85
sumMethod · 0.80
columnMethod · 0.80
lenMethod · 0.45
mapMethod · 0.45
iterMethod · 0.45
as_anyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…