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

Method try_new

datafusion/core/src/test_util/csv.rs:37–58  ·  view source on GitHub ↗

Creates a new csv file at the specified location

(
        path: PathBuf,
        batches: impl IntoIterator<Item = RecordBatch>,
    )

Source from the content-addressed store, hash-verified

35impl TestCsvFile {
36 /// Creates a new csv file at the specified location
37 pub fn try_new(
38 path: PathBuf,
39 batches: impl IntoIterator<Item = RecordBatch>,
40 ) -> Result<Self> {
41 let file = File::create(&path).unwrap();
42 let builder = WriterBuilder::new().with_header(true);
43 let mut writer = builder.build(file);
44
45 let mut batches = batches.into_iter();
46 let first_batch = batches.next().expect("need at least one record batch");
47 let schema = first_batch.schema();
48
49 let mut num_rows = 0;
50 for batch in batches {
51 writer.write(&batch)?;
52 num_rows += batch.num_rows();
53 }
54
55 println!("Generated test dataset with {num_rows} rows");
56
57 Ok(Self { path, schema })
58 }
59
60 /// The schema of this csv file
61 pub fn schema(&self) -> SchemaRef {

Callers

nothing calls this directly

Calls 8

createFunction · 0.85
newFunction · 0.85
with_headerMethod · 0.45
buildMethod · 0.45
into_iterMethod · 0.45
nextMethod · 0.45
schemaMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected