Skip to content

Commit 4f5e5dc

Browse files
authored
feat(tesseract): MultiStage rolling window (#9747)
1 parent 5f5d936 commit 4f5e5dc

File tree

5 files changed

+432
-333
lines changed

5 files changed

+432
-333
lines changed

packages/cubejs-schema-compiler/test/integration/postgres/sql-generation.test.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,15 @@ describe('SQL Generation', () => {
159159
granularity: 'quarter'
160160
}
161161
},
162+
revenue_qtd_proxy: {
163+
type: 'sum',
164+
sql: \`\${revenue}\`,
165+
multi_stage: true,
166+
rollingWindow: {
167+
type: 'to_date',
168+
granularity: 'quarter'
169+
}
170+
},
162171
revenue_day_ago: {
163172
multi_stage: true,
164173
type: 'sum',
@@ -169,6 +178,15 @@ describe('SQL Generation', () => {
169178
type: 'prior',
170179
}]
171180
},
181+
revenueRollingDayAgo: {
182+
type: 'sum',
183+
sql: \`\${revenue_day_ago}\`,
184+
multi_stage: true,
185+
rollingWindow: {
186+
trailing: '2 day',
187+
offset: 'start'
188+
}
189+
},
172190
revenue_day_ago_no_td: {
173191
multi_stage: true,
174192
type: 'sum',
@@ -1033,6 +1051,38 @@ SELECT 1 AS revenue, cast('2024-01-01' AS timestamp) as time UNION ALL
10331051
{ visitors__created_at_day: '2017-01-10T00:00:00.000Z', visitors__revenue_rolling: null }
10341052
]));
10351053

1054+
if (getEnv('nativeSqlPlanner')) {
1055+
it('rolling day ago', async () => runQueryTest({
1056+
measures: [
1057+
'visitors.revenueRollingDayAgo'
1058+
],
1059+
timeDimensions: [{
1060+
dimension: 'visitors.created_at',
1061+
granularity: 'day',
1062+
dateRange: ['2017-01-01', '2017-01-10']
1063+
}],
1064+
order: [{
1065+
id: 'visitors.created_at'
1066+
}],
1067+
timezone: 'America/Los_Angeles'
1068+
}, [
1069+
{ visitors__created_at_day: '2017-01-01T00:00:00.000Z', visitors__revenue_rolling_day_ago: null },
1070+
{ visitors__created_at_day: '2017-01-02T00:00:00.000Z', visitors__revenue_rolling_day_ago: null },
1071+
{ visitors__created_at_day: '2017-01-03T00:00:00.000Z', visitors__revenue_rolling_day_ago: null },
1072+
{ visitors__created_at_day: '2017-01-04T00:00:00.000Z', visitors__revenue_rolling_day_ago: '100' },
1073+
{ visitors__created_at_day: '2017-01-05T00:00:00.000Z', visitors__revenue_rolling_day_ago: '100' },
1074+
{ visitors__created_at_day: '2017-01-06T00:00:00.000Z', visitors__revenue_rolling_day_ago: '200' },
1075+
{ visitors__created_at_day: '2017-01-07T00:00:00.000Z', visitors__revenue_rolling_day_ago: '500' },
1076+
{ visitors__created_at_day: '2017-01-08T00:00:00.000Z', visitors__revenue_rolling_day_ago: '1200' },
1077+
{ visitors__created_at_day: '2017-01-09T00:00:00.000Z', visitors__revenue_rolling_day_ago: '900' },
1078+
{ visitors__created_at_day: '2017-01-10T00:00:00.000Z', visitors__revenue_rolling_day_ago: null }
1079+
]));
1080+
} else {
1081+
it.skip('rolling count without date range', () => {
1082+
// Skipping because it works only in Tesseract
1083+
});
1084+
}
1085+
10361086
it('rolling multiplied', async () => runQueryTest({
10371087
measures: [
10381088
'visitors.revenueRolling',
@@ -1702,6 +1752,34 @@ SELECT 1 AS revenue, cast('2024-01-01' AS timestamp) as time UNION ALL
17021752
{ visitors__created_at_day: '2017-01-10T00:00:00.000Z', visitors__revenue_qtd: '1500' }
17031753
]));
17041754

1755+
if (getEnv('nativeSqlPlanner')) {
1756+
it('rolling qtd proxy', async () => runQueryTest({
1757+
measures: [
1758+
'visitors.revenue_qtd_proxy'
1759+
],
1760+
timeDimensions: [{
1761+
dimension: 'visitors.created_at',
1762+
granularity: 'day',
1763+
dateRange: ['2017-01-05', '2017-01-10']
1764+
}],
1765+
order: [{
1766+
id: 'visitors.created_at'
1767+
}],
1768+
timezone: 'America/Los_Angeles'
1769+
}, [
1770+
{ visitors__created_at_day: '2017-01-05T00:00:00.000Z', visitors__revenue_qtd_proxy: '600' },
1771+
{ visitors__created_at_day: '2017-01-06T00:00:00.000Z', visitors__revenue_qtd_proxy: '1500' },
1772+
{ visitors__created_at_day: '2017-01-07T00:00:00.000Z', visitors__revenue_qtd_proxy: '1500' },
1773+
{ visitors__created_at_day: '2017-01-08T00:00:00.000Z', visitors__revenue_qtd_proxy: '1500' },
1774+
{ visitors__created_at_day: '2017-01-09T00:00:00.000Z', visitors__revenue_qtd_proxy: '1500' },
1775+
{ visitors__created_at_day: '2017-01-10T00:00:00.000Z', visitors__revenue_qtd_proxy: '1500' }
1776+
]));
1777+
} else {
1778+
it.skip('rolling qtd proxy', () => {
1779+
// Skipping because it works only in Tesseract
1780+
});
1781+
}
1782+
17051783
it('CAGR', async () => runQueryTest({
17061784
measures: [
17071785
'visitors.revenue',

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ mod member;
33
mod member_query_planner;
44
mod multi_stage_query_planner;
55
mod query_description;
6-
mod rolling_window_planner;
76

87
pub use applied_state::*;
98
pub use member::*;
109
pub use member_query_planner::MultiStageMemberQueryPlanner;
1110
pub use multi_stage_query_planner::MultiStageQueryPlanner;
1211
pub use query_description::MultiStageQueryDescription;
13-
pub use rolling_window_planner::RollingWindowPlanner;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy