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

Method persist

benchmarks/src/sql_benchmark.rs:285–333  ·  view source on GitHub ↗

Calls run and persists results to disk as a CSV file. Requires that the benchmark defines a `result` or `result_query`. Registers the results in a memory table and writes them to disk with pipe delimiters and a header row. # Errors Returns an error if no results are available or if writing to the target path fails.

(&mut self, ctx: &SessionContext)

Source from the content-addressed store, hash-verified

283 /// Returns an error if no results are available or if writing to the
284 /// target path fails.
285 pub async fn persist(&mut self, ctx: &SessionContext) -> Result<()> {
286 self.run(ctx, true).await?;
287
288 // Check if we have result queries to persist for
289 if self.result_queries.is_empty() {
290 info!("No result paths to persist");
291 return Ok(());
292 }
293
294 let results = self
295 .last_results
296 .as_ref()
297 .expect("run should store last_results after successful execution");
298
299 let query = &self.result_queries[0];
300 let path = query.path.as_ref().ok_or_else(|| {
301 exec_datafusion_err!(
302 "Unable to persist results from query '{}', no result specified",
303 query.query
304 )
305 })?;
306
307 info!("Persisting results for query to {path}");
308
309 let first_batch = results
310 .first()
311 .ok_or_else(|| exec_datafusion_err!("Results should be loaded"))?;
312
313 let schema = first_batch.schema();
314 let provider = MemTable::try_new(schema, vec![results.clone()])?;
315
316 ctx.register_table("persist_data", Arc::new(provider))?;
317
318 let df = ctx.table("persist_data").await?;
319 df.write_csv(
320 path,
321 DataFrameWriteOptions::new(),
322 Some(
323 CsvOptions::default()
324 .with_delimiter(b'|')
325 .with_has_header(true),
326 ),
327 )
328 .await?;
329
330 ctx.deregister_table("persist_data")?;
331
332 Ok(())
333 }
334
335 /// Verifies persisted results against expected values.
336 ///

Calls 12

newFunction · 0.85
runMethod · 0.45
is_emptyMethod · 0.45
as_refMethod · 0.45
firstMethod · 0.45
schemaMethod · 0.45
register_tableMethod · 0.45
tableMethod · 0.45
write_csvMethod · 0.45
with_has_headerMethod · 0.45
with_delimiterMethod · 0.45
deregister_tableMethod · 0.45

Tested by

no test coverage detected