Skip to content

Commit

Permalink
fix: MySQL segment references support
Browse files Browse the repository at this point in the history
  • Loading branch information
paveltiunov committed Mar 24, 2020
1 parent 3d52e3b commit be42298
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/cubejs-schema-compiler/adapter/MysqlQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ class MysqlQuery extends BaseQuery {
unixTimestampSql() {
return `UNIX_TIMESTAMP()`;
}

wrapSegmentForDimensionSelect(sql) {
return `IF(${sql}, 1, 0)`;
}
}

module.exports = MysqlQuery;
52 changes: 51 additions & 1 deletion packages/cubejs-schema-compiler/test/MySqlPreAggregationsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@ describe('MySqlPreAggregations', function test() {
timeDimensionReference: createdAt,
granularity: 'day',
partitionGranularity: 'month'
}
},
googleRollup: {
type: 'rollup',
measureReferences: [count],
segmentReferences: [google],
timeDimensionReference: createdAt,
granularity: 'day',
},
}
})
`);
Expand Down Expand Up @@ -163,4 +170,47 @@ describe('MySqlPreAggregations', function test() {
});
});
});

it('segment', () => compiler.compile().then(() => {
const query = new MySqlQuery({ joinGraph, cubeEvaluator, compiler }, {
measures: [
'visitors.count'
],
dimensions: [],
segments: ['visitors.google'],
timezone: 'UTC',
preAggregationsSchema: '',
timeDimensions: [{
dimension: 'visitors.createdAt',
granularity: 'day',
dateRange: ['2016-12-30', '2017-01-06']
}],
order: [{
id: 'visitors.createdAt'
}],
});

const queryAndParams = query.buildSqlAndParams();
console.log(queryAndParams);
const preAggregationsDescription = query.preAggregations.preAggregationsDescription();
console.log(preAggregationsDescription);

const queries = tempTablePreAggregations(preAggregationsDescription);

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

return dbRunner.testQueries(
queries.concat([queryAndParams]).map(q => replaceTableName(q, preAggregationsDescription, 142))
).then(res => {
console.log(JSON.stringify(res));
res.should.be.deepEqual(
[
{
"visitors__created_at_day": "2017-01-06T00:00:00.000",
"visitors__count": 1
}
]
);
});
}));
});

0 comments on commit be42298

Please sign in to comment.