1+ use crate :: compile:: date_parser:: parse_date_str;
2+ use crate :: {
3+ compile:: {
4+ engine:: df:: wrapper:: { CubeScanWrappedSqlNode , CubeScanWrapperNode , SqlQuery } ,
5+ test:: find_cube_scans_deep_search,
6+ } ,
7+ config:: ConfigObj ,
8+ sql:: AuthContextRef ,
9+ transport:: { CubeStreamReceiver , LoadRequestMeta , SpanId , TransportService } ,
10+ CubeError ,
11+ } ;
112use async_trait:: async_trait;
13+ use chrono:: { Datelike , NaiveDate } ;
214use cubeclient:: models:: { V1LoadRequestQuery , V1LoadResponse } ;
315pub use datafusion:: {
416 arrow:: {
@@ -18,28 +30,6 @@ pub use datafusion::{
1830 Partitioning , PhysicalPlanner , RecordBatchStream , SendableRecordBatchStream , Statistics ,
1931 } ,
2032} ;
21- use futures:: Stream ;
22- use log:: warn;
23- use std:: {
24- any:: Any ,
25- borrow:: Cow ,
26- fmt,
27- sync:: Arc ,
28- task:: { Context , Poll } ,
29- } ;
30-
31- use crate :: compile:: date_parser:: parse_date_str;
32- use crate :: {
33- compile:: {
34- engine:: df:: wrapper:: { CubeScanWrappedSqlNode , CubeScanWrapperNode , SqlQuery } ,
35- test:: find_cube_scans_deep_search,
36- } ,
37- config:: ConfigObj ,
38- sql:: AuthContextRef ,
39- transport:: { CubeStreamReceiver , LoadRequestMeta , SpanId , TransportService } ,
40- CubeError ,
41- } ;
42- use chrono:: { Datelike , NaiveDate } ;
4333use datafusion:: {
4434 arrow:: {
4535 array:: {
@@ -51,7 +41,17 @@ use datafusion::{
5141 execution:: context:: TaskContext ,
5242 scalar:: ScalarValue ,
5343} ;
44+ use futures:: Stream ;
45+ use log:: warn;
5446use serde_json:: Value ;
47+ use std:: str:: FromStr ;
48+ use std:: {
49+ any:: Any ,
50+ borrow:: Cow ,
51+ fmt,
52+ sync:: Arc ,
53+ task:: { Context , Poll } ,
54+ } ;
5555
5656#[ derive( Debug , Clone , Eq , PartialEq ) ]
5757pub struct RegularMember {
@@ -79,10 +79,33 @@ impl MemberField {
7979 }
8080}
8181
82+ #[ derive( Debug , Clone ) ]
83+ pub enum CacheMode {
84+ StaleIfSlow ,
85+ StaleWhileRevalidate ,
86+ MustRevalidate ,
87+ NoCache ,
88+ }
89+
90+ impl FromStr for CacheMode {
91+ type Err = String ;
92+
93+ fn from_str ( s : & str ) -> std:: result:: Result < Self , Self :: Err > {
94+ match s {
95+ "stale-if-slow" => Ok ( Self :: StaleIfSlow ) ,
96+ "stale-while-revalidate" => Ok ( Self :: StaleWhileRevalidate ) ,
97+ "must-revalidate" => Ok ( Self :: MustRevalidate ) ,
98+ "no-cache" => Ok ( Self :: NoCache ) ,
99+ other => Err ( format ! ( "Unknown cache mode: {}" , other) ) ,
100+ }
101+ }
102+ }
103+
82104#[ derive( Debug , Clone ) ]
83105pub struct CubeScanOptions {
84106 pub change_user : Option < String > ,
85107 pub max_records : Option < usize > ,
108+ pub cache_mode : Option < CacheMode > ,
86109}
87110
88111#[ derive( Debug , Clone ) ]
@@ -679,6 +702,7 @@ async fn load_data(
679702 meta,
680703 schema,
681704 member_fields,
705+ options. cache_mode ,
682706 )
683707 . await
684708 . map_err ( |err| ArrowError :: ComputeError ( err. to_string ( ) ) ) ?;
@@ -1189,6 +1213,7 @@ mod tests {
11891213 _meta_fields : LoadRequestMeta ,
11901214 schema : SchemaRef ,
11911215 member_fields : Vec < MemberField > ,
1216+ _cache_mode : Option < CacheMode > ,
11921217 ) -> Result < Vec < RecordBatch > , CubeError > {
11931218 let response = r#"
11941219 {
@@ -1314,6 +1339,7 @@ mod tests {
13141339 options : CubeScanOptions {
13151340 change_user : None ,
13161341 max_records : None ,
1342+ cache_mode : None ,
13171343 } ,
13181344 transport : get_test_transport ( ) ,
13191345 meta : get_test_load_meta ( DatabaseProtocol :: PostgreSQL ) ,
0 commit comments