Skip to content

Commit 9617c3a

Browse files
committed
add tests for named time shifts
1 parent cc4d0e5 commit 9617c3a

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

packages/cubejs-schema-compiler/test/integration/postgres/calendars.test.ts

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ cubes:
7373
- interval: 1 year
7474
type: prior
7575
76+
- name: count_shifted_y_named
77+
type: number
78+
multi_stage: true
79+
sql: "{count}"
80+
time_shift:
81+
- name: one_year
82+
83+
- name: count_shifted_y1d_named
84+
type: number
85+
multi_stage: true
86+
sql: "{count}"
87+
time_shift:
88+
- name: one_year_and_one_day
89+
7690
- name: count_shifted_calendar_m
7791
type: number
7892
multi_stage: true
@@ -244,6 +258,12 @@ cubes:
244258
type: prior
245259
sql: "{CUBE}.retail_date_prev_year"
246260
261+
- name: one_year
262+
sql: "{CUBE}.retail_date_prev_year"
263+
264+
- name: one_year_and_one_day
265+
sql: "({CUBE}.retail_date_prev_year + interval '1 day')"
266+
247267
##### Retail Dates ####
248268
- name: retail_date
249269
sql: retail_date
@@ -282,6 +302,12 @@ cubes:
282302
type: prior
283303
sql: "{CUBE}.retail_date_prev_year"
284304
305+
- name: one_year
306+
sql: "{CUBE}.retail_date_prev_year"
307+
308+
- name: one_year_and_one_day
309+
sql: "({CUBE}.retail_date_prev_year + interval '1 day')"
310+
285311
- name: retail_year
286312
sql: "{CUBE}.retail_year_name"
287313
type: string
@@ -576,6 +602,22 @@ cubes:
576602
},
577603
]));
578604

605+
it('Count shifted by retail year (custom named shift + custom granularity)', async () => runQueryTest({
606+
measures: ['calendar_orders.count', 'calendar_orders.count_shifted_y_named'],
607+
timeDimensions: [{
608+
dimension: 'custom_calendar.retail_date',
609+
granularity: 'year',
610+
dateRange: ['2025-02-02', '2026-02-01']
611+
}],
612+
order: [{ id: 'custom_calendar.retail_date' }]
613+
}, [
614+
{
615+
calendar_orders__count: '37',
616+
calendar_orders__count_shifted_y_named: '39',
617+
custom_calendar__retail_date_year: '2025-02-02T00:00:00.000Z',
618+
},
619+
]));
620+
579621
it('Count shifted by retail month (custom shift + common granularity)', async () => runQueryTest({
580622
measures: ['calendar_orders.count', 'calendar_orders.count_shifted_calendar_m'],
581623
timeDimensions: [{
@@ -677,6 +719,23 @@ cubes:
677719
custom_calendar__retail_date_week: '2025-04-06T00:00:00.000Z',
678720
},
679721
]));
722+
723+
it('Count shifted by retail year and another custom calendar year (2 custom named shifts + custom granularity)', async () => runQueryTest({
724+
measures: ['calendar_orders.count', 'calendar_orders.count_shifted_y_named', 'calendar_orders.count_shifted_y1d_named'],
725+
timeDimensions: [{
726+
dimension: 'custom_calendar.retail_date',
727+
granularity: 'year',
728+
dateRange: ['2025-02-02', '2026-02-01']
729+
}],
730+
order: [{ id: 'custom_calendar.retail_date' }]
731+
}, [
732+
{
733+
calendar_orders__count: '37',
734+
calendar_orders__count_shifted_y_named: '39',
735+
calendar_orders__count_shifted_y1d_named: '39',
736+
custom_calendar__retail_date_year: '2025-02-02T00:00:00.000Z',
737+
},
738+
]));
680739
});
681740

682741
describe('PK dimension time-shifts', () => {
@@ -696,6 +755,22 @@ cubes:
696755
},
697756
]));
698757

758+
it.skip('Count shifted by retail year (custom named shift + custom granularity)1', async () => runQueryTest({
759+
measures: ['calendar_orders.count', 'calendar_orders.count_shifted_y_named'],
760+
timeDimensions: [{
761+
dimension: 'custom_calendar.date_val',
762+
granularity: 'year',
763+
dateRange: ['2025-02-02', '2026-02-01']
764+
}],
765+
order: [{ id: 'custom_calendar.date_val' }]
766+
}, [
767+
{
768+
calendar_orders__count: '37',
769+
calendar_orders__count_shifted_y_named: '39',
770+
custom_calendar__date_val_year: '2025-02-02T00:00:00.000Z',
771+
},
772+
]));
773+
699774
it.skip('Count shifted by retail month (custom shift + common granularity)', async () => runQueryTest({
700775
measures: ['calendar_orders.count', 'calendar_orders.count_shifted_calendar_m'],
701776
timeDimensions: [{
@@ -797,6 +872,23 @@ cubes:
797872
custom_calendar__date_val_week: '2025-04-06T00:00:00.000Z',
798873
},
799874
]));
875+
876+
it.skip('Count shifted by retail year and another custom calendar year (2 custom named shifts + custom granularity)', async () => runQueryTest({
877+
measures: ['calendar_orders.count', 'calendar_orders.count_shifted_y_named', 'calendar_orders.count_shifted_y1d_named'],
878+
timeDimensions: [{
879+
dimension: 'custom_calendar.date_val',
880+
granularity: 'year',
881+
dateRange: ['2025-02-02', '2026-02-01']
882+
}],
883+
order: [{ id: 'custom_calendar.date_val' }]
884+
}, [
885+
{
886+
calendar_orders__count: '37',
887+
calendar_orders__count_shifted_y_named: '39',
888+
calendar_orders__count_shifted_y1d_named: '39',
889+
custom_calendar__date_val_year: '2025-02-02T00:00:00.000Z',
890+
},
891+
]));
800892
});
801893
});
802894
});

0 commit comments

Comments
 (0)