cube-js/cube · error

Pre-aggregation tables are undefined.

Error message

Pre-aggregation tables are undefined.

What it means

getTablesQuery resolves the set of pre-aggregation tables for a pre-aggregation, first from the in-memory tables cache and otherwise from cache driver or uncached fetch. If the lookup returns undefined (cache miss with a cache driver that failed to return data, or fetchTablesNoCache yielded nothing), the method throws rather than propagating undefined to versionEntries.

Source

Thrown at packages/cubejs-query-orchestrator/src/orchestrator/PreAggregationLoadCache.ts:119

    if (this.tablePrefixes && client.getPrefixTablesQuery && this.preAggregations.options.skipExternalCacheAndQueue) {
      return client.getPrefixTablesQuery(preAggregation.preAggregationsSchema, this.tablePrefixes);
    }

    return client.getTablesQuery(preAggregation.preAggregationsSchema);
  }

  public tablesCachePrefixKey(preAggregation: PreAggregationDescription) {
    return this.queryCache.getKey('SQL_PRE_AGGREGATIONS_TABLES', `${preAggregation.dataSource}${preAggregation.preAggregationsSchema}${preAggregation.external ? '_EXT' : ''}`);
  }

  protected async getTablesQuery(preAggregation) {
    const redisKey = this.tablesCachePrefixKey(preAggregation);
    if (!this.tables[redisKey]) {
      const tables = this.preAggregations.options.skipExternalCacheAndQueue && preAggregation.external ?
        await this.fetchTablesNoCache(preAggregation) :
        await this.tablesFromCache(preAggregation);
      if (tables === undefined) {
        throw new Error('Pre-aggregation tables are undefined.');
      }
      this.tables[redisKey] = tables;
    }
    return this.tables[redisKey];
  }

  public async getTableColumnTypes(preAggregation: PreAggregationDescription, tableName: string): Promise<TableStructure> {
    const prefixKey = this.tablesCachePrefixKey(preAggregation);
    if (!this.tableColumnTypes[prefixKey]?.[tableName]) {
      if (!this.preAggregations.options.skipExternalCacheAndQueue && preAggregation.external) {
        throw new Error(`Lambda union with source data feature is supported only by external rollups stored in Cube Store but was invoked for '${preAggregation.preAggregationId}'`);
      }
      const client = await this.externalDriverFactory();
      const columnTypes = await client.tableColumnTypes(tableName);
      if (!this.tableColumnTypes[prefixKey]) {
        this.tableColumnTypes[prefixKey] = {};
      }
      this.tableColumnTypes[prefixKey][tableName] = columnTypes;

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Clear the orchestrator/query cache so tables are re-fetched (restart or flush cache driver)
  2. Verify the cache driver (e.g. Redis) connectivity and persistence settings
  3. Check the external store availability if the pre-aggregation is external; re-build/re-roll-up the pre-aggregation
  4. Upgrade/patch if using skipExternalCacheAndQueue mode known to race with cache population

Example fix

// before
// stale redis entry causes undefined tables
// after
await orchestrator.queryCache.getCacheDriver().remove(keysPrefix); // flush stale entries, then re-run query
Defensive patterns

Strategy: retry

Validate before calling

const key = loadCache.tablesCachePrefixKey(preAggregation);
const cached = loadCache.tables[key];
if (cached === undefined) {
  await loadCache.fetchTables(preAggregation); // warm the cache before reading
}

Type guard

const tablesDefined = (t) => Array.isArray(t);

Try / catch

try {
  return await loadCache.getTablesQuery(preAggregation);
} catch (e) {
  if (String(e.message).includes('Pre-aggregation tables are undefined')) {
    await loadCache.fetchTables(preAggregation); // re-populate and retry once
    return await loadCache.getTablesQuery(preAggregation);
  }
  throw e;
}

Prevention

When it happens

Trigger: versionEntries calls getTablesQuery for a pre-aggregation whose tables cache key is absent and where tablesFromCache/fetchTablesNoCache both return undefined — e.g. cache driver eviction/failure between fetchTables caching and reading, or a failed external fetch in skipExternalCacheAndQueue mode.

Common situations: Redis/memcached cache eviction or connectivity issues dropping pre-aggregation table entries; stale cache after deployments; external store unavailable while skipExternalCacheAndQueue bypasses the queued fetch path.

Related errors


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