cube-js/cube · error · UserError

Output schema is only supported for rollup pre-aggregations

Error message

Output schema is only supported for rollup pre-aggregations

What it means

Output schema (explicit output column typing via outputColumnTypes/output columns mapping) is implemented only for 'rollup' type pre-aggregations. BaseQuery.preAggregationOutputColumnTypes throws this UserError when output schema is requested for any other pre-aggregation type (e.g. originalSql or rollupLambda).

Source

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

            return {
              name: this.aliasName(member),
              type: outputSchemaType.type,
            };
          };

          // The order of the output columns is important, it should match the order in the select statement
          const outputColumnTypes = [
            ...(query.dimensions || []).map(d => findSchemaType(d.dimension)),
            ...(query.timeDimensions || []).map(t => ({
              name: `${this.aliasName(t.dimension)}_${t.granularity}`,
              type: 'TIMESTAMP'
            })),
            ...(query.measures || []).map(m => findSchemaType(m.measure)),
          ];

          return outputColumnTypes;
        }
        throw new UserError('Output schema is only supported for rollup pre-aggregations');
      },
      { inputProps: {}, cache: this.queryCache }
    );
  }

  preAggregationUniqueKeyColumns(cube, preAggregation) {
    if (preAggregation.uniqueKeyColumns) {
      return preAggregation.uniqueKeyColumns.map(key => this.aliasName(`${cube}.${key}`));
    }

    return this.dimensionColumns();
  }

  preAggregationReadOnly(_cube, _preAggregation) {
    return false;
  }

  preAggregationAllowUngroupingWithPrimaryKey(_cube, _preAggregation) {

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Move the output schema declaration to a rollup-type pre-aggregation
  2. Remove the outputColumns/output schema config from the non-rollup pre-aggregation
  3. If column typing is needed for originalSql, cast types in the underlying SQL instead

Example fix

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

Strategy: validation

Validate before calling

if (pa.outputColumnTypes && pa.type !== 'rollup') throw new Error('outputColumnTypes requires type: rollup');

Type guard

const supportsOutputSchema = (pa) => pa?.type === 'rollup' && pa.outputColumnTypes != null;

Try / catch

try { await cubeApi.query(q); } catch (e) { if (e.message === 'Output schema is only supported for rollup pre-aggregations') { /* strip outputColumnTypes from non-rollup pre-aggs */ } throw e; }

Prevention

When it happens

Trigger: Declaring an output columns schema on a pre-aggregation whose type is not 'rollup', or having the compiler evaluate output column types for an originalSql/rollupLambda pre-aggregation that inherited such config.

Common situations: Copying an outputColumns config from a rollup pre-aggregation to an originalSql pre-aggregation; a shared pre-aggregation factory that attaches outputColumns regardless of type; migration tooling generating output schema for all pre-aggregations.

Related errors


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