Skip to content

Commit 14e2626

Browse files
committed
Fix {DATE_OPERATORS}Where methods to return '1 = 1' when the required parameters are unavailable
1 parent d706c88 commit 14e2626

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const dateTimeLocalURegex = /^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d\.\d\d\d\d\d\d$/;
1212
const dateRegex = /^\d\d\d\d-\d\d-\d\d$/;
1313

1414
export class BaseFilter extends BaseDimension {
15+
public static readonly ALWAYS_TRUE: string = '1 = 1';
16+
1517
public readonly measure: any;
1618

1719
public readonly operator: any;
@@ -323,36 +325,57 @@ export class BaseFilter extends BaseDimension {
323325

324326
public inDateRangeWhere(column) {
325327
const [from, to] = this.allocateTimestampParams();
328+
if (!from || !to) {
329+
return BaseFilter.ALWAYS_TRUE;
330+
}
326331
return this.query.timeRangeFilter(column, from, to);
327332
}
328333

329334
public notInDateRangeWhere(column) {
330335
const [from, to] = this.allocateTimestampParams();
336+
if (!from || !to) {
337+
return BaseFilter.ALWAYS_TRUE;
338+
}
331339
return this.query.timeNotInRangeFilter(column, from, to);
332340
}
333341

334342
public onTheDateWhere(column) {
335343
const [from, to] = this.allocateTimestampParams();
344+
if (!from || !to) {
345+
return BaseFilter.ALWAYS_TRUE;
346+
}
336347
return this.query.timeRangeFilter(column, from, to);
337348
}
338349

339350
public beforeDateWhere(column) {
340351
const [before] = this.allocateTimestampParams();
352+
if (!before) {
353+
return BaseFilter.ALWAYS_TRUE;
354+
}
341355
return this.query.beforeDateFilter(column, before);
342356
}
343357

344358
public beforeOrOnDateWhere(column) {
345359
const [before] = this.allocateTimestampParams();
360+
if (!before) {
361+
return BaseFilter.ALWAYS_TRUE;
362+
}
346363
return this.query.beforeOrOnDateFilter(column, before);
347364
}
348365

349366
public afterDateWhere(column) {
350367
const [after] = this.allocateTimestampParams();
368+
if (!after) {
369+
return BaseFilter.ALWAYS_TRUE;
370+
}
351371
return this.query.afterDateFilter(column, after);
352372
}
353373

354374
public afterOrOnDateWhere(column) {
355375
const [after] = this.allocateTimestampParams();
376+
if (!after) {
377+
return BaseFilter.ALWAYS_TRUE;
378+
}
356379
return this.query.afterOrOnDateFilter(column, after);
357380
}
358381

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3784,7 +3784,7 @@ export class BaseQuery {
37843784

37853785
static renderFilterParams(filter, filterParamArgs, allocateParam, newGroupFilter, aliases) {
37863786
if (!filter) {
3787-
return '1 = 1';
3787+
return BaseFilter.ALWAYS_TRUE;
37883788
}
37893789

37903790
if (filter.operator === 'and' || filter.operator === 'or') {
@@ -3815,7 +3815,7 @@ export class BaseQuery {
38153815
}
38163816

38173817
if (!filterParams || !filterParams.length) {
3818-
return '1 = 1';
3818+
return BaseFilter.ALWAYS_TRUE;
38193819
}
38203820

38213821
// eslint-disable-next-line prefer-spread

0 commit comments

Comments
 (0)