cube-js/cube · error · Error

Unable to detect a source table for ksql download query. In

Error message

Unable to detect a source table for ksql download query. In order to query ksql use "SELECT * FROM <TABLE>"

What it means

A guard in KsqlDriver.downloadQueryResults: downloading a table's results requires a simple `SELECT * FROM <TABLE>` form so the driver can identify the source stream/table from the SQL; any other query shape leaves the source table undetectable and is rejected. The input at fault is a download/downloadQueryResults call whose SQL is filtered, joined, or otherwise not a plain SELECT *.

Source

Thrown at packages/cubejs-ksql-driver/src/KsqlDriver.ts:288

  }

  // eslint-disable-next-line @typescript-eslint/no-unused-vars
  public loadPreAggregationIntoTable(preAggregationTableName: string, loadSql: string, params: any[], options: KsqlQueryOptions): Promise<any> {
    const { streamOffset } = options || {};
    return this.query(loadSql.replace(preAggregationTableName, this.tableDashName(preAggregationTableName)), params, { streamOffset });
  }

  // eslint-disable-next-line @typescript-eslint/no-unused-vars
  public async downloadTable(table: string, options: any): Promise<any> {
    const { streamOffset } = options || {};
    return this.getStreamingTableData(this.tableDashName(table), { streamOffset });
  }

  // eslint-disable-next-line @typescript-eslint/no-unused-vars
  public async downloadQueryResults(query: string, params: any, options: any) {
    const table = KsqlQuery.extractTableFromSimpleSelectAsteriskQuery(query);
    if (!table) {
      throw new Error('Unable to detect a source table for ksql download query. In order to query ksql use "SELECT * FROM <TABLE>"');
    }

    const selectStatement = this.prepareQueryWithParams(query, params);
    const { streamOffset, outputColumnTypes } = options || {};
    return this.getStreamingTableData(table, { selectStatement, streamOffset, outputColumnTypes });
  }

  private async getStreamingTableData(streamingTable: string, options: KsqlQueryOptions = {}) {
    const { selectStatement, streamOffset, outputColumnTypes } = options;
    const describe = await this.describeTable(streamingTable);
    const name = this.config.streamingSourceName || 'default';
    const kafkaDirectDownload = !!this.config.kafkaHost;
    const streamingSource = kafkaDirectDownload ? {
      name: `${name}-kafka`,
      type: 'kafka',
      credentials: {
        user: this.config.kafkaUser,
        password: this.config.kafkaPassword,

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Ensure the download query passed to downloadQueryResults matches the expected 'SELECT * FROM <TABLE>' shape so the source table can be extracted
  2. Set options.table (or the table name parameter) explicitly when constructing the download query
  3. Fix query generation upstream in the orchestrator so the pre-aggregation source table name is embedded in the SELECT
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/cubejs-ksql-driver/src/KsqlDriver.ts:288 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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