Skip to content

Commit 1014871

Browse files
committed
feat(sqlite): add quarter granularity support using CASE expression
- Implement quarter granularity in SqliteQuery with explicit CASE to map months to their respective quarter start dates. - Aligns SQLite quarter handling with Postgres DATE_TRUNC('quarter', ...) - Fixes issues with data blending queries requiring quarter granularity.
1 parent 89b00cf commit 1014871

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/cubejs-schema-compiler/src/adapter/SqliteQuery.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ const GRANULARITY_TO_INTERVAL = {
1010
minute: (date) => `strftime('%Y-%m-%dT%H:%M:00.000', ${date})`,
1111
second: (date) => `strftime('%Y-%m-%dT%H:%M:%S.000', ${date})`,
1212
month: (date) => `strftime('%Y-%m-01T00:00:00.000', ${date})`,
13-
year: (date) => `strftime('%Y-01-01T00:00:00.000', ${date})`
13+
year: (date) => `strftime('%Y-01-01T00:00:00.000', ${date})`,
14+
quarter: (date) =>
15+
`CASE
16+
WHEN cast(strftime('%m', ${date}) as integer) BETWEEN 1 AND 3 THEN strftime('%Y-01-01T00:00:00.000', ${date})
17+
WHEN cast(strftime('%m', ${date}) as integer) BETWEEN 4 AND 6 THEN strftime('%Y-04-01T00:00:00.000', ${date})
18+
WHEN cast(strftime('%m', ${date}) as integer) BETWEEN 7 AND 9 THEN strftime('%Y-07-01T00:00:00.000', ${date})
19+
ELSE strftime('%Y-10-01T00:00:00.000', ${date})
20+
END`.trim()
1421
};
1522

1623
class SqliteFilter extends BaseFilter {

0 commit comments

Comments
 (0)