Skip to content

Commit

Permalink
fix: Specifying dateRange in time dimension should produce same res…
Browse files Browse the repository at this point in the history
…ult as `inDateRange` in filter

Fixes #962
  • Loading branch information
paveltiunov committed Nov 27, 2020
1 parent 45fe036 commit a7603d7
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/cubejs-schema-compiler/adapter/BaseFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,14 @@ class BaseFilter extends BaseDimension {
}

allocateTimestampParams() {
return this.filterParams().map(p => this.allocateTimestampParam(p));
return this.filterParams().map((p, i) => {
if (i > 1) {
throw new Error(`Expected only 2 parameters for timestamp filter but got: ${this.filterParams()}`);
}
return this.allocateTimestampParam(
i === 0 ? this.inDbTimeZoneDateFrom(p) : this.inDbTimeZoneDateTo(p)
);
});
}

allParamsRepeat(basePart) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ describe('PreAggregations', function test() {
granularity: 'hour',
partitionGranularity: 'hour'
},
partitionedHourlyForRange: {
type: 'rollup',
measureReferences: [checkinsTotal],
dimensionReferences: [source, createdAt],
timeDimensionReference: createdAt,
granularity: 'hour',
partitionGranularity: 'hour'
},
ratio: {
type: 'rollup',
measureReferences: [checkinsTotal, uniqueSourceCount],
Expand Down Expand Up @@ -795,6 +803,54 @@ describe('PreAggregations', function test() {
});
}));

it('partitioned inDateRange', () => compiler.compile().then(() => {
const query = new PostgresQuery({ joinGraph, cubeEvaluator, compiler }, {
measures: [
'visitors.checkinsTotal'
],
dimensions: [
'visitors.source'
],
timezone: 'America/Los_Angeles',
preAggregationsSchema: '',
filters: [{
member: 'visitors.createdAt',
operator: 'inDateRange',
values: ['2016-12-30', '2017-01-05']
}],
order: [{
id: 'visitors.checkinsTotal'
}],
});

const queryAndParams = query.buildSqlAndParams();
console.log(queryAndParams);
const preAggregationsDescription = query.preAggregations.preAggregationsDescription();
console.log(JSON.stringify(preAggregationsDescription, null, 2));

const queries = tempTablePreAggregations(preAggregationsDescription);

console.log(JSON.stringify(queries.concat(queryAndParams)));

return dbRunner.testQueries(
queries.concat([queryAndParams]).map(q => replaceTableName(q, preAggregationsDescription, 12342))
).then(res => {
console.log(JSON.stringify(res));
res.should.be.deepEqual(
[
{
'visitors__source': 'google',
'visitors__checkins_total': '1'
},
{
'visitors__source': 'some',
'visitors__checkins_total': '5'
}
]
);
});
}));

it('partitioned hourly', () => compiler.compile().then(() => {
const query = new PostgresQuery({ joinGraph, cubeEvaluator, compiler }, {
measures: [
Expand Down

0 comments on commit a7603d7

Please sign in to comment.