cube-js/cube · error · UserError

Output schema type for ${member} not found in pre-aggregatio

Error message

Output schema type for ${member} not found in pre-aggregation ${preAggregation}

What it means

When a pre-aggregation declares an outputColumns/type mapping, BaseQuery evaluates the output column types and builds an output schema by looking up each member (dimension/measure/timeDimension) in the evaluated map. If a member referenced by the query has no corresponding output column type entry, this UserError is thrown — the pre-aggregation's outputColumns do not cover the queried members.

Source

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

    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);
            return acc;
          }, new Map());

          const findSchemaType = member => {
            const outputSchemaType = evaluatedMapOutputColumnTypes.get(member);
            if (!outputSchemaType) {
              throw new UserError(`Output schema type for ${member} not found in pre-aggregation ${preAggregation}`);
            }

            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)),
          ];

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Add the missing member to the pre-aggregation's references/outputColumns so its output column type can be evaluated
  2. Align the query's members with those actually defined in the pre-aggregation
  3. Rebuild/restart the schema compiler after editing the data model to clear stale cached evaluation

Example fix

// before
preAggregations: {
  main: {
    measureReferences: [orders.count],
    outputColumnTypes: { 'orders.count': 'bigint' }
  }
}
// querying orders.totalAmount too
// after
preAggregations: {
  main: {
    measureReferences: [orders.count, orders.totalAmount],
    outputColumnTypes: { 'orders.count': 'bigint', 'orders.totalAmount': 'decimal' }
  }
}
Defensive patterns

Strategy: validation

Validate before calling

const referenced = [...(pa.measureReferences||[]), ...(pa.dimensionReferences||[]), ...(pa.timeDimensionReferences||[])];
const missing = queryMembers.filter(m => !referenced.includes(m));
if ((pa.outputColumnTypes) && missing.length) throw new Error(`Members missing from outputColumnTypes: ${missing}`);

Type guard

const hasOutputTypeFor = (pa, member) => Boolean(pa?.outputColumnTypes && pa.outputColumnTypes[member]);

Try / catch

try { const res = await cubeApi.query(q); } catch (e) { if (/Output schema type for .* not found/.test(e.message)) console.error('Update pre-aggregation outputColumns to cover:', e.message); throw e; }

Prevention

When it happens

Trigger: Querying a measure/dimension that participates in a pre-aggregation with `outputColumnTypes`/output schema declared, but that member is missing from the pre-aggregation definition (or its outputColumns list), so the evaluated map has no entry for it.

Common situations: Adding a new measure to a query without updating the pre-aggregation that serves it; renaming a member in the cube but not in the pre-aggregation's references; outputColumns listing only a subset of the referenced members.

Related errors


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