Skip to content

Add CUBEJS_CUBESTORE_ROLLING_WINDOW_JOIN flag #9351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions packages/cubejs-backend-shared/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,9 @@ const variables: Record<string, (...args: any) => any> = {
cubeStoreNoHeartBeatTimeout: () => get('CUBEJS_CUBESTORE_NO_HEART_BEAT_TIMEOUT')
.default('30')
.asInt(),
cubeStoreRollingWindowJoin: () => get('CUBEJS_CUBESTORE_ROLLING_WINDOW_JOIN')
.default('false')
.asBoolStrict(),

allowUngroupedWithoutPrimaryKey: () => get('CUBEJS_ALLOW_UNGROUPED_WITHOUT_PRIMARY_KEY')
.default(get('CUBESQL_SQL_PUSH_DOWN').default('true').asString())
Expand Down
17 changes: 15 additions & 2 deletions packages/cubejs-schema-compiler/src/adapter/CubeStoreQuery.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import moment from 'moment-timezone';
import { parseSqlInterval } from '@cubejs-backend/shared';
import { parseSqlInterval, getEnv } from '@cubejs-backend/shared';
import { BaseQuery } from './BaseQuery';
import { BaseFilter } from './BaseFilter';
import { BaseMeasure } from './BaseMeasure';
Expand Down Expand Up @@ -30,6 +30,13 @@ type RollingWindow = {
};

export class CubeStoreQuery extends BaseQuery {
private readonly cubeStoreRollingWindowJoin: boolean;

public constructor(compilers, options) {
super(compilers, options);
this.cubeStoreRollingWindowJoin = getEnv('cubeStoreRollingWindowJoin');
}

public newFilter(filter) {
return new CubeStoreFilter(this, filter);
}
Expand All @@ -55,10 +62,16 @@ export class CubeStoreQuery extends BaseQuery {
}

public subtractInterval(date: string, interval: string) {
if (this.cubeStoreRollingWindowJoin) {
return super.subtractInterval(date, interval);
}
return `DATE_SUB(${date}, INTERVAL ${this.formatInterval(interval)})`;
}

public addInterval(date: string, interval: string) {
if (this.cubeStoreRollingWindowJoin) {
return super.addInterval(date, interval);
}
return `DATE_ADD(${date}, INTERVAL ${this.formatInterval(interval)})`;
}

Expand Down Expand Up @@ -179,7 +192,7 @@ export class CubeStoreQuery extends BaseQuery {
cumulativeMeasures: Array<[boolean, BaseMeasure]>,
preAggregationForQuery: any
) {
if (!cumulativeMeasures.length) {
if (this.cubeStoreRollingWindowJoin || !cumulativeMeasures.length) {
return super.regularAndTimeSeriesRollupQuery(regularMeasures, multipliedMeasures, cumulativeMeasures, preAggregationForQuery);
}
const cumulativeMeasuresWithoutMultiplied = cumulativeMeasures.map(([_, measure]) => measure);
Expand Down
Loading