Skip to content

Conversation

Tankilevitch
Copy link
Contributor

@Tankilevitch Tankilevitch commented Sep 13, 2025

Check List

  • Tests have been run in packages where changes made if available
  • Linter has been run for changed code
  • Tests for the changes have been added if not covered yet
  • Docs have been added / updated if required

fixes #9971

Bug: Oracle timestamp parsing mismatch (TO_DATE vs ISO string with .000Z)

Summary
Cube generates an Oracle query using TO_DATE with a format mask that does not match the actual ISO-8601 timestamp emitted by the backend (2024-02-01T00:00:00.000Z). This causes Oracle errors, while Postgres accepts the same value.

Input Query

{
  "query": {
    "measures": ["mortgage.total_mortgage_amount"],
    "filters": [
      {
        "member": "mortgage.mortgage_taken_at",
        "operator": "afterDate",
        "values": ["2024-02-01"]
      }
    ]
  }
}

Generated SQL (Oracle)

WHERE "mortgage".MORTGAGE_TAKEN_DATE >
  to_date(:"?", 'YYYY-MM-DD"T"HH24:MI:SS"Z"')

Bind value passed

2024-02-01T00:00:00.000Z

Problem

The format 'YYYY-MM-DD"T"HH24:MI:SS"Z"' does not handle:Fractional seconds (.000)

Oracle raises ORA-01821: date format not recognized.

Screenshot 2025-09-13 at 22 19 14

Expected behavior

Oracle should parse the backend’s ISO string correctly, including fractional seconds and UTC Z.

Suggested fix

Use TO_TIMESTAMP_TZ with a matching format mask:

to_timestamp_tz(:"?", 'YYYY-MM-DD"T"HH24:MI:SS.FF"Z"')
and

CAST(TO_TIMESTAMP_TZ(:"?", 'YYYY-MM-DD"T"HH24:MI:SS.FF"Z"') AS DATE)

Screenshot 2025-09-13 at 22 20 10

[For example #12]

Description of Changes Made (if issue reference is not provided)

[Description goes here]
-->

@Tankilevitch Tankilevitch requested a review from a team as a code owner September 13, 2025 19:20
@github-actions github-actions bot added the pr:community Contribution from Cube.js community members. label Sep 13, 2025
@Tankilevitch Tankilevitch changed the title fix(schema-compiler): use TO_TIMESTAMP_TZ for ISO 8601 with Z; keep index-friendly casts fix(schema-compiler): Oracle use TO_TIMESTAMP_TZ for ISO 8601 with Z for date and timestamp Sep 13, 2025
@Tankilevitch
Copy link
Contributor Author

more context

Screenshot 2025-09-13 at 22 36 33 Screenshot 2025-09-13 at 22 36 45

@KSDaemon KSDaemon added driver:oracle Issues relating to the Oracle driver data source driver labels Sep 16, 2025
@KSDaemon
Copy link
Member

KSDaemon commented Sep 16, 2025

Hi @Tankilevitch! Thank you for your contribution!
Could you please run yarn run lint:fix in the schema-compiler package?

And the test you added is also failing:

FAIL  dist/test/unit/oracle-query.test.js
2025-09-15T11:06:07.3965474Z   ● OracleQuery › uses to_date with seconds precision and preserves trailing Z
2025-09-15T11:06:07.3966671Z     expect(received).toContain(expected) // indexOf
2025-09-15T11:06:07.3968048Z     Expected substring: "CAST(TO_TIMESTAMP_TZ(:\"?\", 'YYYY-MM-DD\"T\"HH24:MI:SS.FF\"Z\"') AS DATE)"
2025-09-15T11:06:07.3968876Z     Received string:    "SELECT
2025-09-15T11:06:07.3969884Z           TRUNC(\"visitors\".created_at, 'DD') \"visitors__created_at_day\", count(\"visitors\".id) \"visitors__count\"
2025-09-15T11:06:07.3970653Z         FROM
2025-09-15T11:06:07.3972575Z           visitors  \"visitors\"  WHERE (\"visitors\".created_at >= TO_TIMESTAMP_TZ(:\"?\", 'YYYY-MM-DD\"T\"HH24:MI:SS.FF\"Z\"') AND \"visitors\".created_at <= TO_TIMESTAMP_TZ(:\"?\", 'YYYY-MM-DD\"T\"HH24:MI:SS.FF\"Z\"')) GROUP BY TRUNC(\"visitors\".created_at, 'DD') ORDER BY 1 ASC FETCH NEXT 10000 ROWS ONLY"
2025-09-15T11:06:07.3974185Z
2025-09-15T11:06:07.3975178Z       49 |     const [sql, params] = query.buildSqlAndParams();
2025-09-15T11:06:07.3975946Z       50 |
2025-09-15T11:06:07.3977396Z     > 51 |     expect(sql).toContain("CAST(TO_TIMESTAMP_TZ(:\"?\", 'YYYY-MM-DD\"T\"HH24:MI:SS.FF\"Z\"') AS DATE)");
2025-09-15T11:06:07.3978622Z          |                 ^
2025-09-15T11:06:07.3979731Z       52 |     expect(params).toEqual(['2024-02-01T00:00:00.000Z']);
2025-09-15T11:06:07.3980583Z       53 |   });
2025-09-15T11:06:07.3981170Z       54 | });
2025-09-15T11:06:07.3981586Z
2025-09-15T11:06:07.3982545Z       at Object.toContain (test/unit/oracle-query.test.ts:51:17)

Please ping me when you push an update so I can trigger a workflow run.

@github-actions github-actions bot added the javascript Pull requests that update Javascript code label Oct 17, 2025
@KSDaemon KSDaemon merged commit b7018c7 into cube-js:master Oct 21, 2025
92 of 96 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data source driver driver:oracle Issues relating to the Oracle driver javascript Pull requests that update Javascript code pr:community Contribution from Cube.js community members.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Oracle timestamp parsing mismatch (TO_DATE vs ISO string with .000Z)

2 participants