Skip to content

Commit 74768e2

Browse files
feat(schema-compiler)!: Set preAggregation.allowNonStrictDateRangeMatch = true by default (#9404)
* feat(schema-compiler)!: Set preAggregation.allowNonStrictDateRangeMatch = true by default * fix tests * Update docs --------- Co-authored-by: Igor Lukanin <[email protected]>
1 parent b6f1690 commit 74768e2

File tree

8 files changed

+46
-23
lines changed

8 files changed

+46
-23
lines changed

docs/pages/product/caching/matching-pre-aggregations.mdx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,10 @@ the values should be the start and end days of the month, i.e.,
7777
`['2020-01-01T00:00:00.000', '2020-01-31T23:59:59.999']`; when the granularity
7878
is `day`, the values should be the start and end hours of the day, i.e.,
7979
`['2020-01-01T00:00:00.000', '2020-01-01T23:59:59.999']`. Date ranges are
80-
inclusive, and the minimum granularity is `second`. Use the
81-
[`allow_non_strict_date_range_match`][ref-non-strict-date-range-match] to allow
82-
a pre-aggregation to match a non-strict date range anyway.
80+
inclusive, and the minimum granularity is `second`. By default, this is ensured
81+
via the [`allow_non_strict_date_range_match`][ref-non-strict-date-range-match]
82+
parameter of pre-aggregations: it allows to match _non-strict date ranges_ and is
83+
set to `true` by default.
8384
- **The time zone in the query must match the time zone of a pre-aggregation.**
8485
You can configure a list of time zones that pre-aggregations will be built for
8586
using the [`scheduled_refresh_time_zones`][ref-conf-scheduled-refresh-time-zones]

docs/pages/product/configuration/visualization-tools/superset.mdx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,6 @@ The `COUNT(*)` aggregate function is being mapped to a measure of type
117117
[count](/reference/data-model/types-and-formats#count) in Cube's
118118
**Orders** data model file.
119119

120-
## Additional configuration
121-
122-
### Pre-aggregations
123-
124-
To allow queries from Superset to match pre-aggregations in Cube, [the
125-
`allow_non_strict_date_range_match`
126-
property][ref-schema-ref-preagg-allownonstrict] must be set to `true` in the
127-
pre-aggregation definition. This is because Superset uses loose date ranges when
128-
generating SQL queries.
129120

130121
[ref-getting-started]: /product/getting-started/cloud
131122
[ref-schema-ref-preagg-allownonstrict]:

docs/pages/reference/configuration/environment-variables.mdx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,16 @@ to use for storing pre-aggregations.
10571057
It can be also set using the [`pre_aggregations_schema` configuration
10581058
option](/reference/configuration/config#pre_aggregations_schema).
10591059

1060+
## `CUBEJS_PRE_AGGREGATIONS_ALLOW_NON_STRICT_DATE_RANGE_MATCH`
1061+
1062+
If `true`, allows non-strict date range matching for pre-aggregations by default.
1063+
This can be overridden for individual pre-aggregations using the
1064+
[`allow_non_strict_date_range_match`][ref-schema-ref-preagg-allownonstrict] parameter.
1065+
1066+
| Possible Values | Default in Development | Default in Production |
1067+
| --------------- | ---------------------- | --------------------- |
1068+
| `true`, `false` | `true` | `true` |
1069+
10601070
## `CUBEJS_REFRESH_WORKER`
10611071

10621072
If `true`, this instance of Cube will **only** refresh pre-aggregations.
@@ -1078,8 +1088,6 @@ mode](/product/caching/using-pre-aggregations#rollup-only-mode) for details.
10781088
It can be also set using the [`orchestrator_options.rollupOnlyMode` configuration
10791089
option](/reference/configuration/config#orchestrator_options).
10801090

1081-
1082-
10831091
## `CUBEJS_SCHEDULED_REFRESH_TIMEZONES`
10841092

10851093
A comma-separated [list of timezones to schedule refreshes
@@ -1712,3 +1720,4 @@ The port for a Cube deployment to listen to API connections on.
17121720
[ref-sql-api-streaming]: /product/apis-integrations/sql-api#streaming
17131721
[ref-row-limit]: /product/apis-integrations/queries#row-limit
17141722
[mysql-server-tz-support]: https://dev.mysql.com/doc/refman/8.4/en/time-zone-support.html
1723+
[ref-schema-ref-preagg-allownonstrict]: /reference/data-model/pre-aggregations#allow_non_strict_date_range_match

docs/pages/reference/data-model/pre-aggregations.mdx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,14 +1110,20 @@ refreshes.
11101110

11111111
### `allow_non_strict_date_range_match`
11121112

1113-
The `allow_non_strict_date_range_match` property can be used to allow queries to
1114-
match this pre-aggregation when using non-strict date ranges.
1115-
By default Cube checks if requested date range exactly matches pre-aggregation granularity.
1116-
For example if you're requesting half of a day or your date range filter is just one millisecond off for daily granularity pre-aggregation Cube would not use such a pre-aggregation by default.
1117-
Use this flag to lift this strict check.
1118-
This is useful
1119-
when using a visualization tools such as Tableau or [Apache
1120-
Superset][ref-config-downstream-superset] that use loose date ranges by default.
1113+
The `allow_non_strict_date_range_match` parameter is used to allow queries to match a
1114+
pre-aggregation even if a query contains a _non-strict date range_. It is set to `true`
1115+
by default via the [`CUBEJS_PRE_AGGREGATIONS_ALLOW_NON_STRICT_DATE_RANGE_MATCH`][ref-env-allow-non-strict]
1116+
environment variable.
1117+
1118+
If this flag is set to `false`, Cube would check if requested date range exactly matches
1119+
pre-aggregation granularity. For example, if you're requesting half of a day or your date
1120+
range filter is just one millisecond off for a pre-aggregation with the daily granularity,
1121+
Cube would not use such a pre-aggregation.
1122+
1123+
With this flag set to `true`, that strict check is lifted. It allows queries from BI tools
1124+
to still match pre-aggregations at the cost of a slight potential data discrepancy.
1125+
This is convenient when using Cube with visualization tools such as [Tableau][ref-config-downstream-tableau]
1126+
or [Apache Superset][ref-config-downstream-superset] that use loose date ranges.
11211127

11221128
<CodeTabs>
11231129

@@ -1767,3 +1773,5 @@ cubes:
17671773
[ref-pre-aggs]: /product/caching/using-pre-aggregations
17681774
[ref-ref-cubes]: /reference/data-model/cube
17691775
[ref-custom-granularity]: /reference/data-model/dimensions#granularities
1776+
[ref-env-allow-non-strict]: /reference/configuration/environment-variables#cubejs-pre-aggregations-allow-non-strict-date-range-match
1777+
[ref-config-downstream-tableau]: /product/configuration/visualization-tools/tableau

packages/cubejs-backend-shared/src/env.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ const variables: Record<string, (...args: any) => any> = {
226226
transpilationWorkerThreads: () => get('CUBEJS_TRANSPILATION_WORKER_THREADS')
227227
.default('false')
228228
.asBoolStrict(),
229+
allowNonStrictDateRangeMatching: () => get('CUBEJS_PRE_AGGREGATIONS_ALLOW_NON_STRICT_DATE_RANGE_MATCH')
230+
.default('true')
231+
.asBoolStrict(),
229232
transpilationWorkerThreadsCount: () => get('CUBEJS_TRANSPILATION_WORKER_THREADS_COUNT')
230233
.default('0')
231234
.asInt(),

packages/cubejs-schema-compiler/src/compiler/CubeSymbols.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,12 @@ export class CubeSymbols {
249249
preAggregation.type = 'rollup';
250250
}
251251

252+
if (preAggregation.allowNonStrictDateRangeMatch === undefined &&
253+
['originalSql', 'rollupJoin', 'rollup'].includes(preAggregation.type) &&
254+
(preAggregation.timeDimension || preAggregation.timeDimensions)) {
255+
preAggregation.allowNonStrictDateRangeMatch = getEnv('allowNonStrictDateRangeMatching');
256+
}
257+
252258
if (preAggregation.scheduledRefresh === undefined && preAggregation.type !== 'rollupJoin' && preAggregation.type !== 'rollupLambda') {
253259
preAggregation.scheduledRefresh = getEnv('scheduledRefreshDefault');
254260
}

packages/cubejs-schema-compiler/test/integration/postgres/pre-aggregations.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ describe('PreAggregations', () => {
234234
countCustomGranularity: {
235235
measures: [count],
236236
timeDimension: createdAt,
237-
granularity: 'hourTenMinOffset'
237+
granularity: 'hourTenMinOffset',
238+
allowNonStrictDateRangeMatch: false
238239
},
239240
sourceAndIdRollup: {
240241
measures: [count],

packages/cubejs-schema-compiler/test/unit/schema.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ describe('Schema Testing', () => {
6969
refreshRangeEnd: {
7070
sql: expect.any(Function),
7171
},
72+
allowNonStrictDateRangeMatch: true,
7273
},
7374
countCreatedAt: {
7475
external: true,
@@ -102,6 +103,7 @@ describe('Schema Testing', () => {
102103
refreshRangeEnd: {
103104
sql: expect.any(Function),
104105
},
106+
allowNonStrictDateRangeMatch: true,
105107
}
106108
});
107109
});
@@ -128,6 +130,7 @@ describe('Schema Testing', () => {
128130
refreshRangeEnd: {
129131
sql: expect.any(Function),
130132
},
133+
allowNonStrictDateRangeMatch: true,
131134
},
132135
countCreatedAt: {
133136
// because preview
@@ -162,6 +165,7 @@ describe('Schema Testing', () => {
162165
refreshRangeEnd: {
163166
sql: expect.any(Function),
164167
},
168+
allowNonStrictDateRangeMatch: true,
165169
}
166170
});
167171
});

0 commit comments

Comments
 (0)