File tree Expand file tree Collapse file tree 2 files changed +35
-8
lines changed
rust/cubesqlplanner/cubesqlplanner/src/planner Expand file tree Collapse file tree 2 files changed +35
-8
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,15 @@ impl PlanSqlTemplates {
6262 . time_grouped_column ( granularity, dimension)
6363 }
6464
65+ pub fn date_bin (
66+ & self ,
67+ interval : String ,
68+ source : String ,
69+ origin : String ,
70+ ) -> Result < String , CubeError > {
71+ self . driver_tools . date_bin ( interval, source, origin)
72+ }
73+
6574 pub fn timestamp_precision ( & self ) -> Result < u32 , CubeError > {
6675 self . driver_tools . timestamp_precision ( )
6776 }
@@ -121,14 +130,6 @@ impl PlanSqlTemplates {
121130 self . driver_tools . count_distinct_approx ( sql)
122131 }
123132
124- pub fn date_bin (
125- & self ,
126- interval : String ,
127- source : String ,
128- origin : String ,
129- ) -> Result < String , CubeError > {
130- self . driver_tools . date_bin ( interval, source, origin)
131- }
132133 pub fn alias_name ( name : & str ) -> String {
133134 let res = name
134135 . with_boundaries ( & [
Original file line number Diff line number Diff line change 11use super :: { GranularityHelper , QueryDateTime , SqlInterval } ;
22use crate :: planner:: sql_evaluator:: SqlCall ;
3+ use crate :: planner:: sql_templates:: PlanSqlTemplates ;
34use chrono_tz:: Tz ;
45use cubenativeutils:: CubeError ;
56use itertools:: Itertools ;
@@ -166,4 +167,29 @@ impl Granularity {
166167 fn default_origin ( timezone : Tz ) -> Result < QueryDateTime , CubeError > {
167168 Ok ( QueryDateTime :: now ( timezone) ?. start_of_year ( ) )
168169 }
170+
171+ pub fn apply_to_input_sql (
172+ & self ,
173+ templates : & PlanSqlTemplates ,
174+ input : String ,
175+ ) -> Result < String , CubeError > {
176+ let res = if self . is_natural_aligned {
177+ if let Some ( offset) = & self . granularity_offset {
178+ let mut res = templates. subtract_interval ( input. clone ( ) , offset. clone ( ) ) ?;
179+ res = templates. time_grouped_column ( self . granularity_from_interval ( ) ?, res) ?;
180+ res = templates. add_interval ( res, offset. clone ( ) ) ?;
181+ res
182+ } else {
183+ templates. time_grouped_column ( self . granularity_from_interval ( ) ?, input) ?
184+ }
185+ } else {
186+ templates. date_bin (
187+ self . granularity_interval . clone ( ) ,
188+ input,
189+ self . origin_local_formatted ( ) ,
190+ ) ?
191+ } ;
192+
193+ Ok ( res)
194+ }
169195}
You can’t perform that action at this time.
0 commit comments