{"record":{"id":"5ebcdc18aea9a93b","repo":"cube-js/cube","slug":"granularity-granularity-is-not-supported","errorCode":null,"errorMessage":"${granularity} granularity is not supported","messagePattern":"(.+?) granularity is not supported","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cubejs-questdb-driver/src/QuestQuery.ts","lineNumber":116,"sourceCode":"    return `dateadd('${unit}', ${-number * factor}, ${date})`;\n  }\n\n  public addInterval(date: string, interval: string): string {\n    const [number, type] = this.parseInterval(interval);\n    const { unit, factor } = INTERVAL_TO_QUEST_DATE_UNIT[type];\n\n    return `dateadd('${unit}', ${number * factor}, ${date})`;\n  }\n\n  public unixTimestampSql(): string {\n    // QuestDB's now() function returns epoch timestamp with microsecond granularity.\n    return 'now() / 1000000';\n  }\n\n  public timeGroupedColumn(granularity: string, dimension: string): string {\n    const interval = GRANULARITY_TO_INTERVAL[granularity];\n    if (interval === undefined) {\n      throw new Error(`${granularity} granularity is not supported`);\n    }\n    return `timestamp_floor('${GRANULARITY_TO_INTERVAL[granularity]}', ${dimension})`;\n  }\n\n  public dateBin(interval: string, source: string, origin: string): string {\n    const { stride, unit, count } = this.questFloorStride(interval);\n    // timestamp_floor(stride, ts, origin) only buckets forward from `origin`, so\n    // an origin later than the data collapses every row into a single bucket.\n    // Shift `origin` back by a whole number of strides (which preserves the bin\n    // phase, as flooring is periodic modulo the stride) to just before a fixed\n    // anchor that precedes any realistic data.\n    const shift = this.dateBinOriginShift(origin, unit, count);\n    const shiftedOrigin = shift > 0\n      ? `dateadd('${unit}', ${-shift}, cast('${origin}' as timestamp))`\n      : `cast('${origin}' as timestamp)`;\n\n    return `timestamp_floor('${stride}', ${source}, ${shiftedOrigin})`;\n  }","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-questdb-driver/src/QuestQuery.ts#L98-L134","documentation":"QuestQuery.timeGroupedColumn builds the SQL for a time-dimension granularity grouping using the GRANULARITY_TO_INTERVAL map. If the requested granularity string is not a key of that map, the interval is undefined and the driver throws rather than emitting invalid SQL.","triggerScenarios":"Compiling a query with a time dimension granularity not supported by the QuestDB driver — e.g. custom granularities passed as arbitrary strings, or granularity names the driver's map lacks.","commonSituations":"Using cube's custom granularity strings (like 'quarter' in older versions or custom intervals) against a driver version whose GRANULARITY_TO_INTERVAL map does not define them; typos in granularity configuration.","solutions":["Use only granularities supported by the driver (second, minute, hour, day, week, month, quarter, year — check GRANULARITY_TO_INTERVAL in QuestQuery.ts)","Upgrade cubejs-questdb-driver if the needed granularity was added in a newer release","Pre-aggregate/roll up data in the cube schema instead of relying on an unsupported native granularity"],"exampleFix":"// before\n{ dimension: 'Events.timestamp', granularity: 'fortnight' }\n// after\n{ dimension: 'Events.timestamp', granularity: 'week' }","handlingStrategy":"validation","validationCode":"const supported = ['second','minute','hour','day','week','month','quarter','year']; if (!supported.includes(granularity)) throw new Error(`Unsupported granularity ${granularity} for QuestDB`);","typeGuard":"function isQuestGranularity(g) { return g in GRANULARITY_TO_INTERVAL; }","tryCatchPattern":"try { await cube.query(...); } catch (e) { if (e.message.includes('granularity is not supported')) { /* fall back to 'day' or upgrade driver */ } throw e; }","preventionTips":["Restrict timeGranularities in cube configs to driver-supported values","Keep the questdb driver current for added granularities","Test compiled SQL per granularity in CI"],"tags":["granularity","questdb","query-compiler"],"backgroundTag":"unsupported-granularity","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}