Skip to content

Commit dca9d08

Browse files
committed
feat(tesseract): Rolling window over symbols
1 parent 08e3775 commit dca9d08

File tree

5 files changed

+410
-333
lines changed

5 files changed

+410
-333
lines changed

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

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ describe('SQL Generation', () => {
152152
granularity: 'quarter'
153153
}
154154
},
155+
revenue_qtd_proxy: {
156+
type: 'sum',
157+
sql: \`\${revenue}\`,
158+
rollingWindow: {
159+
type: 'to_date',
160+
granularity: 'quarter'
161+
}
162+
},
155163
revenue_day_ago: {
156164
multi_stage: true,
157165
type: 'sum',
@@ -162,6 +170,14 @@ describe('SQL Generation', () => {
162170
type: 'prior',
163171
}]
164172
},
173+
revenueRollingDayAgo: {
174+
type: 'sum',
175+
sql: \`\${revenue_day_ago}\`,
176+
rollingWindow: {
177+
trailing: '2 day',
178+
offset: 'start'
179+
}
180+
},
165181
revenue_day_ago_no_td: {
166182
multi_stage: true,
167183
type: 'sum',
@@ -1026,6 +1042,38 @@ SELECT 1 AS revenue, cast('2024-01-01' AS timestamp) as time UNION ALL
10261042
{ visitors__created_at_day: '2017-01-10T00:00:00.000Z', visitors__revenue_rolling: null }
10271043
]));
10281044

1045+
if (getEnv('nativeSqlPlanner')) {
1046+
it('rolling day ago', async () => runQueryTest({
1047+
measures: [
1048+
'visitors.revenueRollingDayAgo'
1049+
],
1050+
timeDimensions: [{
1051+
dimension: 'visitors.created_at',
1052+
granularity: 'day',
1053+
dateRange: ['2017-01-01', '2017-01-10']
1054+
}],
1055+
order: [{
1056+
id: 'visitors.created_at'
1057+
}],
1058+
timezone: 'America/Los_Angeles'
1059+
}, [
1060+
{ visitors__created_at_day: '2017-01-01T00:00:00.000Z', visitors__revenue_rolling_day_ago: null },
1061+
{ visitors__created_at_day: '2017-01-02T00:00:00.000Z', visitors__revenue_rolling_day_ago: null },
1062+
{ visitors__created_at_day: '2017-01-03T00:00:00.000Z', visitors__revenue_rolling_day_ago: null },
1063+
{ visitors__created_at_day: '2017-01-04T00:00:00.000Z', visitors__revenue_rolling_day_ago: '100' },
1064+
{ visitors__created_at_day: '2017-01-05T00:00:00.000Z', visitors__revenue_rolling_day_ago: '100' },
1065+
{ visitors__created_at_day: '2017-01-06T00:00:00.000Z', visitors__revenue_rolling_day_ago: '200' },
1066+
{ visitors__created_at_day: '2017-01-07T00:00:00.000Z', visitors__revenue_rolling_day_ago: '500' },
1067+
{ visitors__created_at_day: '2017-01-08T00:00:00.000Z', visitors__revenue_rolling_day_ago: '1200' },
1068+
{ visitors__created_at_day: '2017-01-09T00:00:00.000Z', visitors__revenue_rolling_day_ago: '900' },
1069+
{ visitors__created_at_day: '2017-01-10T00:00:00.000Z', visitors__revenue_rolling_day_ago: null }
1070+
]));
1071+
} else {
1072+
it.skip('rolling count without date range', () => {
1073+
// Skipping because it works only in Tesseract
1074+
});
1075+
}
1076+
10291077
it('rolling multiplied', async () => runQueryTest({
10301078
measures: [
10311079
'visitors.revenueRolling',
@@ -1474,6 +1522,34 @@ SELECT 1 AS revenue, cast('2024-01-01' AS timestamp) as time UNION ALL
14741522
{ visitors__created_at_day: '2017-01-10T00:00:00.000Z', visitors__revenue_qtd: '1500' }
14751523
]));
14761524

1525+
if (getEnv('nativeSqlPlanner')) {
1526+
it('rolling qtd proxy', async () => runQueryTest({
1527+
measures: [
1528+
'visitors.revenue_qtd_proxy'
1529+
],
1530+
timeDimensions: [{
1531+
dimension: 'visitors.created_at',
1532+
granularity: 'day',
1533+
dateRange: ['2017-01-05', '2017-01-10']
1534+
}],
1535+
order: [{
1536+
id: 'visitors.created_at'
1537+
}],
1538+
timezone: 'America/Los_Angeles'
1539+
}, [
1540+
{ visitors__created_at_day: '2017-01-05T00:00:00.000Z', visitors__revenue_qtd_proxy: '600' },
1541+
{ visitors__created_at_day: '2017-01-06T00:00:00.000Z', visitors__revenue_qtd_proxy: '1500' },
1542+
{ visitors__created_at_day: '2017-01-07T00:00:00.000Z', visitors__revenue_qtd_proxy: '1500' },
1543+
{ visitors__created_at_day: '2017-01-08T00:00:00.000Z', visitors__revenue_qtd_proxy: '1500' },
1544+
{ visitors__created_at_day: '2017-01-09T00:00:00.000Z', visitors__revenue_qtd_proxy: '1500' },
1545+
{ visitors__created_at_day: '2017-01-10T00:00:00.000Z', visitors__revenue_qtd_proxy: '1500' }
1546+
]));
1547+
} else {
1548+
it.skip('rolling qtd proxy', () => {
1549+
// Skipping because it works only in Tesseract
1550+
});
1551+
}
1552+
14771553
it('CAGR', async () => runQueryTest({
14781554
measures: [
14791555
'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)