cube-js/cube · error · UserError

Unknown pre-aggregation type '${preAggregation.type}' in '${

Error message

Unknown pre-aggregation type '${preAggregation.type}' in '${cube}'

What it means

Cube's schema compiler only supports a fixed set of pre-aggregation types (e.g. rollup, rollupLambda, originalSql). When compiling a pre-aggregation definition whose 'type' field is not one of the known types, BaseQuery.preAggregationSymbolsForUsedPreAggregations aborts with this UserError. It protects against misspelled or unsupported type declarations in the data model.

Source

Thrown at packages/cubejs-schema-compiler/src/adapter/BaseQuery.js:4479

            collectOriginalSqlPreAggregations
          });
        } else if (preAggregation.type === 'originalSql') {
          const originalSqlPreAggregationQuery = this.preAggregations.originalSqlPreAggregationQuery(
            cube,
            preAggregation
          );
          const cubeFromPath = this.cubeEvaluator.cubeFromPath(cube);
          return this.paramAllocator.buildSqlAndParams(originalSqlPreAggregationQuery.evaluateSymbolSqlWithContext(
            () => {
              if (cubeFromPath.sqlTable) {
                return `SELECT * FROM ${originalSqlPreAggregationQuery.cubeSql(cube)}`;
              }
              return originalSqlPreAggregationQuery.evaluateSql(cube, cubeFromPath.sql);
            },
            { preAggregationQuery: true, collectOriginalSqlPreAggregations }
          ));
        }
        throw new UserError(`Unknown pre-aggregation type '${preAggregation.type}' in '${cube}'`);
      },
      { inputProps: { collectOriginalSqlPreAggregations: [] }, cache: this.queryCache }
    );
  }

  preAggregationOutputColumnTypes(cube, preAggregation) {
    return this.cacheValue(
      ['preAggregationOutputColumnTypes', cube, JSON.stringify(preAggregation)],
      () => {
        if (!preAggregation.outputColumnTypes) {
          return null;
        }

        if (preAggregation.type === 'rollup') {
          const query = this.preAggregations.rollupPreAggregationQuery(cube, preAggregation);

          const evaluatedMapOutputColumnTypes = preAggregation.outputColumnTypes.reduce((acc, outputColumnType) => {
            acc.set(outputColumnType.name, outputColumnType);

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Fix the `type` field of the pre-aggregation to a supported value: 'rollup', 'originalSql', or 'rollupLambda'
  2. Log/print the resolved preAggregation object to confirm what type value actually reaches the compiler (it may come from a factory function)
  3. Check the Cube docs for your version — supported types have changed over time

Example fix

// before
preAggregations: {
  main: {
    type: 'rollups',
    measureReferences: [orders.count]
  }
}
// after
preAggregations: {
  main: {
    type: 'rollup',
    measureReferences: [orders.count]
  }
}
Defensive patterns

Strategy: validation

Validate before calling

const VALID = ['rollup', 'rollupLambda', 'originalSql'];
for (const [name, pa] of Object.entries(cube.preAggregations || {})) {
  if (!VALID.includes(pa.type)) throw new Error(`Pre-aggregation '${name}' has invalid type: ${pa.type}`);
}

Type guard

const isKnownPreAggType = (t) => typeof t === 'string' && ['rollup','rollupLambda','originalSql'].includes(t);

Try / catch

try { await cubeApi.query(query); } catch (e) { if (String(e.message).includes('Unknown pre-aggregation type')) { /* fix model type field */ } throw e; }

Prevention

When it happens

Trigger: A cube defines a pre-aggregation with `type:` set to a misspelled or non-existent value (e.g. 'rollups', 'RollUp', 'originaSql') instead of 'rollup', 'originalSql', or 'rollupLambda'.

Common situations: Typo in the data model YAML/JS; copying an example from docs for an older Cube version whose type name changed; building the pre-aggregation programmatically and passing an invalid type variable.

Related errors


AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02). Data as JSON: /api/errors/36d2ffe35e05b606. Report an issue: GitHub.