cube.js data-blending一些说明
cube.js 的data-blending 理论上是可以支持多种查询的的聚合的,但是因为目前有一些限制,使用起来不是很方便
参考代码
gateway.ts 文件
async getNormalizedQueries(query, context) {
query = this.parseQueryParam(query);
let queryType = query_1.QUERY_TYPE.REGULAR_QUERY;
if (!Array.isArray(query)) {
query = this.compareDateRangeTransformer(query);
if (Array.isArray(query)) {
queryType = query_1.QUERY_TYPE.COMPARE_DATE_RANGE_QUERY;
}
}
else {
queryType = query_1.QUERY_TYPE.BLENDING_QUERY;
}
const queries = Array.isArray(query) ? query : [query];
const normalizedQueries = await Promise.all(queries.map((currentQuery) => this.queryTransformer(query_1.normalizeQuery(currentQuery), context)));
if (normalizedQueries.find((currentQuery) => !currentQuery)) {
throw new Error('queryTransformer returned null query. Please check your queryTransformer implementation');
}
if (queryType === query_1.QUERY_TYPE.BLENDING_QUERY) {
// 此处限制了必须使用包含时间区间数据的,参考如下禁用就可以临时解决
// const queryGranularity = query_1.getQueryGranularity(normalizedQueries);
// if (queryGranularity.length > 1) {
// throw new UserError_1.UserError('Data blending query granularities must match');
// }
// if (queryGranularity.filter(Boolean).length === 0) {
// throw new UserError_1.UserError('Data blending query without granularity is not supported');
// }
}
return [queryType, normalizedQueries];
}
参考查询
query 参数传递一个数组(url编码)同时添加queryType=multi 参考
http://localhost:4000/cubejs-api/v1/load?query=%5B%7B%22measures%22%3A%5B%22CallCenter.count%22%5D%2C%22timeDimensions%22%3A%5B%5D%2C%22order%22%3A%7B%22CallCenter.count%22%3A%22desc%22%7D%2C%22dimensions%22%3A%5B%22CallCenter.ccName%22%5D%2C%22limit%22%3A50%7D%2C%7B%22measures%22%3A%5B%22Customer.count%22%5D%2C%22timeDimensions%22%3A%5B%5D%2C%22order%22%3A%7B%22Customer.count%22%3A%22desc%22%7D%2C%22dimensions%22%3A%5B%22Customer.cLastName%22%5D%2C%22limit%22%3A50%7D%5D&queryType=multi
query 实际为
[{"measures":["CallCenter.count"],"timeDimensions":[],"order":{"CallCenter.count":"desc"},"dimensions":["CallCenter.ccName"],"limit":50},{"measures":["Customer.count"],"timeDimensions":[],"order":{"Customer.count":"desc"},"dimensions":["Customer.cLastName"],"limit":50}]
解决方法
可以参考上边的删除限制,目前已经提交了一个issue,期待后边官方的回复