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

Function write_csv_with_order

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

Source from the content-addressed store, hash-verified

2808// Test issue: https://github.com/apache/datafusion/issues/13873
2809#[tokio::test]
2810async fn write_csv_with_order() -> Result<()> {
2811 let tmp_dir = TempDir::new()?;
2812 let schema = Arc::new(Schema::new(vec![
2813 Field::new("a", DataType::Int32, true),
2814 Field::new("b", DataType::Int32, true),
2815 ]));
2816
2817 let ctx = SessionContext::new();
2818 let write_df = ctx.read_batch(RecordBatch::try_new(
2819 schema.clone(),
2820 vec![
2821 Arc::new(Int32Array::from(vec![1, 5, 7, 3, 2])),
2822 Arc::new(Int32Array::from(vec![2, 3, 4, 5, 6])),
2823 ],
2824 )?)?;
2825
2826 let test_path = tmp_dir.path().join("test.csv");
2827
2828 write_df
2829 .clone()
2830 .write_csv(
2831 test_path.to_str().unwrap(),
2832 DataFrameWriteOptions::new().with_sort_by(vec![col("a").sort(true, true)]),
2833 None,
2834 )
2835 .await?;
2836
2837 let ctx = SessionContext::new();
2838 ctx.register_csv(
2839 "data",
2840 test_path.to_str().unwrap(),
2841 CsvReadOptions::new().schema(&schema),
2842 )
2843 .await?;
2844
2845 let df = ctx.sql("SELECT * FROM data").await?;
2846 let results = df.collect().await?;
2847
2848 assert_snapshot!(
2849 batches_to_string(&results),
2850 @r"
2851 +---+---+
2852 | a | b |
2853 +---+---+
2854 | 1 | 2 |
2855 | 2 | 6 |
2856 | 3 | 5 |
2857 | 5 | 3 |
2858 | 7 | 4 |
2859 +---+---+
2860 "
2861 );
2862 Ok(())
2863}
2864
2865// Test issue: https://github.com/apache/datafusion/issues/13873
2866#[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_csvMethod · 0.45
register_csvMethod · 0.45
schemaMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…