{"record":{"id":"337fe121c04572b5","repo":"cube-js/cube","slug":"can-t-find-dialect-for-datasource-data-source","errorCode":null,"errorMessage":"Can't find dialect for '${dataSource}' data source: ${_dbType}","messagePattern":"Can't find dialect for '(.+?)' data source: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cubejs-server-core/src/core/CompilerApi.ts","lineNumber":344,"sourceCode":"    }\n\n    // sqlGenerator.dataSource can return undefined for query without members\n    // Queries like this are used by api-gateway to initialize SQL API\n    // At the same time, those queries should use concrete dataSource, so we should be good to go with it\n    dataSource = compilers.compiler.withQuery(sqlGenerator, () => sqlGenerator.dataSource);\n    if (dataSource !== undefined) {\n      const _dbType = await this.getDbType(dataSource);\n      if (dataSource !== 'default' && dbType !== _dbType) {\n        // TODO consider more efficient way than instantiating query\n        sqlGenerator = await this.createQueryByDataSource(\n          compilers,\n          query,\n          dataSource,\n          _dbType\n        );\n\n        if (!sqlGenerator) {\n          throw new Error(\n            `Can't find dialect for '${dataSource}' data source: ${_dbType}`\n          );\n        }\n      }\n    }\n\n    return { sqlGenerator, compilers };\n  }\n\n  public async getSql(query: NormalizedQuery, options: GetSqlOptions = {}): Promise<SqlResult> {\n    const { includeDebugInfo, exportAnnotatedSql, preAggregationsOnly } = options;\n    const { sqlGenerator, compilers } = await this.getSqlGenerator(query);\n\n    const getSqlFn = () => compilers.compiler.withQuery(sqlGenerator, () => ({\n      external: sqlGenerator.externalPreAggregationQuery(),\n      sql: preAggregationsOnly ? null : sqlGenerator.buildSqlAndParams(exportAnnotatedSql),\n      lambdaQueries: preAggregationsOnly ? [] : sqlGenerator.buildLambdaQuery(),\n      timeDimensionAlias: sqlGenerator.timeDimensions[0]?.unescapedAliasName(),","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-server-core/src/core/CompilerApi.ts#L326-L362","documentation":"When the dbType is known but the driver-family lookup (e.g. by driverClass/dialect mapping) still cannot find a dialect implementation for a named data source, this Error is thrown, including both the dataSource name and the underlying _dbType.","triggerScenarios":"Multi-tenant setups where an additional data source's driver does not map to a supported dialect — e.g. a custom driver class whose family isn't recognized, or dbType set correctly but the dialect module not installed.","commonSituations":"Adding a second database (e.g. ClickHouse, Databricks) without installing the driver package that registers its dialect; custom driver wrappers that change the prototype/family detection.","solutions":["Install the official driver package for that data source's database","Verify the dbType for that dataSource matches a supported dialect family","Use the built-in driver class instead of a wrapper, or ensure the wrapper extends the official driver","Log _dbType and dataSource and check the dialect registry coverage"],"exampleFix":"// before\n// no clickhouse driver installed, custom wrapper used\n// after\nyarn add @cubejs-backend/clickhouse-driver\n// and driverFactory returns new ClickHouseDriver({...})","handlingStrategy":"validation","validationCode":"for (const [ds, driver] of Object.entries(drivers)) {\n  const t = await driver.dbType();\n  if (!dialectRegistry.has(t)) throw new Error(`Data source '${ds}' has no dialect for dbType '${t}'`);\n}","typeGuard":"const hasDialect = (dbType: string): dbType is KnownDbType => Object.prototype.hasOwnProperty.call(dialectMap, dbType);","tryCatchPattern":"try { await compilerApi.getSqlGenerator(query, ds); } catch (e) { if (/Can't find dialect for/.test(e.message)) { /* install/register dialect */ } else throw e; }","preventionTips":["Install official driver packages for every configured data source","Avoid wrappers that obscure the driver class identity","Test each data source's SQL generation at startup","Keep driver and server versions aligned"],"tags":["dialect","datasource","configuration"],"backgroundTag":"unsupported-database-type","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}