cube
cube copied to clipboard
Pre-aggregations don't respect `offset: start` in rolling window measures
Describe the bug
Cube returns different results when a rolling window measure with offset
set to start
is served directly from the data source vs. from a pre-aggregation. Looks like offset
is ignored by pre-aggregations.
To Reproduce Steps to reproduce the behavior:
- Use the following data model:
cube(`order_rolling`, {
sql: `
SELECT 10 AS value, '2023-11-01'::TIMESTAMP AS date UNION ALL
SELECT 10 AS value, '2023-12-01'::TIMESTAMP AS date UNION ALL
SELECT 10 AS value, '2024-01-01'::TIMESTAMP AS date UNION ALL
SELECT 30 AS value, '2024-02-01'::TIMESTAMP AS date UNION ALL
SELECT 50 AS value, '2024-03-01'::TIMESTAMP AS date UNION ALL
SELECT 80 AS value, '2024-04-01'::TIMESTAMP AS date
`,
dimensions: {
date: {
sql: `date`,
type: `time`
},
},
measures: {
current_month_sum: {
sql: `value`,
type: `sum`,
rolling_window: {
trailing: `3 month`,
offset: `start`
}
},
},
// preAggregations: {
// main: {
// measures: [order_rolling.current_month_sum],
// timeDimension: order_rolling.date,
// granularity: `day`,
// refresh_key: {
// every: `1 week`,
// },
// }
// }
});
- Run the following query:
{
"limit": 5000,
"timeDimensions": [
{
"dimension": "order_rolling.date",
"granularity": "month",
"dateRange": [
"2023-11-01",
"2024-07-01"
]
}
],
"measures": [
"order_rolling.current_month_sum"
]
}
- Observe the result
- Uncomment the pre-aggregation
- Run the same query
- Compare the result with the initial one, they will be different.
Expected behavior With a pre-aggregation or not, the result should be the same.
Screenshots
No pre-aggregation:
Pre-aggregation:
Version: 0.35.69
Additional context Reported in Slack: https://cube-js.slack.com/archives/C04KDTE2EF7/p1722975927331859