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

Method cache

datafusion/core/src/dataframe/mod.rs:2395–2410  ·  view source on GitHub ↗

Cache DataFrame as a memory table. Default behavior could be changed using a [`crate::execution::session_state::CacheFactory`] configured via [`SessionState`]. ``` # use datafusion::prelude::*; # use datafusion::error::Result; # #[tokio::main] # async fn main() -> Result<()> { let ctx = SessionContext::new(); let df = ctx .read_csv("tests/data/example.csv", CsvReadOptions::new()) .await?; let df

(self)

Source from the content-addressed store, hash-verified

2393 /// # }
2394 /// ```
2395 pub async fn cache(self) -> Result<DataFrame> {
2396 if let Some(cache_factory) = self.session_state.cache_factory() {
2397 let new_plan =
2398 cache_factory.create(self.plan, self.session_state.as_ref())?;
2399 Ok(Self::new(*self.session_state, new_plan))
2400 } else {
2401 let context = SessionContext::new_with_state((*self.session_state).clone());
2402 // The schema is consistent with the output
2403 let plan = self.create_physical_plan().await?;
2404 let schema = plan.schema();
2405 let task_ctx = Arc::new(self.task_ctx());
2406 let partitions = collect_partitioned(plan, task_ctx).await?;
2407 let mem_table = MemTable::try_new(schema, partitions)?;
2408 context.read_table(Arc::new(mem_table))
2409 }
2410 }
2411
2412 /// Apply an alias to the DataFrame.
2413 ///

Callers 4

test_cache_mismatchFunction · 0.45
cache_testFunction · 0.45
cache_producer_testFunction · 0.45

Calls 10

newFunction · 0.85
collect_partitionedFunction · 0.85
cache_factoryMethod · 0.80
read_tableMethod · 0.80
createMethod · 0.45
as_refMethod · 0.45
cloneMethod · 0.45
create_physical_planMethod · 0.45
schemaMethod · 0.45
task_ctxMethod · 0.45

Tested by 3

test_cache_mismatchFunction · 0.36
cache_testFunction · 0.36
cache_producer_testFunction · 0.36