Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -473,15 +473,21 @@ impl MultiStageQueryPlanner {
}
}

let base_member = MemberSymbol::new_measure(measure.new_unrolling());

if time_dimensions.is_empty() {
let base_state =
self.replace_date_range_for_rolling_window(&rolling_window, state.clone())?;
let rolling_base = self.add_rolling_window_base(
member.clone(),
base_state,
ungrouped,
descriptions,
)?;
let rolling_base = if !measure.is_multi_stage() {
self.add_rolling_window_base(base_member, base_state, false, descriptions)?
} else {
self.make_queries_descriptions(
base_member,
base_state,
descriptions,
resolved_multi_stage_dimensions,
)?
};
return Ok(Some(rolling_base));
}
let uniq_time_dimensions = time_dimensions
Expand All @@ -504,7 +510,6 @@ impl MultiStageQueryPlanner {
&rolling_window,
state.clone(),
)?;
let base_member = MemberSymbol::new_measure(measure.new_unrolling());

let time_series =
self.add_time_series(time_dimension.clone(), state.clone(), descriptions)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ cubes:
rolling_window:
type: to_date
granularity: month
- name: rolling_avg_to_date
type: avg
sql: amount
rolling_window:
type: to_date
granularity: month
- name: rolling_sum_to_date_multistage
multi_stage: true
type: sum
sql: "{total_amount}"
rolling_window:
type: to_date
granularity: month
# Cat 2 — different aggregation types (all trailing 7 day)
- name: rolling_count_7d
type: count
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
source: cubesqlplanner/src/tests/integration/rolling_window/to_date_variations.rs
expression: result
---
orders__rolling_avg_to_date
---------------------------
137.7500000000000000
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
source: cubesqlplanner/src/tests/integration/rolling_window/to_date_variations.rs
expression: result
---
orders__rolling_sum_to_date_multistage
--------------------------------------
2755.00
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,49 @@ async fn test_to_date_no_granularity() {
"#};

let result = ctx.build_sql(query);
// to_date without query granularity — may work or error
match result {
Ok(_sql) => {
if let Some(result) = ctx.try_execute_pg(query, SEED).await {
insta::assert_snapshot!(result);
}
}
Err(e) => {
insta::assert_snapshot!("to_date_no_granularity_error", e.to_string());
}
}
}
#[tokio::test(flavor = "multi_thread")]
async fn test_to_date_no_granularity_multistage() {
let ctx = create_context();

let query = indoc! {r#"
measures:
- orders.rolling_sum_to_date_multistage
"#};

let result = ctx.build_sql(query);
match result {
Ok(_sql) => {
if let Some(result) = ctx.try_execute_pg(query, SEED).await {
insta::assert_snapshot!(result);
}
}
Err(e) => {
insta::assert_snapshot!("to_date_no_granularity_error", e.to_string());
}
}
}

#[tokio::test(flavor = "multi_thread")]
async fn test_to_date_avg_no_time_dimension() {
let ctx = create_context();

let query = indoc! {r#"
measures:
- orders.rolling_avg_to_date
"#};

let result = ctx.build_sql(query);
match result {
Ok(_sql) => {
if let Some(result) = ctx.try_execute_pg(query, SEED).await {
Expand Down
Loading