cube-js/cube · error · UserError

'${prevReferencedPreAggregation.cube}.${prevReferencedPreAgg

Error message

'${prevReferencedPreAggregation.cube}.${prevReferencedPreAggregation.preAggregationName}' and '${referencedPreAggregation.cube}.${referencedPreAggregation.preAggregationName}' referenced by '${cube}.${preAggregationName}' rollupLambda have incompatible partition granularities. '${partitionGranularityPrev}' can't be padded by '${partitionGranularity}'

What it means

A rollupLambda concatenates multiple partitioned rollups; consecutive rollups' partition granularities must be compatible such that the finer one can be padded to the coarser one (minGranularity must equal the second granularity). When 'partitionGranularityPrev' cannot be padded by 'partitionGranularity', this UserError is thrown.

Source

Thrown at packages/cubejs-schema-compiler/src/adapter/PreAggregations.ts:1231

          throw new UserError(`unionWithSourceData can be enabled only for pre-aggregation within '${preAggObj.cube}' cube but '${referencedPreAggregations[i].preAggregationName}' pre-aggregation is defined within '${referencedPreAggregations[i].cube}' cube`);
        }
        referencedPreAggregations[i] = {
          ...referencedPreAggregations[i],
          preAggregation: {
            ...referencedPreAggregations[i].preAggregation,
            unionWithSourceData: i === referencedPreAggregations.length - 1 ? preAggObj.preAggregation.unionWithSourceData : false,
            rollupLambdaId: `${cube}.${preAggregationName}`,
            lastRollupLambda: i === referencedPreAggregations.length - 1,
            rollupLambdaTimeDimensionsReference: preAggObj.references.timeDimensions,
          }
        };
        if (i > 0) {
          const partitionGranularity = PreAggregations.checkPartitionGranularityDefined(cube, preAggregationName, referencedPreAggregations[i]);
          const prevReferencedPreAggregation = referencedPreAggregations[i - 1];
          const partitionGranularityPrev = PreAggregations.checkPartitionGranularityDefined(cube, preAggregationName, prevReferencedPreAggregation);
          const minGranularity = this.query.minGranularity(partitionGranularityPrev, partitionGranularity);
          if (minGranularity !== partitionGranularity) {
            throw new UserError(`'${prevReferencedPreAggregation.cube}.${prevReferencedPreAggregation.preAggregationName}' and '${referencedPreAggregation.cube}.${referencedPreAggregation.preAggregationName}' referenced by '${cube}.${preAggregationName}' rollupLambda have incompatible partition granularities. '${partitionGranularityPrev}' can't be padded by '${partitionGranularity}'`);
          }
        }
        PreAggregations.memberNameMismatchValidation(preAggObj, referencedPreAggregation, 'measures');
        PreAggregations.memberNameMismatchValidation(preAggObj, referencedPreAggregation, 'dimensions');
        PreAggregations.memberNameMismatchValidation(preAggObj, referencedPreAggregation, 'timeDimensions');
      });
      referencedPreAggregations.forEach(preAgg => {
        references.rollupsReferences.push(preAgg.references);
      });
      const lambdaResult = canUsePreAggregation(references);
      return {
        ...preAggObj,
        canUsePreAggregation: lambdaResult.canUse,
        leafMeasureMatch: lambdaResult.leafMeasureMatch,
        referencedPreAggregations,
      };
    } else {
      return preAggObj;

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Align partitionGranularity across all rollups referenced by the lambda (e.g. all 'month').
  2. Reorder the rollups array so granularities are pad-compatible.
  3. Split incompatible rollups into separate lambdas.

Example fix

// before
rollups: [CUBE.ordersByDay /* partitionGranularity: day */, CUBE.ordersByMonth /* month */]
// after
rollups: [CUBE.ordersByDay, CUBE.ordersByWeek, CUBE.ordersByMonth] // or align both to 'month'
Defensive patterns

Strategy: validation

Validate before calling

// Check consecutive partition granularities are pad-compatible before defining the lambda
const ORDER = { day: 1, week: 2, month: 3, quarter: 4, year: 5 };
function padCompatible(prev, cur) { return ORDER[cur] >= ORDER[prev]; }
const grans = rollups.map(r => r.partitionGranularity);
grans.every((g, i) => i === 0 || padCompatible(grans[i - 1], g)) || (() => { throw new Error('Incompatible partitionGranularity sequence in rollupLambda'); })();

Type guard

null

Try / catch

try { await cube.query(query); } catch (e) { if (/have incompatible partition granularities/.test(e.message)) { console.error('Align partitionGranularity or reorder rollups:', e.message); } else throw e; }

Prevention

When it happens

Trigger: In buildRollupLambdaPreAggregations, for i > 0, minGranularity(prev, current) !== current — e.g. chaining a rollup partitioned by 'month' after one partitioned by 'day' in an incompatible order for the lambda's concatenation.

Common situations: Mixing day-partitioned and month-partitioned rollups in one lambda; adding a new rollup to a lambda with a different partitionGranularity; copying a lambda across cubes where partitionGranularity differs.

Related errors


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