constructor(metaResponse) { this.meta = metaResponse; const { cubes } = this.meta; this.cubes = cubes; this.cubesMap = fromPairs(cubes.map(c => [ c.name, { measures: memberMap(c.measures), dimensions: memberMap(c.dimensions), segments: memberMap(c.segments) } ])); }
const toConfigMap = (metaConfig) => ( R.pipe( R.map(c => [c.config.name, c.config]), R.fromPairs )(metaConfig) )
get aliasNameToMember() { return R.fromPairs( this.measures.map(m => [m.unescapedAliasName(), m.measure]).concat( this.dimensions.map(m => [m.unescapedAliasName(), m.dimension]) ).concat( this.timeDimensions.filter(m => !!m.granularity) .map(m => [m.unescapedAliasName(), `${m.dimension}.${m.granularity}`]) ) ); }
// eslint-disable-next-line no-unused-vars compile(contexts, errorReporter) { if (contexts.length === 0) { return; } // TODO: handle duplications, context names must be uniq this.contextDefinitions = R.compose( R.fromPairs, R.map(v => [v.name, this.compileContext(v)]) )(contexts); }
compile(cubes, errorReporter) { super.compile(cubes, errorReporter); const validCubes = this.cubeList.filter(cube => this.cubeValidator.isCubeValid(cube)); this.evaluatedCubes = R.fromPairs(validCubes.map(v => [v.name, v])); this.byFileName = R.groupBy(v => v.fileName, validCubes); this.primaryKeys = R.fromPairs(validCubes.map((v) => { const primaryKeyNameToSymbol = R.compose(R.find(d => d[1].primaryKey), R.toPairs)(v.dimensions || {}); return [ v.name, primaryKeyNameToSymbol && primaryKeyNameToSymbol[0] ]; })); }
cubeCardinalityQueries() { // TODO collect sub queries return R.fromPairs(this.allCubeNames .map(cube => [ cube, this.paramAllocator.buildSqlAndParams(`select count(*) as ${this.escapeColumnName('total_count')} from ${this.cubeSql(cube)} ${this.asSyntaxTable} ${this.cubeAlias(cube)}`) ])); }
simpleQuery() { const ungrouped = this.evaluateSymbolSqlWithContext( () => `${this.commonQuery()} ${this.baseWhere(this.allFilters)}`, { ungroupedForWrappingGroupBy: true } ); const select = this.evaluateSymbolSqlWithContext( () => this.dimensionsForSelect().map( d => d.aliasName() ).concat(this.measures.map(m => m.selectColumns())).filter(s => !!s), { ungroupedAliases: R.fromPairs(this.forSelect().map(m => [m.measure || m.dimension, m.aliasName()])) } ); return `SELECT ${select} FROM (${ungrouped}) AS ${this.escapeColumnName('hive_wrapper')} ${this.groupByClause()}${this.baseHaving(this.measureFilters)}${this.orderBy()}${this.groupByDimensionLimit()}`; }
buildJoinNode(cube) { return R.compose( R.fromPairs, R.map(v => [v[0], 1]), R.toPairs )(cube.joins || {}); }
tablePivot(pivotConfig) { const normalizedPivotConfig = this.normalizePivotConfig(pivotConfig || {}); const isMeasuresPresent = normalizedPivotConfig.x.concat(normalizedPivotConfig.y).includes('measures'); return this.pivot(normalizedPivotConfig).map(({ xValues, yValuesArray }) => fromPairs( normalizedPivotConfig.x .map((key, index) => [key, xValues[index]]) .concat( isMeasuresPresent ? yValuesArray.map(([yValues, measure]) => [ yValues.length ? yValues.join() : 'value', measure ]) : [] ) )); }
compile(cubes, errorReporter) { this.cubeDefinitions = R.pipe( R.map(c => [c.name, c]), R.fromPairs )(cubes); this.cubeList = cubes.map(c => (c.name ? this.getCubeDefinition(c.name) : this.createCube(c))); this.symbols = R.pipe( R.map((c) => [c.name, this.transform(c.name, errorReporter.inContext(`${c.name} cube`))]), R.fromPairs )(cubes); }
async loadQueries() { const { queries } = this; try { this.error = undefined; this.loading = true; const resultPromises = Promise.all(toPairs(queries).map( ([name, query]) => this.cubejsApi.load(query, { mutexObj: this.mutexObj, mutexKey: name }).then(r => [name, r]) )); this.resultSet = fromPairs(await resultPromises); this.loading = false; } catch (exc) { this.error = exc; this.loading = false; } }
granularityHierarchies() { return R.fromPairs(Object.keys(standardGranularitiesParents).map(k => [k, this.granularityParentHierarchy(k)])); }
R.pipe( R.map(s => [s.id, s]), R.fromPairs )
constructor(sourceFiles) { this.fileToTargetSource = {}; this.fileContent = fromPairs(sourceFiles.map(({ fileName, content }) => [fileName, content])); this.importDependencies = {}; }
// eslint-disable-next-line no-unused-vars compile(cubes, errorReporter) { this.byId = R.fromPairs(cubes.map(v => [v.name, v])); }