Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ export class BaseTimeDimension extends BaseFilter {
return this.granularityObj ? this.granularityObj.resolvedGranularity() : null;
}

public resolvedGranularityAsIs() {
return this.granularityObj ? this.granularityObj.granularity : null;
}

public wildcardRange() {
return [FROM_PARTITION_RANGE, TO_PARTITION_RANGE];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ export class PreAggregations {
public static timeDimensionsAsIs(timeDimensions: BaseTimeDimension[] | undefined): [expressionPath: string, resolvedGranularity: string | null][] {
return timeDimensions && R.sortBy(
([exprPath]) => exprPath,
timeDimensions.map(d => [d.expressionPath(), d.resolvedGranularity()] as [string, string | null]),
timeDimensions.map(d => [d.expressionPath(), d.resolvedGranularityAsIs()] as [string, string | null]),
) || [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ describe('PreAggregations', () => {
granularity: 'halfYear',
allowNonStrictDateRangeMatch: false
},
countAnotherCountCustomGranularityNonStrict: {
measures: [countAnother],
timeDimension: createdAt,
granularity: 'halfYear',
allowNonStrictDateRangeMatch: true
},
sourceAndIdRollup: {
measures: [count],
dimensions: [sourceAndId, source],
Expand Down Expand Up @@ -1451,7 +1457,7 @@ describe('PreAggregations', () => {
});
});

it('pre-aggregation with custom granularity should match its own references', async () => {
it('pre-aggregation with custom granularity should match its own references (allowNonStrictDateRangeMatch=false)', async () => {
await compiler.compile();

const preAggregationId = 'visitors.countAnotherCountCustomGranularity';
Expand All @@ -1477,6 +1483,32 @@ describe('PreAggregations', () => {
expect(preAggregationFromQuery.preAggregationId).toBe(preAggregationId);
});

it('pre-aggregation with custom granularity should match its own references (allowNonStrictDateRangeMatch=true)', async () => {
await compiler.compile();

const preAggregationId = 'visitors.countAnotherCountCustomGranularityNonStrict';
const preAggregations = cubeEvaluator.preAggregations({ preAggregationIds: [preAggregationId] });

const preAggregation = preAggregations[0];
if (preAggregation === undefined) {
throw expect(preAggregation).toBeDefined();
}

const query = new PostgresQuery({ joinGraph, cubeEvaluator, compiler }, {
...preAggregation.references,
preAggregationId: preAggregation.id,
timezone: 'UTC',
});

const preAggregationsDescription: any = query.preAggregations?.preAggregationsDescription();
const preAggregationFromQuery = preAggregationsDescription.find(p => p.preAggregationId === preAggregation.id);
if (preAggregationFromQuery === undefined) {
throw expect(preAggregationFromQuery).toBeDefined();
}

expect(preAggregationFromQuery.preAggregationId).toBe(preAggregationId);
});

it('leaf measure pre-aggregation', async () => {
await compiler.compile();

Expand Down
Loading