@cubejs-backend/schema-compiler
Advanced tools
Comparing version 0.12.0 to 0.12.1
@@ -286,50 +286,78 @@ const R = require('ramda'); | ||
if (!this.preAggregationForQuery) { | ||
const query = this.query; | ||
this.preAggregationForQuery = this.rollupMatchResults().find(p => p.canUsePreAggregation); | ||
} | ||
return this.preAggregationForQuery; | ||
} | ||
if (PreAggregations.hasCumulativeMeasures(query)) { | ||
return null; | ||
} | ||
findAutoRollupPreAggregationsForCube(cube, preAggregations) { | ||
if ( | ||
R.any(m => m.path() && m.path()[0] === cube, this.query.measures) || | ||
!this.query.measures.length && !this.query.timeDimensions.length && | ||
R.all(d => d.path() && d.path()[0] === cube, this.query.dimensions) | ||
) { | ||
return R.pipe( | ||
R.toPairs, | ||
R.filter(([k, a]) => a.type === 'autoRollup'), | ||
R.map(([preAggregationName, preAggregation]) => { | ||
const cubeLattice = this.getCubeLattice(cube, preAggregationName, preAggregation); | ||
const optimalPreAggregation = cubeLattice.findOptimalPreAggregationFromLattice(this.query); | ||
return optimalPreAggregation && { | ||
preAggregationName: preAggregationName + this.autoRollupNameSuffix(cube, optimalPreAggregation), | ||
preAggregation: Object.assign( | ||
optimalPreAggregation, | ||
preAggregation | ||
), | ||
cube, | ||
canUsePreAggregation: true | ||
}; | ||
}) | ||
)(preAggregations); | ||
} | ||
return []; | ||
} | ||
const canUsePreAggregation = this.canUsePreAggregationFn(query); | ||
rollupMatchResults() { | ||
const { query } = this; | ||
this.preAggregationForQuery = R.pipe( | ||
R.map(cube => { | ||
const preAggregations = this.query.cubeEvaluator.preAggregationsForCube(cube); | ||
let rollupPreAggregations = R.pipe( | ||
R.toPairs, | ||
R.filter(([k, a]) => a.type === 'rollup'), | ||
R.filter(([k, aggregation]) => canUsePreAggregation(this.evaluateAllReferences(cube, aggregation))), | ||
R.map(([preAggregationName, preAggregation]) => ({ preAggregationName, preAggregation, cube })) | ||
)(preAggregations); | ||
if ( | ||
R.any(m => m.path() && m.path()[0] === cube, this.query.measures) || | ||
!this.query.measures.length && !this.query.timeDimensions.length && | ||
R.all(d => d.path() && d.path()[0] === cube, this.query.dimensions) | ||
) { | ||
const autoRollupPreAggregations = R.pipe( | ||
R.toPairs, | ||
R.filter(([k, a]) => a.type === 'autoRollup'), | ||
R.map(([preAggregationName, preAggregation]) => { | ||
const cubeLattice = this.getCubeLattice(cube, preAggregationName, preAggregation); | ||
const optimalPreAggregation = cubeLattice.findOptimalPreAggregationFromLattice(this.query); | ||
return optimalPreAggregation && { | ||
preAggregationName: preAggregationName + this.autoRollupNameSuffix(cube, optimalPreAggregation), | ||
preAggregation: Object.assign( | ||
optimalPreAggregation, | ||
preAggregation | ||
), | ||
cube | ||
}; | ||
}) | ||
)(preAggregations); | ||
rollupPreAggregations = rollupPreAggregations.concat(autoRollupPreAggregations); | ||
} | ||
return rollupPreAggregations; | ||
}), | ||
R.unnest | ||
)(query.collectCubeNames())[0]; | ||
if (PreAggregations.hasCumulativeMeasures(query)) { | ||
return []; | ||
} | ||
return this.preAggregationForQuery; | ||
const canUsePreAggregation = this.canUsePreAggregationFn(query); | ||
return R.pipe( | ||
R.map(cube => { | ||
const preAggregations = this.query.cubeEvaluator.preAggregationsForCube(cube); | ||
let rollupPreAggregations = | ||
this.findRollupPreAggregationsForCube(cube, canUsePreAggregation, preAggregations); | ||
rollupPreAggregations = rollupPreAggregations.concat( | ||
this.findAutoRollupPreAggregationsForCube(cube, preAggregations) | ||
); | ||
return rollupPreAggregations; | ||
}), | ||
R.unnest | ||
)(query.collectCubeNames()); | ||
} | ||
findRollupPreAggregationsForCube(cube, canUsePreAggregation, preAggregations) { | ||
return R.pipe( | ||
R.toPairs, | ||
R.filter(([k, a]) => a.type === 'rollup'), | ||
R.map(([preAggregationName, preAggregation]) => ({ | ||
preAggregationName, | ||
preAggregation, | ||
cube, | ||
canUsePreAggregation: canUsePreAggregation(this.evaluateAllReferences(cube, preAggregation)) | ||
})) | ||
)(preAggregations); | ||
} | ||
rollupMatchResultDescriptions() { | ||
return this.rollupMatchResults().map(p => ({ | ||
...this.preAggregationDescriptionFor(p.cube, p), | ||
references: this.evaluateAllReferences(p.cube, p.preAggregation), | ||
canUsePreAggregation: p.canUsePreAggregation | ||
})); | ||
} | ||
static hasCumulativeMeasures(query) { | ||
@@ -336,0 +364,0 @@ const measures = (query.measures.concat(query.measureFilters)); |
@@ -6,2 +6,13 @@ # Change Log | ||
## [0.12.1](https://github.com/cube-js/cube.js/compare/v0.12.0...v0.12.1) (2019-11-26) | ||
### Features | ||
* Show used pre-aggregations and match rollup results in Playground ([4a67346](https://github.com/cube-js/cube.js/commit/4a67346)) | ||
# [0.12.0](https://github.com/cube-js/cube.js/compare/v0.11.25...v0.12.0) (2019-11-25) | ||
@@ -8,0 +19,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"author": "Statsbot, Inc.", | ||
"version": "0.12.0", | ||
"version": "0.12.1", | ||
"repository": { | ||
@@ -51,3 +51,3 @@ "type": "git", | ||
"license": "Apache-2.0", | ||
"gitHead": "1e19567b8451359f9238f6efb8da1f2601bb06d8" | ||
"gitHead": "acc2b442f8ccf979ea08b238aa106906e4517fd0" | ||
} |
380192
10419