diff --git a/packages/cubejs-server-core/core/RefreshScheduler.js b/packages/cubejs-server-core/core/RefreshScheduler.js index bbe57778ea2d0..a04df9f00d92c 100644 --- a/packages/cubejs-server-core/core/RefreshScheduler.js +++ b/packages/cubejs-server-core/core/RefreshScheduler.js @@ -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' })) ); @@ -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, @@ -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) { @@ -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, ...( @@ -137,6 +137,7 @@ class RefreshScheduler { ) }; const sqlQuery = await compilerApi.getSql(query); + const orchestratorApi = this.serverCore.getOrchestratorApi(context); await orchestratorApi.executeQuery({ ...sqlQuery,