Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/cubejs-schema-compiler/src/adapter/OracleQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@ export class OracleQuery extends BaseQuery {
}

public dateTimeCast(value) {
return `to_date(:"${value}", 'YYYY-MM-DD"T"HH24:MI:SS"Z"')`;
// Use timezone-aware parsing for ISO 8601 with milliseconds and trailing 'Z', then cast to DATE
// to preserve index-friendly comparisons against DATE columns.
return `CAST(TO_TIMESTAMP_TZ(:"${value}", 'YYYY-MM-DD"T"HH24:MI:SS.FF"Z"') AS DATE)`;
}

public timeStampCast(value) {
return this.dateTimeCast(value);
// Return timezone-aware timestamp for TIMESTAMP comparisons
return `TO_TIMESTAMP_TZ(:"${value}", 'YYYY-MM-DD"T"HH24:MI:SS.FF"Z"')`;
}

public timeStampParam(timeDimension) {
Expand Down
56 changes: 56 additions & 0 deletions packages/cubejs-schema-compiler/test/unit/oracle-query.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { OracleQuery } from '../../src/adapter/OracleQuery';
import { prepareJsCompiler } from './PrepareCompiler';

describe('OracleQuery', () => {
const { compiler, joinGraph, cubeEvaluator } = prepareJsCompiler(`
cube(\`visitors\`, {
sql: \`
select * from visitors
\`,

measures: {
count: {
type: 'count'
}
},

dimensions: {
id: {
sql: 'id',
type: 'number',
primaryKey: true
},
createdAt: {
type: 'time',
sql: 'created_at'
}
}
})
`, { adapter: 'oracle' });

it('uses to_date with seconds precision and preserves trailing Z', async () => {
await compiler.compile();

const query = new OracleQuery(
{ joinGraph, cubeEvaluator, compiler },
{
measures: ['visitors.count'],
timeDimensions: [
{
dimension: 'visitors.createdAt',
dateRange: ['2024-02-01', '2024-02-02'],
granularity: 'day'
}
],
timezone: 'UTC'
}
);

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

expect(sql).toContain("CAST(TO_TIMESTAMP_TZ(:\"?\", 'YYYY-MM-DD\"T\"HH24:MI:SS.FF\"Z\"') AS DATE)");
expect(params).toEqual(['2024-02-01T00:00:00.000Z']);
});
});


Loading