Skip to content

Commit b944111

Browse files
committed
cr comments fixes
1 parent 3529c9b commit b944111

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class OracleQuery extends BaseQuery {
8282
}
8383

8484
public timeStampParam(timeDimension) {
85-
return timeDimension.dateFieldType() === 'string' ? ':"?"' : this.dateTimeCast('?');
85+
return timeDimension.dateFieldType() === 'string' ? ':"?"' : this.timeStampCast('?');
8686
}
8787

8888
public timeGroupedColumn(granularity, dimension) {

packages/cubejs-schema-compiler/test/unit/oracle-query.test.ts

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('OracleQuery', () => {
2828
})
2929
`, { adapter: 'oracle' });
3030

31-
it('uses TO_TIMESTAMP_TZ with milliseconds precision and preserves trailing Z', async () => {
31+
it('generates TO_TIMESTAMP_TZ with millisecond precision for date range filters', async () => {
3232
await compiler.compile();
3333

3434
const query = new OracleQuery(
@@ -48,7 +48,64 @@ describe('OracleQuery', () => {
4848

4949
const [sql, params] = query.buildSqlAndParams();
5050

51+
// Verify TO_TIMESTAMP_TZ is used with proper ISO 8601 format including milliseconds
5152
expect(sql).toContain('TO_TIMESTAMP_TZ(:"?", \'YYYY-MM-DD"T"HH24:MI:SS.FF"Z"\')');
53+
expect(sql).toMatch(/created_at\s+>=\s+TO_TIMESTAMP_TZ/);
54+
expect(sql).toMatch(/created_at\s+<=\s+TO_TIMESTAMP_TZ/);
55+
56+
// Verify parameters include millisecond precision
5257
expect(params).toEqual(['2024-02-01T00:00:00.000Z', '2024-02-02T23:59:59.999Z']);
5358
});
59+
60+
it('generates TRUNC function for day granularity grouping', async () => {
61+
await compiler.compile();
62+
63+
const query = new OracleQuery(
64+
{ joinGraph, cubeEvaluator, compiler },
65+
{
66+
measures: ['visitors.count'],
67+
timeDimensions: [
68+
{
69+
dimension: 'visitors.createdAt',
70+
dateRange: ['2024-01-01', '2024-01-31'],
71+
granularity: 'day'
72+
}
73+
],
74+
timezone: 'UTC'
75+
}
76+
);
77+
78+
const [sql, params] = query.buildSqlAndParams();
79+
80+
// Verify TRUNC with DD format for day grouping
81+
expect(sql).toContain('TRUNC("visitors".created_at, \'DD\')');
82+
expect(sql).toMatch(/GROUP BY\s+TRUNC/);
83+
expect(params).toEqual(['2024-01-01T00:00:00.000Z', '2024-01-31T23:59:59.999Z']);
84+
});
85+
86+
it('generates TRUNC function for month granularity grouping', async () => {
87+
await compiler.compile();
88+
89+
const query = new OracleQuery(
90+
{ joinGraph, cubeEvaluator, compiler },
91+
{
92+
measures: ['visitors.count'],
93+
timeDimensions: [
94+
{
95+
dimension: 'visitors.createdAt',
96+
dateRange: ['2024-01-01', '2024-12-31'],
97+
granularity: 'month'
98+
}
99+
],
100+
timezone: 'UTC'
101+
}
102+
);
103+
104+
const [sql, params] = query.buildSqlAndParams();
105+
106+
// Verify TRUNC with MM format for month grouping
107+
expect(sql).toContain('TRUNC("visitors".created_at, \'MM\')');
108+
expect(sql).toMatch(/GROUP BY\s+TRUNC/);
109+
expect(params).toEqual(['2024-01-01T00:00:00.000Z', '2024-12-31T23:59:59.999Z']);
110+
});
54111
});

0 commit comments

Comments
 (0)