Skip to content

Commit 2a9d6d0

Browse files
committed
fix(tesseract): Issue with multistage rolling window without time dimension
1 parent 0db9e70 commit 2a9d6d0

5 files changed

Lines changed: 82 additions & 8 deletions

File tree

rust/cubesqlplanner/cubesqlplanner/src/planner/planners/multi_stage/multi_stage_query_planner.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -473,15 +473,21 @@ impl MultiStageQueryPlanner {
473473
}
474474
}
475475

476+
let base_member = MemberSymbol::new_measure(measure.new_unrolling());
477+
476478
if time_dimensions.is_empty() {
477479
let base_state =
478480
self.replace_date_range_for_rolling_window(&rolling_window, state.clone())?;
479-
let rolling_base = self.add_rolling_window_base(
480-
member.clone(),
481-
base_state,
482-
ungrouped,
483-
descriptions,
484-
)?;
481+
let rolling_base = if !measure.is_multi_stage() {
482+
self.add_rolling_window_base(base_member, base_state, false, descriptions)?
483+
} else {
484+
self.make_queries_descriptions(
485+
base_member,
486+
base_state,
487+
descriptions,
488+
resolved_multi_stage_dimensions,
489+
)?
490+
};
485491
return Ok(Some(rolling_base));
486492
}
487493
let uniq_time_dimensions = time_dimensions
@@ -504,7 +510,6 @@ impl MultiStageQueryPlanner {
504510
&rolling_window,
505511
state.clone(),
506512
)?;
507-
let base_member = MemberSymbol::new_measure(measure.new_unrolling());
508513

509514
let time_series =
510515
self.add_time_series(time_dimension.clone(), state.clone(), descriptions)?;

rust/cubesqlplanner/cubesqlplanner/src/test_fixtures/schemas/yaml_files/common/integration_rolling_window.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,19 @@ cubes:
8585
rolling_window:
8686
type: to_date
8787
granularity: month
88+
- name: rolling_avg_to_date
89+
type: avg
90+
sql: amount
91+
rolling_window:
92+
type: to_date
93+
granularity: month
94+
- name: rolling_sum_to_date_multistage
95+
multi_stage: true
96+
type: sum
97+
sql: "{total_amount}"
98+
rolling_window:
99+
type: to_date
100+
granularity: month
88101
# Cat 2 — different aggregation types (all trailing 7 day)
89102
- name: rolling_count_7d
90103
type: count
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
source: cubesqlplanner/src/tests/integration/rolling_window/to_date_variations.rs
3+
expression: result
4+
---
5+
orders__rolling_avg_to_date
6+
---------------------------
7+
137.7500000000000000
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
source: cubesqlplanner/src/tests/integration/rolling_window/to_date_variations.rs
3+
expression: result
4+
---
5+
orders__rolling_sum_to_date_multistage
6+
--------------------------------------
7+
2755.00

rust/cubesqlplanner/cubesqlplanner/src/tests/integration/rolling_window/to_date_variations.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,49 @@ async fn test_to_date_no_granularity() {
166166
"#};
167167

168168
let result = ctx.build_sql(query);
169-
// to_date without query granularity — may work or error
169+
match result {
170+
Ok(_sql) => {
171+
if let Some(result) = ctx.try_execute_pg(query, SEED).await {
172+
insta::assert_snapshot!(result);
173+
}
174+
}
175+
Err(e) => {
176+
insta::assert_snapshot!("to_date_no_granularity_error", e.to_string());
177+
}
178+
}
179+
}
180+
#[tokio::test(flavor = "multi_thread")]
181+
async fn test_to_date_no_granularity_multistage() {
182+
let ctx = create_context();
183+
184+
let query = indoc! {r#"
185+
measures:
186+
- orders.rolling_sum_to_date_multistage
187+
"#};
188+
189+
let result = ctx.build_sql(query);
190+
match result {
191+
Ok(_sql) => {
192+
if let Some(result) = ctx.try_execute_pg(query, SEED).await {
193+
insta::assert_snapshot!(result);
194+
}
195+
}
196+
Err(e) => {
197+
insta::assert_snapshot!("to_date_no_granularity_error", e.to_string());
198+
}
199+
}
200+
}
201+
202+
#[tokio::test(flavor = "multi_thread")]
203+
async fn test_to_date_avg_no_time_dimension() {
204+
let ctx = create_context();
205+
206+
let query = indoc! {r#"
207+
measures:
208+
- orders.rolling_avg_to_date
209+
"#};
210+
211+
let result = ctx.build_sql(query);
170212
match result {
171213
Ok(_sql) => {
172214
if let Some(result) = ctx.try_execute_pg(query, SEED).await {

0 commit comments

Comments
 (0)