{"record":{"id":"086a7214e4eb0951","repo":"cube-js/cube","slug":"distributed-approximate-distinct-count-is-not-supp","errorCode":null,"errorMessage":"Distributed approximate distinct count is not supported by this DB","messagePattern":"Distributed approximate distinct count is not supported by this DB","errorType":"exception","errorClass":"UserError","httpStatus":null,"severity":"error","filePath":"packages/cubejs-schema-compiler/src/adapter/BaseQuery.js","lineNumber":3989,"sourceCode":"    if (symbol.type === 'count' || symbol.type === 'sum') {\n      return `sum(${evaluateSql})`;\n    } else if (symbol.type === 'countDistinctApprox') {\n      return topLevelMerge ? this.hllCardinalityMerge(evaluateSql) : this.hllMergeOnly(evaluateSql);\n    } else if (symbol.type === 'min' || symbol.type === 'max') {\n      return `${symbol.type}(${evaluateSql})`;\n    }\n    return undefined;\n  }\n\n  topAggregateWrap(symbol, evaluateSql) {\n    if (symbol.type === 'countDistinctApprox') {\n      return this.hllCardinality(evaluateSql);\n    }\n    return evaluateSql;\n  }\n\n  hllInit(_sql) {\n    throw new UserError('Distributed approximate distinct count is not supported by this DB');\n  }\n\n  hllMerge(_sql) {\n    throw new UserError('Distributed approximate distinct count is not supported by this DB');\n  }\n\n  hllCardinality(_sql) {\n    throw new UserError('Distributed approximate distinct count is not supported by this DB');\n  }\n\n  hllMergeOnly(sql) {\n    return this.hllMerge(sql);\n  }\n\n  hllCardinalityMerge(sql) {\n    return this.hllMerge(sql);\n  }\n","sourceCodeStart":3971,"sourceCodeEnd":4007,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js#L3971-L4007","documentation":"hllInit() is the base dialect hook used to initialize HyperLogLog state for distributed approximate distinct counts (needed when distinct counts are computed across multiple nodes/pre-aggregations). The default BaseQuery implementation is a stub that always throws, since not every database has HLL primitives.","triggerScenarios":"A query or pre-aggregation plan requests approximate distinct count in a mode that requires distributed HLL (hllInit) while running against an adapter that did not override hllInit.","commonSituations":"Using countDistinctApprox (approximate distinct count measure type) on a database driver that lacks HLL support; mixing in rolled-up approx counts across cubes on an unsupported DB.","solutions":["Switch to a database/adapter with HLL support (e.g. Postgres with postgresql-hll, BigQuery, Snowflake)","Override hllInit/hllMerge/hllCardinality in a custom adapter for your DB","Replace the approximate measure with an exact regular countDistinct measure"],"exampleFix":"// before\nmeasures: { visitors: { type: 'countDistinctApprox', sql: 'user_id' } }\n// after\nmeasures: { visitors: { type: 'countDistinct', sql: 'user_id' } } // or move to an HLL-capable DB","handlingStrategy":"fallback","validationCode":"const approxSupported = ['postgres', 'bigquery', 'snowflake', 'clickhouse', 'duckdb'];\nif (measureType === 'countDistinctApprox' && !approxSupported.includes(dbType)) {\n  console.warn('Distributed HLL not supported; falling back to exact countDistinct');\n}","typeGuard":"function supportsHllInit(adapter) {\n  return typeof adapter.hllInit === 'function' &&\n    adapter.hllInit !== Object.getPrototypeOf(Object.getPrototypeOf(adapter)).hllInit;\n}","tryCatchPattern":"try { return await cube.load(measures, query); } catch (e) {\n  if (/Distributed approximate distinct count/.test(e.message)) {\n    return await cube.load(withExactCountDistinct(measures), query);\n  }\n  throw e;\n}","preventionTips":["Use countDistinctApprox only on dialects with HLL support","Keep an exact countDistinct variant of key measures as a fallback","Pin database versions that ship HLL extensions"],"tags":["schema-compiler","approximate-distinct-count","hyperloglog","unsupported-feature"],"backgroundTag":"approx-distinct-count-unsupported","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}