File tree Expand file tree Collapse file tree 2 files changed +61
-2
lines changed
packages/cubejs-schema-compiler Expand file tree Collapse file tree 2 files changed +61
-2
lines changed Original file line number Diff line number Diff line change @@ -71,11 +71,14 @@ export class OracleQuery extends BaseQuery {
7171 }
7272
7373 public dateTimeCast ( value ) {
74- return `to_date(:"${ value } ", 'YYYY-MM-DD"T"HH24:MI:SS"Z"')` ;
74+ // Use timezone-aware parsing for ISO 8601 with milliseconds and trailing 'Z', then cast to DATE
75+ // to preserve index-friendly comparisons against DATE columns.
76+ return `CAST(TO_TIMESTAMP_TZ(:"${ value } ", 'YYYY-MM-DD"T"HH24:MI:SS.FF"Z"') AS DATE)` ;
7577 }
7678
7779 public timeStampCast ( value ) {
78- return this . dateTimeCast ( value ) ;
80+ // Return timezone-aware timestamp for TIMESTAMP comparisons
81+ return `TO_TIMESTAMP_TZ(:"${ value } ", 'YYYY-MM-DD"T"HH24:MI:SS.FF"Z"')` ;
7982 }
8083
8184 public timeStampParam ( timeDimension ) {
Original file line number Diff line number Diff line change 1+ import { OracleQuery } from '../../src/adapter/OracleQuery' ;
2+ import { prepareJsCompiler } from './PrepareCompiler' ;
3+
4+ describe ( 'OracleQuery' , ( ) => {
5+ const { compiler, joinGraph, cubeEvaluator } = prepareJsCompiler ( `
6+ cube(\`visitors\`, {
7+ sql: \`
8+ select * from visitors
9+ \`,
10+
11+ measures: {
12+ count: {
13+ type: 'count'
14+ }
15+ },
16+
17+ dimensions: {
18+ id: {
19+ sql: 'id',
20+ type: 'number',
21+ primaryKey: true
22+ },
23+ createdAt: {
24+ type: 'time',
25+ sql: 'created_at'
26+ }
27+ }
28+ })
29+ ` , { adapter : 'oracle' } ) ;
30+
31+ it ( 'uses to_date with seconds precision and preserves trailing Z' , async ( ) => {
32+ await compiler . compile ( ) ;
33+
34+ const query = new OracleQuery (
35+ { joinGraph, cubeEvaluator, compiler } ,
36+ {
37+ measures : [ 'visitors.count' ] ,
38+ timeDimensions : [
39+ {
40+ dimension : 'visitors.createdAt' ,
41+ dateRange : [ '2024-02-01' , '2024-02-02' ] ,
42+ granularity : 'day'
43+ }
44+ ] ,
45+ timezone : 'UTC'
46+ }
47+ ) ;
48+
49+ const [ sql , params ] = query . buildSqlAndParams ( ) ;
50+
51+ expect ( sql ) . toContain ( "CAST(TO_TIMESTAMP_TZ(:\"?\", 'YYYY-MM-DD\"T\"HH24:MI:SS.FF\"Z\"') AS DATE)" ) ;
52+ expect ( params ) . toEqual ( [ '2024-02-01T00:00:00.000Z' ] ) ;
53+ } ) ;
54+ } ) ;
55+
56+
You can’t perform that action at this time.
0 commit comments