|
5 | 5 | createCubeSchema, |
6 | 6 | createCubeSchemaWithCustomGranularities, |
7 | 7 | createCubeSchemaYaml, |
| 8 | + createECommerceSchema, |
8 | 9 | createJoinedCubesSchema, |
9 | 10 | createSchemaYaml, |
10 | 11 | createSchemaYamlForGroupFilterParamsTests |
@@ -360,6 +361,62 @@ describe('SQL Generation', () => { |
360 | 361 | const expectedParams = ['type_value', 'not_type_value', '3']; |
361 | 362 | expect(queryAndParams[1]).toEqual(expectedParams); |
362 | 363 | }); |
| 364 | + |
| 365 | + it('Simple query - order by for query with filtered timeDimension', async () => { |
| 366 | + const compilersLocal = prepareYamlCompiler( |
| 367 | + createSchemaYaml(createECommerceSchema()) |
| 368 | + ); |
| 369 | + |
| 370 | + await compilersLocal.compiler.compile(); |
| 371 | + |
| 372 | + let query = new PostgresQuery(compilersLocal, { |
| 373 | + measures: [ |
| 374 | + 'orders.count' |
| 375 | + ], |
| 376 | + timeDimensions: [ |
| 377 | + { |
| 378 | + dimension: 'orders.updated_at', |
| 379 | + granularity: 'week' |
| 380 | + }, |
| 381 | + { |
| 382 | + dimension: 'orders.created_at', |
| 383 | + dateRange: [ |
| 384 | + '2016-01-01', |
| 385 | + '2018-01-01' |
| 386 | + ] |
| 387 | + }, |
| 388 | + ], |
| 389 | + order: [{ id: 'orders.updated_at', desc: false }], |
| 390 | + }); |
| 391 | + |
| 392 | + let queryAndParams = query.buildSqlAndParams(); |
| 393 | + expect(queryAndParams[0].includes('ORDER BY 1')).toBeTruthy(); |
| 394 | + |
| 395 | + // The order of time dimensions should have no effect on the `ORDER BY` clause |
| 396 | + |
| 397 | + query = new PostgresQuery(compilersLocal, { |
| 398 | + measures: [ |
| 399 | + 'orders.count' |
| 400 | + ], |
| 401 | + timeDimensions: [ |
| 402 | + { |
| 403 | + dimension: 'orders.created_at', |
| 404 | + dateRange: [ |
| 405 | + '2016-01-01', |
| 406 | + '2018-01-01' |
| 407 | + ] |
| 408 | + }, |
| 409 | + { |
| 410 | + dimension: 'orders.updated_at', |
| 411 | + granularity: 'week' |
| 412 | + } |
| 413 | + ], |
| 414 | + order: [{ id: 'orders.updated_at', desc: false }], |
| 415 | + }); |
| 416 | + |
| 417 | + queryAndParams = query.buildSqlAndParams(); |
| 418 | + expect(queryAndParams[0].includes('ORDER BY 1')).toBeTruthy(); |
| 419 | + }); |
363 | 420 | }); |
364 | 421 |
|
365 | 422 | describe('Custom granularities', () => { |
|
0 commit comments