{"record":{"id":"89091ac36f153930","repo":"cube-js/cube","slug":"athena-presto-supports-only-simple-intervals-with","errorCode":null,"errorMessage":"Athena/Presto supports only simple intervals with one date part","messagePattern":"Athena/Presto supports only simple intervals with one date part","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cubejs-schema-compiler/src/adapter/PrestodbQuery.ts","lineNumber":95,"sourceCode":"    const timestampField = this.promoteDateToTimestamp(field);\n    const atTimezone = `${timestampField} AT TIME ZONE '${this.timezone}'`;\n    return `CAST(date_add('minute', timezone_minute(${atTimezone}), date_add('hour', timezone_hour(${atTimezone}), ${timestampField})) AS TIMESTAMP)`;\n  }\n\n  /**\n   * Returns sql for source expression floored to timestamps aligned with\n   * intervals relative to origin timestamp point.\n   * Athena doesn't support INTERVALs directly — using date_diff/date_add.\n   * Origin is wrapped in `CAST(... AS TIMESTAMP)` so that `date_add` returns\n   * a plain TIMESTAMP rather than `timestamp with time zone` — Hive cannot\n   * write the TZ-aware type into an export bucket.\n   */\n  public dateBin(interval: string, source: string, origin: string): string {\n    const intervalParsed = parseSqlInterval(interval);\n    const intervalParts = Object.entries(intervalParsed);\n\n    if (intervalParts.length > 1) {\n      throw new Error('Athena/Presto supports only simple intervals with one date part');\n    }\n\n    const [unit, count] = intervalParts[0];\n    const originExpr = `CAST(${this.timeStampCast(`'${origin}'`)} AS TIMESTAMP)`;\n\n    return `date_add('${unit}',\n      floor(\n        date_diff('${unit}', ${originExpr}, ${source}) / ${count}\n      ) * ${count},\n      ${originExpr}\n    )`;\n  }\n\n  public timeGroupedColumn(granularity, dimension) {\n    return `date_trunc('${GRANULARITY_TO_INTERVAL[granularity]}', ${dimension})`;\n  }\n\n  public intervalString(interval: string): string {","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-schema-compiler/src/adapter/PrestodbQuery.ts#L77-L113","documentation":"PrestoDB/Athena only supports date_bin-style shifting with a single-unit interval (e.g. '1 day', '5 minute'). parseSqlInterval() returns an object of date parts; if more than one part is present (e.g. '1 month 3 days'), the query cannot be translated, so Cube throws immediately in dateBin.","triggerScenarios":"Calling dateBin(interval, source, origin) (directly or via time-dimension dateBin/granularity derivation) with a compound interval string like '1 month 2 days' or '1 year 6 months' against a Presto/Athena data source.","commonSituations":"Defining a named granularity or pre-aggregation with a multi-part interval; a time dimension granularity configured for another dialect (e.g. Postgres supports compound intervals) being reused against Athena.","solutions":["Use an interval with exactly one date part, e.g. change '1 month 3 days' to '1 month' or '3 days'","If a compound interval is required, compute the equivalent single unit (e.g. 6 months) or split the logic into multiple granularities/pre-aggregations","Check that the query is not accidentally routed to Presto/Athena (wrong driver/dbType) if your interval was valid on another database"],"exampleFix":"// before\nconst interval = '1 month 7 days';\nqueryBuilder.dateBin(interval, src, origin);\n// after\nconst interval = '1 month'; // or '7 days' — one date part only","handlingStrategy":"validation","validationCode":"const parts = parseSqlInterval(interval);\nif (Object.values(parts).filter(v => v).length > 1) throw new Error('Use a single date-part interval for Athena/Presto');","typeGuard":null,"tryCatchPattern":"try { return qb.dateBin(interval, src, origin); } catch (e) { if (e.message.includes('simple intervals')) { /* fall back to single-unit interval or rethrow with guidance */ } throw e; }","preventionTips":["Keep granularity intervals to one unit for Athena/Presto sources","Centralize interval constants per dialect","Add schema-level tests that compile time dimensions against the target dialect"],"tags":["presto","athena","interval","datebin"],"backgroundTag":"unsupported-interval-precision","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}