|
| 1 | +import fs from 'fs'; |
| 2 | +import path from 'path'; |
1 | 3 | import { prepareJsCompiler, prepareYamlCompiler } from './PrepareCompiler';
|
2 | 4 | import { createECommerceSchema, createSchemaYaml } from './utils';
|
3 | 5 | import { PostgresQuery, queryClass, QueryFactory } from '../../src';
|
@@ -447,4 +449,165 @@ describe('pre-aggregations', () => {
|
447 | 449 | expect(preAggregationsDescription[0].invalidateKeyQueries[0][0].includes('WHERE ((date(created_at) >= $1::timestamptz AND date(created_at) <= $2::timestamptz))')).toBeTruthy();
|
448 | 450 | expect(preAggregationsDescription[0].invalidateKeyQueries[0][1]).toEqual(['__FROM_PARTITION_RANGE', '__TO_PARTITION_RANGE']);
|
449 | 451 | });
|
| 452 | + |
| 453 | + describe('rollup with multiplied measure', () => { |
| 454 | + let compiler; |
| 455 | + let cubeEvaluator; |
| 456 | + let joinGraph; |
| 457 | + |
| 458 | + beforeAll(async () => { |
| 459 | + const modelContent = fs.readFileSync( |
| 460 | + path.join(process.cwd(), '/test/unit/fixtures/orders_and_items_multiplied_pre_agg.yml'), |
| 461 | + 'utf8' |
| 462 | + ); |
| 463 | + ({ compiler, cubeEvaluator, joinGraph } = prepareYamlCompiler(modelContent)); |
| 464 | + await compiler.compile(); |
| 465 | + }); |
| 466 | + |
| 467 | + it('measure is unmultiplied in query but multiplied in pre-agg', async () => { |
| 468 | + const query = new PostgresQuery({ joinGraph, cubeEvaluator, compiler }, { |
| 469 | + measures: [ |
| 470 | + 'orders.total_qty' |
| 471 | + ], |
| 472 | + dimensions: [], |
| 473 | + timeDimensions: [ |
| 474 | + { |
| 475 | + dimension: 'orders.created_at', |
| 476 | + dateRange: [ |
| 477 | + '2017-05-01', |
| 478 | + '2025-05-01' |
| 479 | + ] |
| 480 | + } |
| 481 | + ] |
| 482 | + }); |
| 483 | + |
| 484 | + const preAggregationsDescription: any = query.preAggregations?.preAggregationsDescription(); |
| 485 | + // Pre-agg should not match |
| 486 | + expect(preAggregationsDescription).toEqual([]); |
| 487 | + }); |
| 488 | + |
| 489 | + it('measure is unmultiplied in query but multiplied in pre-agg + granularity', async () => { |
| 490 | + const query = new PostgresQuery({ joinGraph, cubeEvaluator, compiler }, { |
| 491 | + measures: [ |
| 492 | + 'orders.total_qty' |
| 493 | + ], |
| 494 | + dimensions: [], |
| 495 | + timeDimensions: [ |
| 496 | + { |
| 497 | + dimension: 'orders.created_at', |
| 498 | + dateRange: [ |
| 499 | + '2017-05-01', |
| 500 | + '2025-05-01' |
| 501 | + ], |
| 502 | + granularity: 'month' |
| 503 | + } |
| 504 | + ] |
| 505 | + }); |
| 506 | + |
| 507 | + const preAggregationsDescription: any = query.preAggregations?.preAggregationsDescription(); |
| 508 | + // Pre-agg should not match |
| 509 | + expect(preAggregationsDescription).toEqual([]); |
| 510 | + }); |
| 511 | + |
| 512 | + it('measure is unmultiplied in query but multiplied in pre-agg + granularity + local dimension', async () => { |
| 513 | + const query = new PostgresQuery({ joinGraph, cubeEvaluator, compiler }, { |
| 514 | + measures: [ |
| 515 | + 'orders.total_qty' |
| 516 | + ], |
| 517 | + dimensions: [ |
| 518 | + 'orders.status' |
| 519 | + ], |
| 520 | + timeDimensions: [ |
| 521 | + { |
| 522 | + dimension: 'orders.created_at', |
| 523 | + dateRange: [ |
| 524 | + '2017-05-01', |
| 525 | + '2025-05-01' |
| 526 | + ], |
| 527 | + granularity: 'month' |
| 528 | + } |
| 529 | + ] |
| 530 | + }); |
| 531 | + |
| 532 | + const preAggregationsDescription: any = query.preAggregations?.preAggregationsDescription(); |
| 533 | + // Pre-agg should not match |
| 534 | + expect(preAggregationsDescription).toEqual([]); |
| 535 | + }); |
| 536 | + |
| 537 | + it('measure is unmultiplied in query but multiplied in pre-agg + granularity + external dimension', async () => { |
| 538 | + const query = new PostgresQuery({ joinGraph, cubeEvaluator, compiler }, { |
| 539 | + measures: [ |
| 540 | + 'orders.total_qty' |
| 541 | + ], |
| 542 | + dimensions: [ |
| 543 | + 'line_items.product_id' |
| 544 | + ], |
| 545 | + timeDimensions: [ |
| 546 | + { |
| 547 | + dimension: 'orders.created_at', |
| 548 | + dateRange: [ |
| 549 | + '2017-05-01', |
| 550 | + '2025-05-01' |
| 551 | + ], |
| 552 | + granularity: 'month' |
| 553 | + } |
| 554 | + ] |
| 555 | + }); |
| 556 | + |
| 557 | + const preAggregationsDescription: any = query.preAggregations?.preAggregationsDescription(); |
| 558 | + // Pre-agg should not match |
| 559 | + expect(preAggregationsDescription).toEqual([]); |
| 560 | + }); |
| 561 | + |
| 562 | + it('partial-match of query with pre-agg: 1 measure + all dimensions, no granularity', async () => { |
| 563 | + const query = new PostgresQuery({ joinGraph, cubeEvaluator, compiler }, { |
| 564 | + measures: [ |
| 565 | + 'orders.total_qty' |
| 566 | + ], |
| 567 | + dimensions: [ |
| 568 | + 'orders.status', |
| 569 | + 'line_items.product_id' |
| 570 | + ], |
| 571 | + timeDimensions: [ |
| 572 | + { |
| 573 | + dimension: 'orders.created_at', |
| 574 | + dateRange: [ |
| 575 | + '2017-05-01', |
| 576 | + '2025-05-01' |
| 577 | + ] |
| 578 | + } |
| 579 | + ] |
| 580 | + }); |
| 581 | + |
| 582 | + const preAggregationsDescription: any = query.preAggregations?.preAggregationsDescription(); |
| 583 | + // Pre-agg should not match |
| 584 | + expect(preAggregationsDescription).toEqual([]); |
| 585 | + }); |
| 586 | + |
| 587 | + it('full-match of query with pre-agg: 1 measure + granularity + all dimensions', async () => { |
| 588 | + const query = new PostgresQuery({ joinGraph, cubeEvaluator, compiler }, { |
| 589 | + measures: [ |
| 590 | + 'orders.total_qty' |
| 591 | + ], |
| 592 | + dimensions: [ |
| 593 | + 'orders.status', |
| 594 | + 'line_items.product_id' |
| 595 | + ], |
| 596 | + timeDimensions: [ |
| 597 | + { |
| 598 | + dimension: 'orders.created_at', |
| 599 | + dateRange: [ |
| 600 | + '2017-05-01', |
| 601 | + '2025-05-01' |
| 602 | + ], |
| 603 | + granularity: 'month' |
| 604 | + } |
| 605 | + ] |
| 606 | + }); |
| 607 | + |
| 608 | + const preAggregationsDescription: any = query.preAggregations?.preAggregationsDescription(); |
| 609 | + expect(preAggregationsDescription.length).toEqual(1); |
| 610 | + expect(preAggregationsDescription[0].preAggregationId).toEqual('orders.pre_agg_with_multiplied_measures'); |
| 611 | + }); |
| 612 | + }); |
450 | 613 | });
|
0 commit comments