Skip to content

Commit

Permalink
fix(server-core): RefreshScheduler - pass real dataSource for createQ…
Browse files Browse the repository at this point in the history
…ueryByDataSource
  • Loading branch information
ovr committed Dec 23, 2020
1 parent 658c797 commit de3648b
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions packages/cubejs-server-core/core/RefreshScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@ class RefreshScheduler {

async refreshQueriesForPreAggregation(context, compilerApi, preAggregation, queryingOptions) {
const compilers = await compilerApi.getCompilers();
const query = compilerApi.createQueryByDataSource(compilers, queryingOptions);
if (preAggregation.preAggregation.partitionGranularity) {
const dataSource = query.cubeDataSource(preAggregation.cube);
const cubeFromPath = compilers.cubeEvaluator.cubeFromPath(preAggregation.cube);

if (preAggregation.preAggregation.partitionGranularity) {
const orchestratorApi = this.serverCore.getOrchestratorApi(context);
const [startDate, endDate] =
await Promise.all(
compilerApi.createQueryByDataSource(compilers, queryingOptions, dataSource)
compilerApi.createQueryByDataSource(compilers, queryingOptions, cubeFromPath.dataSource)
.preAggregationStartEndQueries(preAggregation.cube, preAggregation.preAggregation)
.map(sql => orchestratorApi.executeQuery({
query: sql[0],
values: sql[1],
continueWait: true,
cacheKeyQueries: [],
dataSource
dataSource: cubeFromPath.dataSource || 'default'
}))
);

Expand All @@ -45,7 +44,7 @@ class RefreshScheduler {
dateRange
}]
};
const partitionQuery = compilerApi.createQueryByDataSource(compilers, baseQuery);
const partitionQuery = compilerApi.createQueryByDataSource(compilers, baseQuery, cubeFromPath.dataSource);
const { partitionDimension } = partitionQuery.preAggregations.partitionDimension(preAggregation);
return partitionDimension.timeSeries().map(range => ({
...baseQuery,
Expand All @@ -57,7 +56,6 @@ class RefreshScheduler {
} else if (preAggregation.preAggregation.type === 'rollup') {
return [{ ...queryingOptions, ...preAggregation.references }];
} else if (preAggregation.preAggregation.type === 'originalSql') {
const cubeFromPath = query.cubeEvaluator.cubeFromPath(preAggregation.cube);
const measuresCount = Object.keys(cubeFromPath.measures || {}).length;
const dimensionsCount = Object.keys(cubeFromPath.dimensions || {}).length;
if (measuresCount === 0 && dimensionsCount === 0) {
Expand Down Expand Up @@ -117,14 +115,16 @@ class RefreshScheduler {

async refreshCubesRefreshKey(context, compilerApi, queryingOptions) {
const compilers = await compilerApi.getCompilers();
const queryForEvaluation = compilerApi.createQueryByDataSource(compilers, {});
await Promise.all(queryForEvaluation.cubeEvaluator.cubeNames().map(async cube => {
const cubeFromPath = queryForEvaluation.cubeEvaluator.cubeFromPath(cube);

await Promise.all(compilers.cubeEvaluator.cubeNames().map(async cube => {
const cubeFromPath = compilers.cubeEvaluator.cubeFromPath(cube);
const measuresCount = Object.keys(cubeFromPath.measures || {}).length;
const dimensionsCount = Object.keys(cubeFromPath.dimensions || {}).length;

if (measuresCount === 0 && dimensionsCount === 0) {
return;
}

const query = {
...queryingOptions,
...(
Expand All @@ -137,6 +137,7 @@ class RefreshScheduler {
)
};
const sqlQuery = await compilerApi.getSql(query);

const orchestratorApi = this.serverCore.getOrchestratorApi(context);
await orchestratorApi.executeQuery({
...sqlQuery,
Expand Down

0 comments on commit de3648b

Please sign in to comment.