milenkovicm commented on code in PR #18688:
URL: https://github.com/apache/datafusion/pull/18688#discussion_r2527949706


##########
datafusion/core/src/execution/context/mod.rs:
##########
@@ -1884,6 +1890,15 @@ pub enum RegisterFunction {
     Table(String, Arc<dyn TableFunctionImpl>),
 }
 
+/// Interface for applying a custom caching strategy.
+/// Implement this trait and register via [`SessionState`]
+/// to create a custom logical node for caching.
+pub trait CacheProducer: Debug + Sync + Send {
+    /// Create a custom logical node for caching
+    /// given a logical plan (of DF to cache).
+    fn create(&self, plan: LogicalPlan) -> Result<Arc<dyn 
UserDefinedLogicalNode>>;

Review Comment:
   maybe we should provide SessionState as parameter as well ?



##########
datafusion/core/tests/dataframe/mod.rs:
##########
@@ -2338,6 +2338,29 @@ async fn cache_test() -> Result<()> {
     Ok(())
 }
 
+#[tokio::test]
+async fn cache_producer_test() -> Result<()> {
+    let df = test_table_with_cache_producer()
+        .await?
+        .select_columns(&["c2", "c3"])?
+        .limit(0, Some(1))?
+        .with_column("sum", cast(col("c2") + col("c3"), DataType::Int64))?;
+
+    let cached_df = df.clone().cache().await?;
+
+    assert_snapshot!(
+        cached_df.clone().into_optimized_plan().unwrap(),
+        @r###"
+    CacheNode
+      Projection: aggregate_test_100.c2, aggregate_test_100.c3, 
CAST(CAST(aggregate_test_100.c2 AS Int64) + CAST(aggregate_test_100.c3 AS 
Int64) AS Int64) AS sum
+        Projection: aggregate_test_100.c2, aggregate_test_100.c3
+          Limit: skip=0, fetch=1
+            TableScan: aggregate_test_100, fetch=1
+    "###
+    );

Review Comment:
   I dont think we need to cover physical plan for this case, as it would be up 
to user to provide it 



##########
datafusion/core/src/execution/context/mod.rs:
##########
@@ -1884,6 +1890,15 @@ pub enum RegisterFunction {
     Table(String, Arc<dyn TableFunctionImpl>),
 }
 
+/// Interface for applying a custom caching strategy.
+/// Implement this trait and register via [`SessionState`]
+/// to create a custom logical node for caching.
+pub trait CacheProducer: Debug + Sync + Send {

Review Comment:
   Could we explain that when cache producer is provided user should provide 
its own logical query planner to handle that specific case



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to