Skip to content

Commit c8c7e20

Browse files
committed
add tests
1 parent 54880a4 commit c8c7e20

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ cubes:
8080
time_shift:
8181
- name: one_year
8282
83+
- name: count_shifted_y_named_common_interval
84+
type: number
85+
multi_stage: true
86+
sql: "{count}"
87+
time_shift:
88+
- name: one_year_common_interval
89+
8390
- name: count_shifted_y1d_named
8491
type: number
8592
multi_stage: true
@@ -261,6 +268,10 @@ cubes:
261268
- name: one_year
262269
sql: "{CUBE}.retail_date_prev_year"
263270
271+
- name: one_year_common_interval
272+
interval: 1 year
273+
type: prior
274+
264275
- name: one_year_and_one_day
265276
sql: "({CUBE}.retail_date_prev_year + interval '1 day')"
266277
@@ -305,6 +316,10 @@ cubes:
305316
- name: one_year
306317
sql: "{CUBE}.retail_date_prev_year"
307318
319+
- name: one_year_common_interval
320+
interval: 1 year
321+
type: prior
322+
308323
- name: one_year_and_one_day
309324
sql: "({CUBE}.retail_date_prev_year + interval '1 day')"
310325
@@ -736,6 +751,22 @@ cubes:
736751
custom_calendar__retail_date_year: '2025-02-02T00:00:00.000Z',
737752
},
738753
]));
754+
755+
it('Count shifted by year (custom named shift with common interval + custom granularity)', async () => runQueryTest({
756+
measures: ['calendar_orders.count', 'calendar_orders.count_shifted_y_named_common_interval'],
757+
timeDimensions: [{
758+
dimension: 'custom_calendar.retail_date',
759+
granularity: 'year',
760+
dateRange: ['2025-02-02', '2026-02-01']
761+
}],
762+
order: [{ id: 'custom_calendar.retail_date' }]
763+
}, [
764+
{
765+
calendar_orders__count: '37',
766+
calendar_orders__count_shifted_y_named_common_interval: '39',
767+
custom_calendar__retail_date_year: '2025-02-02T00:00:00.000Z',
768+
},
769+
]));
739770
});
740771

741772
describe('PK dimension time-shifts', () => {
@@ -889,6 +920,22 @@ cubes:
889920
custom_calendar__date_val_year: '2025-02-02T00:00:00.000Z',
890921
},
891922
]));
923+
924+
it.skip('Count shifted by year (custom named shift with common interval + custom granularity)', async () => runQueryTest({
925+
measures: ['calendar_orders.count', 'calendar_orders.count_shifted_y_named_common_interval'],
926+
timeDimensions: [{
927+
dimension: 'custom_calendar.date_val',
928+
granularity: 'year',
929+
dateRange: ['2025-02-02', '2026-02-01']
930+
}],
931+
order: [{ id: 'custom_calendar.date_val' }]
932+
}, [
933+
{
934+
calendar_orders__count: '37',
935+
calendar_orders__count_shifted_y_named_common_interval: '39',
936+
custom_calendar__retail_date_year: '2025-02-02T00:00:00.000Z',
937+
},
938+
]));
892939
});
893940
});
894941
});

packages/cubejs-schema-compiler/test/unit/fixtures/custom_calendar.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ cubes:
4848
- name: retail_date_prev_year
4949
sql: "{CUBE.retail_date_prev_year}"
5050

51+
- name: prev_year_named_common_interval
52+
interval: 1 year
53+
type: prior
54+
5155
# All needed intervals should be defined explicitly
5256
- interval: 2 year
5357
type: prior

0 commit comments

Comments
 (0)