Skip to content

Commit 313a606

Browse files
authored
fix(schema-compiler): Fix non-match for exact custom granularity pre-aggregation (#9517)
* actual fix * add tests * add tests * lint fix
1 parent ceb7663 commit 313a606

File tree

9 files changed

+230
-87
lines changed

9 files changed

+230
-87
lines changed

packages/cubejs-schema-compiler/src/adapter/BaseDimension.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { BaseQuery } from './BaseQuery';
22
import type { DimensionDefinition, SegmentDefinition } from '../compiler/CubeEvaluator';
3-
import { CubeSymbols } from "../compiler/CubeSymbols";
3+
import { CubeSymbols } from '../compiler/CubeSymbols';
44

55
export class BaseDimension {
66
public readonly expression: any;

packages/cubejs-schema-compiler/src/adapter/BaseMeasure.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { UserError } from '../compiler/UserError';
22
import type { BaseQuery } from './BaseQuery';
33
import { MeasureDefinition } from '../compiler/CubeEvaluator';
4-
import { CubeSymbols } from "../compiler/CubeSymbols";
4+
import { CubeSymbols } from '../compiler/CubeSymbols';
55

66
export class BaseMeasure {
77
public readonly expression: any;

packages/cubejs-schema-compiler/src/adapter/BaseQuery.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
timeSeriesFromCustomInterval
2525
} from '@cubejs-backend/shared';
2626

27-
import { CubeSymbols } from "../compiler/CubeSymbols";
27+
import { CubeSymbols } from '../compiler/CubeSymbols';
2828
import { UserError } from '../compiler/UserError';
2929
import { SqlParser } from '../parser/SqlParser';
3030
import { BaseDimension } from './BaseDimension';

packages/cubejs-schema-compiler/src/adapter/BaseSegment.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { BaseQuery } from './BaseQuery';
2-
import { CubeSymbols } from "../compiler/CubeSymbols";
2+
import { CubeSymbols } from '../compiler/CubeSymbols';
33

44
export class BaseSegment {
55
public readonly expression: any;

packages/cubejs-schema-compiler/src/adapter/BaseTimeDimension.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,15 @@ export class BaseTimeDimension extends BaseFilter {
249249
return this.dateRangeGranularity();
250250
}
251251

252-
if (!this.dateRange) {
253-
return this.granularityObj.minGranularity();
254-
}
255-
256252
// If we have granularity and date range, we need to check
257253
// that the interval and the granularity offset are stacked/fits with date range
258-
if (this.granularityObj.isPredefined() ||
259-
!this.granularityObj.isAlignedWithDateRange([this.dateFromFormatted(), this.dateToFormatted()])) {
254+
if (this.dateRange && (this.granularityObj.isPredefined() ||
255+
!this.granularityObj.isAlignedWithDateRange([this.dateFromFormatted(), this.dateToFormatted()]))) {
260256
return this.query.minGranularity(this.granularityObj.minGranularity(), this.dateRangeGranularity());
261257
}
262258

259+
// We return the granularity as-is, including custom ones,
260+
// because baseQuery.granularityHierarchies correctly expands all custom granularities into hierarchies.
263261
return this.granularityObj.granularity;
264262
}
265263
);

packages/cubejs-schema-compiler/src/adapter/Granularity.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class Granularity {
3131
) {
3232
this.granularity = timeDimension.granularity;
3333
this.predefinedGranularity = isPredefinedGranularity(this.granularity);
34-
this.queryTimezone = query.timezone;
34+
this.queryTimezone = query.timezone || 'UTC';
3535
this.origin = moment.tz(query.timezone).startOf('year'); // Defaults to current year start
3636

3737
if (this.predefinedGranularity) {

packages/cubejs-schema-compiler/src/adapter/PreAggregations.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import R from 'ramda';
22
import { FROM_PARTITION_RANGE, getEnv, TO_PARTITION_RANGE } from '@cubejs-backend/shared';
33

4-
import { CubeSymbols } from "../compiler/CubeSymbols";
4+
import { CubeSymbols } from '../compiler/CubeSymbols';
55
import { UserError } from '../compiler/UserError';
66

77
export class PreAggregations {

0 commit comments

Comments
 (0)