Skip to content

Commit be42298

Browse files
committed
fix: MySQL segment references support
1 parent 3d52e3b commit be42298

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

packages/cubejs-schema-compiler/adapter/MysqlQuery.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ class MysqlQuery extends BaseQuery {
7070
unixTimestampSql() {
7171
return `UNIX_TIMESTAMP()`;
7272
}
73+
74+
wrapSegmentForDimensionSelect(sql) {
75+
return `IF(${sql}, 1, 0)`;
76+
}
7377
}
7478

7579
module.exports = MysqlQuery;

packages/cubejs-schema-compiler/test/MySqlPreAggregationsTest.js

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,14 @@ describe('MySqlPreAggregations', function test() {
7777
timeDimensionReference: createdAt,
7878
granularity: 'day',
7979
partitionGranularity: 'month'
80-
}
80+
},
81+
googleRollup: {
82+
type: 'rollup',
83+
measureReferences: [count],
84+
segmentReferences: [google],
85+
timeDimensionReference: createdAt,
86+
granularity: 'day',
87+
},
8188
}
8289
})
8390
`);
@@ -163,4 +170,47 @@ describe('MySqlPreAggregations', function test() {
163170
});
164171
});
165172
});
173+
174+
it('segment', () => compiler.compile().then(() => {
175+
const query = new MySqlQuery({ joinGraph, cubeEvaluator, compiler }, {
176+
measures: [
177+
'visitors.count'
178+
],
179+
dimensions: [],
180+
segments: ['visitors.google'],
181+
timezone: 'UTC',
182+
preAggregationsSchema: '',
183+
timeDimensions: [{
184+
dimension: 'visitors.createdAt',
185+
granularity: 'day',
186+
dateRange: ['2016-12-30', '2017-01-06']
187+
}],
188+
order: [{
189+
id: 'visitors.createdAt'
190+
}],
191+
});
192+
193+
const queryAndParams = query.buildSqlAndParams();
194+
console.log(queryAndParams);
195+
const preAggregationsDescription = query.preAggregations.preAggregationsDescription();
196+
console.log(preAggregationsDescription);
197+
198+
const queries = tempTablePreAggregations(preAggregationsDescription);
199+
200+
console.log(JSON.stringify(queries.concat(queryAndParams)));
201+
202+
return dbRunner.testQueries(
203+
queries.concat([queryAndParams]).map(q => replaceTableName(q, preAggregationsDescription, 142))
204+
).then(res => {
205+
console.log(JSON.stringify(res));
206+
res.should.be.deepEqual(
207+
[
208+
{
209+
"visitors__created_at_day": "2017-01-06T00:00:00.000",
210+
"visitors__count": 1
211+
}
212+
]
213+
);
214+
});
215+
}));
166216
});

0 commit comments

Comments
 (0)