Commit ed791ed
fix(schema-compiler): add support for time filters and rolling windows and fix subquery aliasing in Oracle dialect (#10066)
* fix(schema-compiler): remove hardcoded AS keyword in subquery aliases for Oracle compatibility
Oracle database does not support the AS keyword for table/subquery aliasing,
while other databases like PostgreSQL and MySQL do. The existing BaseQuery
implementation hardcoded 'as' in subquery alias generation, causing Oracle
queries to fail.
This change:
- Replaces hardcoded 'as' with asSyntaxJoin property in BaseQuery
- Oracle returns empty string for asSyntaxJoin (no AS keyword)
- PostgreSQL/MySQL return 'AS' (maintains existing behavior)
- Adds comprehensive Oracle query test suite validating AS syntax removal
- Adds PostgreSQL regression test ensuring AS keyword is still present
This fixes queries with rolling windows and multiple subqueries on Oracle,
which previously generated invalid SQL like:
SELECT ... FROM (...) as q_0 INNER JOIN (...) as q_1 ON ...
Now Oracle correctly generates:
SELECT ... FROM (...) q_0 INNER JOIN (...) q_1 ON ...
* fix(oracle): add support for time filters and rolling windows
- Fix AS keyword in subquery aliases (Oracle doesn't support it)
- Handle time dimensions without granularity to prevent TypeError
- Implement Oracle-specific interval arithmetic using ADD_MONTHS and NUMTODSINTERVAL
- Add comprehensive test suite for Oracle query generation
These changes enable Oracle users to execute queries with:
- Time dimension filters without granularity specification
- Rolling windows and time-based calculations
- Multiple subqueries with proper aliasing
All changes maintain backward compatibility with other database adapters.
* add tests for subtractInterval and addInterval in oracle
* fix(oracle): exclude time dimensions without granularity from GROUP BY
Oracle's custom groupByClause() was incorrectly including time dimensions
without granularity in the GROUP BY clause, causing SQL errors when time
dimensions were used solely for filtering (no grouping).
Changes:
- Update OracleQuery.groupByClause() to check selectColumns() before
including dimensions in GROUP BY
- Time dimensions without granularity return null from selectColumns(),
so they are now properly excluded
- Add comprehensive tests for both PostgreSQL and Oracle covering:
* Time dimensions without granularity (filtering only)
* Time dimensions with granularity (grouping and filtering)
- Remove unnecessary guard in BaseQuery.dimensionTimeGroupedColumn()
as it's no longer needed with the Oracle-specific fix
The fix aligns Oracle's behavior with PostgreSQL, which already handles
this correctly through its base implementation.1 parent 32a1db6 commit ed791ed
File tree
4 files changed
+964
-5
lines changed- packages/cubejs-schema-compiler
- src/adapter
- test/unit
4 files changed
+964
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1380 | 1380 | | |
1381 | 1381 | | |
1382 | 1382 | | |
1383 | | - | |
1384 | | - | |
| 1383 | + | |
| 1384 | + | |
1385 | 1385 | | |
1386 | 1386 | | |
1387 | 1387 | | |
| |||
1410 | 1410 | | |
1411 | 1411 | | |
1412 | 1412 | | |
1413 | | - | |
| 1413 | + | |
1414 | 1414 | | |
1415 | 1415 | | |
1416 | 1416 | | |
| |||
Lines changed: 89 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
4 | | - | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
58 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
59 | 64 | | |
60 | 65 | | |
61 | 66 | | |
| |||
92 | 97 | | |
93 | 98 | | |
94 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
95 | 182 | | |
96 | 183 | | |
97 | 184 | | |
| |||
0 commit comments