@@ -32,6 +32,10 @@ describe('PreAggregations', () => {
3232 type: 'count'
3333 },
3434
35+ countAnother: {
36+ type: 'count'
37+ },
38+
3539 checkinsTotal: {
3640 sql: \`\${checkinsCount}\`,
3741 type: 'sum'
@@ -100,6 +104,10 @@ describe('PreAggregations', () => {
100104 hourTenMinOffset: {
101105 interval: '1 hour',
102106 offset: '10 minutes'
107+ },
108+ halfYear: {
109+ interval: '6 months',
110+ origin: '2017-01-01'
103111 }
104112 }
105113 },
@@ -237,6 +245,12 @@ describe('PreAggregations', () => {
237245 granularity: 'hourTenMinOffset',
238246 allowNonStrictDateRangeMatch: false
239247 },
248+ countAnotherCountCustomGranularity: {
249+ measures: [countAnother],
250+ timeDimension: createdAt,
251+ granularity: 'halfYear',
252+ allowNonStrictDateRangeMatch: false
253+ },
240254 sourceAndIdRollup: {
241255 measures: [count],
242256 dimensions: [sourceAndId, source],
@@ -623,6 +637,35 @@ describe('PreAggregations', () => {
623637 } ) ;
624638 } ) ) ;
625639
640+ it ( 'simple pre-aggregation with custom granularity (exact match) 2' , ( ) => compiler . compile ( ) . then ( ( ) => {
641+ const query = new PostgresQuery ( { joinGraph, cubeEvaluator, compiler } , {
642+ measures : [
643+ 'visitors.countAnother'
644+ ] ,
645+ timeDimensions : [ {
646+ dimension : 'visitors.createdAt' ,
647+ dateRange : [ '2017-01-01 00:00:00.000' , '2017-12-31 23:59:59.999' ] ,
648+ granularity : 'halfYear' ,
649+ } ] ,
650+ timezone : 'UTC' ,
651+ preAggregationsSchema : ''
652+ } ) ;
653+
654+ const queryAndParams = query . buildSqlAndParams ( ) ;
655+ console . log ( queryAndParams ) ;
656+ expect ( query . preAggregations ?. preAggregationForQuery ?. canUsePreAggregation ) . toEqual ( true ) ;
657+ expect ( queryAndParams [ 0 ] ) . toMatch ( / v i s i t o r s _ c o u n t _ a n o t h e r _ c o u n t _ c u s t o m _ g r a n u l a r i t y / ) ;
658+
659+ return dbRunner . evaluateQueryWithPreAggregations ( query ) . then ( res => {
660+ expect ( res ) . toEqual ( [
661+ {
662+ visitors__count_another : '5' ,
663+ visitors__created_at_halfYear : '2017-01-01T00:00:00.000Z' ,
664+ } ,
665+ ] ) ;
666+ } ) ;
667+ } ) ) ;
668+
626669 it ( 'leaf measure pre-aggregation' , ( ) => compiler . compile ( ) . then ( ( ) => {
627670 const query = new PostgresQuery ( { joinGraph, cubeEvaluator, compiler } , {
628671 measures : [
0 commit comments