@@ -48,16 +48,28 @@ describe('PreAggregationsMultiStage', () => {
4848 sql: 'id',
4949 type: 'countDistinctApprox'
5050 },
51- revenue_per_id : {
51+ revenuePerId : {
5252 multi_stage: true,
5353 sql: \`\${revenue} / \${id}\`,
5454 type: 'sum',
5555 add_group_by: [visitors.id],
56- },
56+ },
57+
58+ revenueAndTime: {
59+ multi_stage: true,
60+ sql: \`LENGTH(CONCAT(\${revenue}, ' - ', \${createdAtDay}))\`,
61+ type: 'sum',
62+ add_group_by: [createdAtDay],
63+ },
5764
5865 ratio: {
5966 sql: \`\${uniqueSourceCount} / nullif(\${checkinsTotal}, 0)\`,
6067 type: 'number'
68+ },
69+
70+ testMeas: {
71+ type: 'countDistinct',
72+ sql: \`\${createdAtDay}\`
6173 }
6274 },
6375
@@ -73,14 +85,31 @@ describe('PreAggregationsMultiStage', () => {
7385 },
7486 createdAt: {
7587 type: 'time',
76- sql: 'created_at'
88+ sql: 'created_at',
89+ granularities: {
90+ three_days: {
91+ interval: '1 days',
92+ title: '1 days',
93+ origin: '2017-01-01'
94+ }
95+ }
7796 },
7897 checkinsCount: {
7998 type: 'number',
8099 sql: \`\${visitor_checkins.count}\`,
81100 subQuery: true,
82101 propagateFiltersToSubQuery: true
83102 },
103+ revTest: {
104+ sql: \`CONCAT(\${source}, \${createdAtDay})\`,
105+ type: 'string',
106+ },
107+
108+ createdAtDay: {
109+ type: 'time',
110+ sql: \`\${createdAt.three_days}\`,
111+ },
112+
84113
85114
86115 },
@@ -100,6 +129,14 @@ describe('PreAggregationsMultiStage', () => {
100129 granularity: 'day',
101130 partitionGranularity: 'month',
102131 },
132+ revenueAndTimeRollup: {
133+ type: 'rollup',
134+ measureReferences: [revenue],
135+ dimensionReferences: [source],
136+ timeDimensionReference: createdAt,
137+ granularity: 'day',
138+ partitionGranularity: 'month',
139+ },
103140 }
104141 })
105142
@@ -134,7 +171,7 @@ describe('PreAggregationsMultiStage', () => {
134171 },
135172 created_at: {
136173 type: 'time',
137- sql: 'created_at'
174+ sql: 'created_at',
138175 }
139176 },
140177
@@ -143,56 +180,118 @@ describe('PreAggregationsMultiStage', () => {
143180
144181 ` ) ;
145182
183+ if ( getEnv ( 'nativeSqlPlanner' ) ) {
184+ it ( 'simple multi stage with add_group_by' , ( ) => compiler . compile ( ) . then ( ( ) => {
185+ const query = new PostgresQuery ( { joinGraph, cubeEvaluator, compiler } , {
186+ measures : [
187+ 'visitors.revenuePerId'
188+ ] ,
189+ timeDimensions : [ {
190+ dimension : 'visitors.createdAt' ,
191+ granularity : 'day' ,
192+ dateRange : [ '2017-01-01' , '2017-01-30' ]
193+ } ] ,
194+ timezone : 'America/Los_Angeles' ,
195+ order : [ {
196+ id : 'visitors.createdAt'
197+ } ] ,
198+ preAggregationsSchema : ''
199+ } ) ;
146200
147- it ( 'simple multi stage with add_group_by' , ( ) => compiler . compile ( ) . then ( ( ) => {
148- if ( ! getEnv ( 'nativeSqlPlanner' ) ) {
149- return ;
150- }
151- const query = new PostgresQuery ( { joinGraph, cubeEvaluator, compiler } , {
152- measures : [
153- 'visitors.revenue_per_id'
154- ] ,
155- timeDimensions : [ {
156- dimension : 'visitors.createdAt' ,
157- granularity : 'day' ,
158- dateRange : [ '2017-01-01' , '2017-01-30' ]
159- } ] ,
160- timezone : 'America/Los_Angeles' ,
161- order : [ {
162- id : 'visitors.createdAt'
163- } ] ,
164- preAggregationsSchema : ''
165- } ) ;
166-
167- const preAggregationsDescription : any = query . preAggregations ?. preAggregationsDescription ( ) ;
168- const sqlAndParams = query . buildSqlAndParams ( ) ;
169- console . log ( "!!!! sqlAndParamsl" , sqlAndParams ) ;
170- expect ( preAggregationsDescription [ 0 ] . tableName ) . toEqual ( 'rvis_rollupalias' ) ;
171- expect ( sqlAndParams [ 0 ] ) . toContain ( 'rvis_rollupalias' ) ;
172-
173- return dbRunner . evaluateQueryWithPreAggregations ( query ) . then ( res => {
174- console . log ( "!!!! res" , res ) ;
175- expect ( res ) . toEqual (
201+ const preAggregationsDescription : any = query . preAggregations ?. preAggregationsDescription ( ) ;
202+ const sqlAndParams = query . buildSqlAndParams ( ) ;
203+ console . log ( '!!!! sqlAndParamsl' , sqlAndParams ) ;
204+ expect ( preAggregationsDescription [ 0 ] . tableName ) . toEqual ( 'vis_revenue_per_id_rollup' ) ;
205+ expect ( sqlAndParams [ 0 ] ) . toContain ( 'vis_revenue_per_id_rollup' ) ;
206+
207+ return dbRunner . evaluateQueryWithPreAggregations ( query ) . then ( res => {
208+ expect ( res ) . toEqual (
209+ [
210+ {
211+ vis__created_at_day : '2017-01-02T00:00:00.000Z' ,
212+ vis__revenue_per_id : '100.0000000000000000'
213+ } ,
214+ {
215+ vis__created_at_day : '2017-01-04T00:00:00.000Z' ,
216+ vis__revenue_per_id : '100.0000000000000000'
217+ } ,
218+ {
219+ vis__created_at_day : '2017-01-05T00:00:00.000Z' ,
220+ vis__revenue_per_id : '100.0000000000000000'
221+ } ,
222+ {
223+ vis__created_at_day : '2017-01-06T00:00:00.000Z' ,
224+ vis__revenue_per_id : '200.0000000000000000'
225+ }
226+ ]
227+
228+ ) ;
229+ } ) ;
230+ } ) ) ;
231+ }
232+
233+ it ( 'simple multi stage with add_group_by and time proxy dimension 11' , ( ) => compiler . compile ( ) . then ( ( ) => {
234+ const query = new PostgresQuery ( { joinGraph, cubeEvaluator, compiler } , {
235+ measures : [
236+ 'visitors.revenueAndTime'
237+ ] ,
238+ dimensions : [ 'visitors.source' ] ,
239+ timezone : 'America/Los_Angeles' ,
240+ order : [ {
241+ id : 'visitors.source'
242+ } ] ,
243+ preAggregationsSchema : ''
244+ } ) ;
245+
246+ const preAggregationsDescription : any = query . preAggregations ?. preAggregationsDescription ( ) ;
247+ const sqlAndParams = query . buildSqlAndParams ( ) ;
248+ console . log ( '!!!! sqlAndParamsl' , sqlAndParams ) ;
249+ expect ( preAggregationsDescription [ 0 ] . tableName ) . toEqual ( 'vis_revenue_and_time_rollup' ) ;
250+ expect ( sqlAndParams [ 0 ] ) . toContain ( 'vis_revenue_and_time_rollup' ) ;
251+
252+ return dbRunner . evaluateQueryWithPreAggregations ( query ) . then ( res => {
253+ console . log ( '!!!! res' , res ) ;
254+ expect ( res ) . toEqual (
255+ [
256+ { vis__source : 'google' , vis__revenue_and_time : '25' } ,
257+ { vis__source : 'some' , vis__revenue_and_time : '50' } ,
258+ { vis__source : null , vis__revenue_and_time : '50' }
259+ ]
260+
261+ ) ;
262+ } ) ;
263+ } ) ) ;
264+
265+ it ( 'simple multi stage with add_group_by and time proxy dimension tttmp' , ( ) => compiler . compile ( ) . then ( ( ) => {
266+ const query = new PostgresQuery ( { joinGraph, cubeEvaluator, compiler } , {
267+ measures : [
268+ 'visitors.testMeas'
269+ ] ,
270+ dimensions : [ 'visitor_checkins.source' ] ,
271+ timezone : 'America/Los_Angeles' ,
272+ order : [ {
273+ id : 'visitor_checkins.source'
274+ } ] ,
275+ preAggregationsSchema : ''
276+ } ) ;
277+
278+ const preAggregationsDescription : any = query . preAggregations ?. preAggregationsDescription ( ) ;
279+ const sqlAndParams = query . buildSqlAndParams ( ) ;
280+ console . log ( '!!!! sqlAndParamsl' , sqlAndParams ) ;
281+ /* console.log('!!!! sqlAndParamsl', sqlAndParams);
282+ expect(preAggregationsDescription[0].tableName).toEqual('vis_revenue_and_time_rollup');
283+ expect(sqlAndParams[0]).toContain('vis_revenue_and_time_rollup'); */
284+
285+ return dbRunner . evaluateQueryWithPreAggregations ( query ) . then ( res => {
286+ console . log ( '!!!! res' , res ) ;
287+ expect ( res ) . toEqual (
176288 [
177- {
178- vis__created_at_day : '2017-01-02T00:00:00.000Z' ,
179- vis__revenue_per_id : '100'
180- } ,
181- {
182- vis__created_at_day : '2017-01-04T00:00:00.000Z' ,
183- vis__revenue_per_id : '100'
184- } ,
185- {
186- vis__created_at_day : '2017-01-05T00:00:00.000Z' ,
187- vis__revenue_per_id : '100'
188- } ,
189- {
190- vis__created_at_day : '2017-01-06T00:00:00.000Z' ,
191- vis__revenue_per_id : '200'
192- }
289+ { vis__source : 'google' , vis__revenue_and_time : '25' } ,
290+ { vis__source : 'some' , vis__revenue_and_time : '50' } ,
291+ { vis__source : null , vis__revenue_and_time : '50' }
193292 ]
194293
195- ) ;
196- } ) ;
197- } ) ) ;
294+ ) ;
295+ } ) ;
296+ } ) ) ;
198297} ) ;
0 commit comments