Skip to content

Commit

Permalink
fix: Internal: ParserError("Expected AND, found: INTERVAL") in case o…
Browse files Browse the repository at this point in the history
…f trailing and leading window parts are defined for pre-aggregated rolling window measure (#8611)
  • Loading branch information
paveltiunov authored Aug 22, 2024
1 parent b67a2f1 commit 18d0620
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export class CubeStoreQuery extends BaseQuery {
const preceding = rollingWindow.trailing ? `${this.toInterval(rollingWindow.trailing)} PRECEDING` : '';
const following = rollingWindow.leading ? `${this.toInterval(rollingWindow.leading)} FOLLOWING` : '';
const offset = ` OFFSET ${rollingWindow.offset || 'end'}`;
const rollingMeasure = `ROLLING(${measureSql} ${preceding && following ? 'RANGE BETWEEN ' : 'RANGE '}${preceding}${preceding && following ? ' ' : ''}${following}${offset})`;
const rollingMeasure = `ROLLING(${measureSql} ${preceding && following ? 'RANGE BETWEEN ' : 'RANGE '}${preceding}${preceding && following ? ' AND ' : ''}${following}${offset})`;
return this.topAggregateWrap(m.measureDefinition(), rollingMeasure);
} else {
const conditionFn = m.isCumulative() ? this.dateFromStartToEndConditionSql(m.dateJoinCondition(), true, true)[0] : timeDimension;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ cube(`visitors`, {
}
},

checkinsPrevMonth: {
sql: `${checkinsCount}`,
type: 'sum',
rollingWindow: {
trailing: '60 day',
leading: '-30 day'
}
},

uniqueSourceCount: {
sql: 'source',
type: 'countDistinct'
Expand Down Expand Up @@ -174,7 +183,7 @@ cube(`visitors`, {
},
partitionedRolling: {
type: 'rollup',
measureReferences: [checkinsRollingTotal, checkinsRolling2day, count],
measureReferences: [checkinsRollingTotal, checkinsRolling2day, checkinsPrevMonth, count],
dimensionReferences: [source],
timeDimensionReference: createdAt,
granularity: 'hour',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,41 @@ Array [
]
`;

exports[`postgresql HTTP Transport Rolling Prev Period: Rolling Prev Period 1`] = `
Array [
Object {
"visitors.checkinsPrevMonth": "1",
"visitors.createdAt": "2017-02-05T00:00:00.000",
"visitors.createdAt.day": "2017-02-05T00:00:00.000",
"visitors.source": "google",
},
Object {
"visitors.checkinsPrevMonth": "3",
"visitors.createdAt": "2017-02-02T00:00:00.000",
"visitors.createdAt.day": "2017-02-02T00:00:00.000",
"visitors.source": "some",
},
Object {
"visitors.checkinsPrevMonth": "3",
"visitors.createdAt": "2017-02-03T00:00:00.000",
"visitors.createdAt.day": "2017-02-03T00:00:00.000",
"visitors.source": "some",
},
Object {
"visitors.checkinsPrevMonth": "5",
"visitors.createdAt": "2017-02-04T00:00:00.000",
"visitors.createdAt.day": "2017-02-04T00:00:00.000",
"visitors.source": "some",
},
Object {
"visitors.checkinsPrevMonth": "5",
"visitors.createdAt": "2017-02-05T00:00:00.000",
"visitors.createdAt.day": "2017-02-05T00:00:00.000",
"visitors.source": "some",
},
]
`;

exports[`postgresql HTTP Transport Rolling with Quarter granularity: Rolling with Quarter granularity 1`] = `
Array [
Object {
Expand Down
21 changes: 21 additions & 0 deletions packages/cubejs-testing/test/pre-aggregations-test-case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,27 @@ const asserts: [options: QueryTestOptions, query: Query][] = [
}
}
],
[
{ name: 'Rolling Prev Period' },
{
measures: [
'visitors.checkinsPrevMonth'
],
dimensions: [
'visitors.source'
],
timezone: 'UTC',
timeDimensions: [{
dimension: 'visitors.createdAt',
granularity: 'day',
dateRange: ['2017-02-02', '2017-02-05']
}],
order: {
'visitors.createdAt': 'asc',
'visitors.source': 'asc'
}
}
],
[
{ name: 'Rolling Mixed With Dimension No Granularity' },
{
Expand Down

0 comments on commit 18d0620

Please sign in to comment.