cube-js/cube · error
Cannot transform interval expression "${interval}" to Databr
Error message
Cannot transform interval expression "${interval}" to Databricks dialect What it means
formatInterval in DatabricksQuery converts a parsed SQL interval expression into Databricks dialect (e.g. 'X' DAY TO HOUR). Databricks only supports a subset of interval combos, and the method deliberately does not handle microseconds; anything not matching a known key combination throws this error.
Source
Thrown at packages/cubejs-databricks-jdbc-driver/src/DatabricksQuery.ts:140
} else if (intervalParsed.day && intKeys === 1) {
return [`'${intervalParsed.day}' DAY`, 'DAY'];
} else if (intervalParsed.day && intervalParsed.hour && intKeys === 2) {
return [`'${intervalParsed.day} ${intervalParsed.hour}' DAY TO HOUR`, 'HOUR'];
} else if (intervalParsed.day && intervalParsed.hour && intervalParsed.minute && intKeys === 3) {
return [`'${intervalParsed.day} ${intervalParsed.hour}:${intervalParsed.minute}' DAY TO MINUTE`, 'MINUTE'];
} else if (intervalParsed.day && intervalParsed.hour && intervalParsed.minute && intervalParsed.second && intKeys === 4) {
return [`'${intervalParsed.day} ${intervalParsed.hour}:${intervalParsed.minute}:${intervalParsed.second}' DAY TO SECOND`, 'SECOND'];
} else if (intervalParsed.hour && intervalParsed.minute && intKeys === 2) {
return [`'${intervalParsed.hour}:${intervalParsed.minute}' HOUR TO MINUTE`, 'MINUTE'];
} else if (intervalParsed.hour && intervalParsed.minute && intervalParsed.second && intKeys === 3) {
return [`'${intervalParsed.hour}:${intervalParsed.minute}:${intervalParsed.second}' HOUR TO SECOND`, 'SECOND'];
} else if (intervalParsed.minute && intervalParsed.second && intKeys === 2) {
return [`'${intervalParsed.minute}:${intervalParsed.second}' MINUTE TO SECOND`, 'SECOND'];
}
// No need to support microseconds.
throw new Error(`Cannot transform interval expression "${interval}" to Databricks dialect`);
}
public escapeColumnName(name: string) {
return `\`${name}\``;
}
public override getFieldIndex(id: string): string | number | null {
const idx = super.getFieldIndex(id);
if (idx !== null) {
return idx;
}
return this.escapeColumnName(this.aliasName(id, false));
}
public unixTimestampSql() {
return 'unix_timestamp()';
}View on GitHub (pinned to 7d981676b3)
Solutions
- Rewrite the query/calculated member to use an interval combination Databricks supports (day-to-second or year-to-month forms present in the code)
- Avoid microsecond precision in intervals — use seconds instead
- Express the interval arithmetic differently, e.g. via date_add/timestamp arithmetic functions in the cube schema
Example fix
// before INTERVAL '0 00:00:00.000001' DAY TO SECOND // microseconds unsupported // after INTERVAL '1' SECOND // or a supported DAY TO SECOND combination
Defensive patterns
Strategy: try-catch
Validate before calling
// avoid microsecond or unsupported interval combos in calculated members
const SUPPORTED_INTERVALS = /^\d+ (second|minute|hour|day|month|year)s?$/i;
if (!SUPPORTED_INTERVALS.test(myIntervalLiteral)) throw new Error('Use a simple single-unit interval for Databricks'); Try / catch
try {
const result = await cube.query(queryObject);
} catch (e) {
if (e.message.includes('Cannot transform interval expression')) {
// rewrite the interval in the schema/calculated member and resubmit
}
throw e;
} Prevention
- Use whole-unit intervals (DAY, HOUR, SECOND...) in calculated members
- Never use microsecond precision against Databricks
- Snapshot-test generated SQL for interval-heavy queries
When it happens
Trigger: A time-dimension or calculated query compiles an interval literal whose parsed fields (e.g. only year, or exotic combos, or microsecond precision) don't match any supported branch in formatInterval.
Common situations: Using interval expressions with unsupported precision (microseconds) or unusual unit combinations in a calculated member or date filter against Databricks; driver dialect translating a generic interval from the schema compiler.
Related errors
- Unsupported interval unit "${unit}" for the Pinot dialect
- Cannot transform interval expression "${interval}" to MySQL
- You cannot change security context via __user from ${session
- Incorrect user name "${user}" or password
- ${queryExecution.QueryExecution?.Status?.StateChangeReason}
AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02).
Data as JSON: /api/errors/0e752d611e7f9322.
Report an issue: GitHub.