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

Function write_json_with_order

datafusion/core/tests/dataframe/mod.rs:2867–2920  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2865// Test issue: https://github.com/apache/datafusion/issues/13873
2866#[tokio::test]
2867async fn write_json_with_order() -> Result<()> {
2868 let tmp_dir = TempDir::new()?;
2869 let schema = Arc::new(Schema::new(vec![
2870 Field::new("a", DataType::Int32, true),
2871 Field::new("b", DataType::Int32, true),
2872 ]));
2873
2874 let ctx = SessionContext::new();
2875 let write_df = ctx.read_batch(RecordBatch::try_new(
2876 schema.clone(),
2877 vec![
2878 Arc::new(Int32Array::from(vec![1, 5, 7, 3, 2])),
2879 Arc::new(Int32Array::from(vec![2, 3, 4, 5, 6])),
2880 ],
2881 )?)?;
2882
2883 let test_path = tmp_dir.path().join("test.json");
2884
2885 write_df
2886 .clone()
2887 .write_json(
2888 test_path.to_str().unwrap(),
2889 DataFrameWriteOptions::new().with_sort_by(vec![col("a").sort(true, true)]),
2890 None,
2891 )
2892 .await?;
2893
2894 let ctx = SessionContext::new();
2895 ctx.register_json(
2896 "data",
2897 test_path.to_str().unwrap(),
2898 JsonReadOptions::default().schema(&schema),
2899 )
2900 .await?;
2901
2902 let df = ctx.sql("SELECT * FROM data").await?;
2903 let results = df.collect().await?;
2904
2905 assert_snapshot!(
2906 batches_to_string(&results),
2907 @r"
2908 +---+---+
2909 | a | b |
2910 +---+---+
2911 | 1 | 2 |
2912 | 2 | 6 |
2913 | 3 | 5 |
2914 | 5 | 3 |
2915 | 7 | 4 |
2916 +---+---+
2917 "
2918 );
2919 Ok(())
2920}
2921
2922// Test issue: https://github.com/apache/datafusion/issues/13873
2923#[tokio::test]

Callers

nothing calls this directly

Calls 11

newFunction · 0.85
read_batchMethod · 0.80
with_sort_byMethod · 0.80
sqlMethod · 0.80
collectMethod · 0.80
cloneMethod · 0.45
joinMethod · 0.45
pathMethod · 0.45
write_jsonMethod · 0.45
register_jsonMethod · 0.45
schemaMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…