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 @@ -261,6 +261,10 @@ export class BaseTimeDimension extends BaseFilter {
return this.granularityObj?.resolvedGranularity();
}

public isPredefinedGranularity(): boolean {
return this.granularityObj?.isPredefined() || false;
}

public wildcardRange() {
return [FROM_PARTITION_RANGE, TO_PARTITION_RANGE];
}
Expand Down
4 changes: 4 additions & 0 deletions packages/cubejs-schema-compiler/src/adapter/Granularity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export class Granularity {
}
}

public isPredefined(): boolean {
return this.predefinedGranularity;
}

public originFormatted(): string {
return this.origin.format('YYYY-MM-DDTHH:mm:ss.SSS');
}
Expand Down
22 changes: 17 additions & 5 deletions packages/cubejs-schema-compiler/src/adapter/PreAggregations.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,11 @@ export class PreAggregations {
static sortTimeDimensionsWithRollupGranularity(timeDimensions) {
return timeDimensions && R.sortBy(
R.prop(0),
timeDimensions.map(d => [d.expressionPath(), d.rollupGranularity()])
timeDimensions.map(d => (d.isPredefinedGranularity() ?
[d.expressionPath(), d.rollupGranularity(), null] :
// For custom granularities we need to add its name to the list (for exact matches)
[d.expressionPath(), d.rollupGranularity(), d.granularity]
))
) || [];
}

Expand Down Expand Up @@ -548,7 +552,8 @@ export class PreAggregations {
backAlias(references.sortedTimeDimensions || sortTimeDimensions(references.timeDimensions));
const qryTimeDimensions = references.allowNonStrictDateRangeMatch
? transformedQuery.timeDimensions
: transformedQuery.sortedTimeDimensions;
: transformedQuery.sortedTimeDimensions.map(t => t.slice(0, 2));
// slice above is used to exclude possible custom granularity returned from sortTimeDimensionsWithRollupGranularity()

const backAliasMeasures = backAlias(references.measures);
const backAliasSortedDimensions = backAlias(references.sortedDimensions || references.dimensions);
Expand Down Expand Up @@ -615,9 +620,16 @@ export class PreAggregations {
* @returns {Array<Array<string>>}
*/
const expandTimeDimension = (timeDimension) => {
const [dimension, granularity] = timeDimension;
return expandGranularity(granularity)
const [dimension, granularity, customGranularity] = timeDimension;
const res = expandGranularity(granularity)
.map((newGranularity) => [dimension, newGranularity]);

if (customGranularity) {
// For custom granularities we add it upfront to the list (for exact matches)
res.unshift([dimension, customGranularity]);
}

return res;
};

/**
Expand Down Expand Up @@ -782,7 +794,7 @@ export class PreAggregations {
}

/**
* Returns an array of potencially applicable for the query preaggs in the
* Returns an array of potentially applicable for the query preaggs in the
* same order they appear in the schema file.
* @returns {Array<Object>}
*/
Expand Down
Loading