function tempTablePreAggregations(preAggregationsDescriptions) { return R.unnest(preAggregationsDescriptions.map( desc => desc.invalidateKeyQueries.concat([ [desc.loadSql[0].replace('CREATE TABLE', 'CREATE TEMP TABLE'), desc.loadSql[1]] ]).concat( (desc.indexesSql || []).map(({ sql }) => sql) ) )); }
preAggregationsDescription() { return R.pipe(R.unnest, R.uniqBy(desc => desc.tableName))( [this.preAggregationsDescriptionLocal()].concat( this.query.subQueryDimensions.map(d => this.query.subQueryDescription(d).subQuery) .map(q => q.preAggregations.preAggregationsDescription()) ) ); }
preAggregationDescriptionsFor(cube, foundPreAggregation) { if (this.canPartitionsBeUsed(foundPreAggregation)) { const { dimension, partitionDimension } = this.partitionDimension(foundPreAggregation); return R.unnest(partitionDimension.timeSeries().map( range => this.preAggregationDescriptionsForRecursive( cube, this.addPartitionRangeTo(foundPreAggregation, dimension, range) ) )); } return this.preAggregationDescriptionsForRecursive(cube, foundPreAggregation); }
static hasCumulativeMeasures(query) { const measures = (query.measures.concat(query.measureFilters)); const collectLeafMeasures = query.collectLeafMeasures.bind(query); return R.pipe( R.map(m => query.collectFrom([m], collectLeafMeasures, 'collectLeafMeasures')), R.unnest, R.uniq, R.map(p => query.newMeasure(p)), R.any(m => m.isCumulative()) )(measures); }
fullKeyQueryAggregateMeasures() { const measureToHierarchy = this.collectRootMeasureToHieararchy(); const measuresToRender = (multiplied, cumulative) => R.pipe( R.values, R.flatten, R.filter( m => m.multiplied === multiplied && this.newMeasure(m.measure).isCumulative() === cumulative ), R.map(m => m.measure), R.uniq, R.map(m => this.newMeasure(m)) ); const multipliedMeasures = measuresToRender(true, false)(measureToHierarchy); const regularMeasures = measuresToRender(false, false)(measureToHierarchy); const cumulativeMeasures = R.pipe( R.map(multiplied => R.xprod([multiplied], measuresToRender(multiplied, true)(measureToHierarchy))), R.unnest )([false, true]); return { multipliedMeasures, regularMeasures, cumulativeMeasures }; }
transform(cubeName, errorReporter) { const cube = this.getCubeDefinition(cubeName); const duplicateNames = R.compose( R.map(nameToDefinitions => nameToDefinitions[0]), R.toPairs, R.filter(definitionsByName => definitionsByName.length > 1), R.groupBy(nameToDefinition => nameToDefinition[0]), R.unnest, R.map(R.toPairs), R.filter(v => !!v) )([cube.measures, cube.dimensions, cube.segments]); if (duplicateNames.length > 0) { errorReporter.error(`${duplicateNames.join(', ')} defined more than once`); } return Object.assign( { cubeName: () => cube.name }, cube.measures || {}, cube.dimensions || {}, cube.segments || {} ); }
rollupMatchResults() { const { query } = this; if (PreAggregations.hasCumulativeMeasures(query)) { return []; } 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()); }
compile(cubes, errorReporter) { this.edges = R.compose( R.fromPairs, R.unnest, R.map(v => this.buildJoinEdges(v, errorReporter.inContext(`${v.name} cube`))), R.filter(this.cubeValidator.isCubeValid.bind(this.cubeValidator)) )(this.cubeEvaluator.cubeList); this.nodes = R.compose( R.map(groupedByFrom => R.fromPairs(groupedByFrom.map(join => [join.to, 1]))), R.groupBy(join => join.from), R.map(v => v[1]), R.toPairs )(this.edges); this.undirectedNodes = R.compose( R.map(groupedByFrom => R.fromPairs(groupedByFrom.map(join => [join.from, 1]))), R.groupBy(join => join.to), R.unnest, R.map(v => [v[1], { from: v[1].to, to: v[1].from }]), R.toPairs )(this.edges); this.graph = new Graph(this.nodes); }
collectFrom(membersToCollectFrom, fn, methodName, cache) { return R.pipe( R.map(f => f.getMembers()), R.flatten, R.map(s => ( (cache || this.compilerCache).cache( ['collectFrom', methodName].concat( s.path() ? [s.path().join('.')] : [s.cube().name, s.expressionName || s.definition().sql] ), () => fn(() => this.traverseSymbol(s)) ) )), R.unnest, R.uniq, R.filter(R.identity) )( membersToCollectFrom ); }
preAggregationsDescriptionLocal() { const isInPreAggregationQuery = this.query.options.preAggregationQuery; if (!isInPreAggregationQuery) { const preAggregationForQuery = this.findPreAggregationForQuery(); if (preAggregationForQuery) { return this.preAggregationDescriptionsFor(preAggregationForQuery.cube, preAggregationForQuery); } } if ( !isInPreAggregationQuery || isInPreAggregationQuery && this.query.options.useOriginalSqlPreAggregationsInPreAggregation) { return R.pipe( R.map(cube => { const foundPreAggregation = this.findPreAggregationToUseForCube(cube); if (foundPreAggregation) { return this.preAggregationDescriptionsFor(cube, foundPreAggregation); } return null; }), R.filter(R.identity), R.unnest )(this.preAggregationCubes()); } return []; }
joins(tableName, tableDefinition) { return R.unnest(tableDefinition .filter(column => (column.name.match(new RegExp(idRegex, 'i')) && column.name.toLowerCase() !== 'id')) .map(column => {
prepareTableNamesToTables(tableNames) { this.tableNamesToTables = R.pipe( R.unnest, R.groupBy(n => n[0]), R.map(groupedNameToDef => groupedNameToDef.map(nameToDef => nameToDef[1])) )( tableNames.map(tableName => { const [schema, table] = this.parseTableName(tableName); const tableDefinition = this.resolveTableDefinition(tableName); const definition = { schema, table, tableDefinition, tableName }; const tableizeName = inflection.tableize(table); const parts = tableizeName.split('_'); const tableNamesFromParts = R.range(0, parts.length - 1).map(toDrop => inflection.tableize(R.drop(toDrop, parts).join('_'))); const names = R.uniq([table, tableizeName].concat(tableNamesFromParts)); return names.map(n => [n, definition]); }) ); }
segments: R.fromPairs((query.segments || []).map(annotation('segments')).filter(a => !!a)), timeDimensions: R.fromPairs( R.unnest( (query.timeDimensions || []) .filter(td => !!td.granularity)
R.unnest, R.map(join => [ [`${cube.name}-${join[0]}`, {
R.pipe( R.map(m => query.collectFrom([m], collectLeafMeasures, 'collectLeafMeasures')), R.unnest, R.uniq )(measures);