Repository navigation
chore(schema-compiler): Add failing test reproducing old bug (#11474) - #12628
paveltiunov wants to merge 1 commit into
Conversation
RedshiftQuery.subtractInterval concatenates '-' with a negative interval value, emitting 'DATEADD(day, --1, ...)'. Redshift parses '--' as a line comment, so custom granularities with a negative offset produce invalid SQL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tgekq9NGxJQdrJEcrnoBqP
|
Claude finished @paveltiunov's task in 1m 3s —— View job Changes requested: 1 high, 1 low. The tests are committed while they fail on purpose, so merging them turns master's unit job red. Review details
Findings
Notes
Review threadsThe listing returned 0 of my threads (no prior threads), so none were resolved or re-affirmed. Both findings were posted as new threads. |
|
|
||
| // https://github.com/cube-js/cube/issues/11474 | ||
| describe('RedshiftQuery', () => { | ||
| it('subtractInterval with a negative interval does not emit a SQL line comment', () => { |
There was a problem hiding this comment.
High: if this PR is merged as is, yarn unit on master goes red. Both tests are plain it and fail by design, since RedshiftQuery.subtractInterval (src/adapter/RedshiftQuery.ts:26) still emits -${intervalValue}. Every later PR touching schema-compiler then inherits a red unit job.
Jest 29 has it.failing. It records the bug as a passing test and turns red once the fix lands, which tells the fixer to flip it back to it:
| it('subtractInterval with a negative interval does not emit a SQL line comment', () => { | |
| it.failing('subtractInterval with a negative interval does not emit a SQL line comment', () => { |
Use the same at line 42. The other option is to ship the fix in this PR. It's a one-line change: negate the parsed value (-1 * Number(intervalValue)) or wrap it as -(${intervalValue}). Do the same in any other dialect that builds -${...} from a parsed interval.
Both planners are affected. Tesseract calls back into the JS subtractInterval through driver tools (rust/cube/cubesqlplanner/cubesqlplanner/src/planner/time_dimension/granularity.rs:243).
| const sql = query.subtractInterval('t.ts', '-1 day'); | ||
|
|
||
| expect(sql).not.toContain('--'); | ||
| expect(sql).toEqual('DATEADD(day, 1, t.ts)'); |
There was a problem hiding this comment.
Low: toEqual('DATEADD(day, 1, t.ts)') here and toContain('DATEADD(day, 1, ') at line 57 lock the test to one fix. A fix that emits DATEADD(day, -(-1), t.ts) is equally valid on Redshift and still fails this test. The invariant that matters is not.toContain('--'). To also pin the direction of the shift, check the evaluated result (offset -1 day should move the bucket start one day earlier) rather than the exact SQL text.
Check List
Issue Reference this PR resolves
Adds a failing test for #11474. It does not fix the bug.
Description of Changes Made
RedshiftQuery.subtractIntervalbuildsDATEADD(${datePart}, -${intervalValue}, ...). When the value is already negative, the output isDATEADD(day, --1, ...). Redshift reads--as the start of a line comment, so any custom granularity with a negativeoffset(for exampleoffset: -1 day, as in thesunday_weekrecipe) produces invalid SQL.Reproduced end to end on
cubejs/cube:v1.8.18withCUBEJS_DB_TYPE=redshift, on both Tesseract and the legacy planner:/v1/sqlcontainsDATEADD(day, --1, ...)and/v1/loadfails withsyntax error at or near "FROM".New test
packages/cubejs-schema-compiler/test/unit/redshift-query.test.ts:subtractInterval('t.ts', '-1 day')directly and expectsDATEADD(day, 1, t.ts);sunday_weekgranularity (offset: -1 day) and expects no--in the SQL.Both cases currently fail with
CUBEJS_TESSERACT_SQL_PLANNER=trueandfalse.Generated by Claude Code