Skip to content

Commit c7ae936

Browse files
authored
feat(schema-compiler): add quarter granularity support in SqliteQuery using CASE expression (#9633)
* 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. * fixed the lint fail issue * removed the unnecessary .trim() function
1 parent 737caab commit c7ae936

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ 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) => `CASE
15+
WHEN cast(strftime('%m', ${date}) as integer) BETWEEN 1 AND 3 THEN strftime('%Y-01-01T00:00:00.000', ${date})
16+
WHEN cast(strftime('%m', ${date}) as integer) BETWEEN 4 AND 6 THEN strftime('%Y-04-01T00:00:00.000', ${date})
17+
WHEN cast(strftime('%m', ${date}) as integer) BETWEEN 7 AND 9 THEN strftime('%Y-07-01T00:00:00.000', ${date})
18+
ELSE strftime('%Y-10-01T00:00:00.000', ${date})
19+
END`
1420
};
1521

1622
class SqliteFilter extends BaseFilter {

0 commit comments

Comments
 (0)