Skip to content

[SPARK-58876][SQL] Map Oracle DATE and TIMESTAMP to TimestampNTZType - #58203

Open
aleksandar-trajkovic-db wants to merge 2 commits into
apache:masterfrom
aleksandar-trajkovic-db:spark-oracle-ntz-mapping
Open

[SPARK-58876][SQL] Map Oracle DATE and TIMESTAMP to TimestampNTZType#58203
aleksandar-trajkovic-db wants to merge 2 commits into
apache:masterfrom
aleksandar-trajkovic-db:spark-oracle-ntz-mapping

Conversation

@aleksandar-trajkovic-db

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

The Oracle JDBC dialect maps Oracle DATE and TIMESTAMP to TimestampNTZType by default, independent of the preferTimestampNTZ read option (DATE only when the driver default oracle.jdbc.mapDateToTimestamp=true surfaces it as TIMESTAMP; otherwise it stays DateType). TIMESTAMP WITH TIME ZONE and TIMESTAMP WITH LOCAL TIME ZONE are unchanged (TimestampType). A new spark.sql.legacy.oracle.timestampNTZMapping.enabled (default false) restores the prior behavior. The change also adds convertJavaTimestampToTimestampNTZ / convertTimestampNTZToJavaTimestamp overrides (mirroring PostgresDialect) and a compileValue LocalDateTime case so NTZ filter literals push down as JDBC {ts ...} escapes.

Why are the changes needed?

Oracle DATE and TIMESTAMP are zoneless wall-clock types. Reading them as TimestampType (an instant) rebases the value through the session time zone, so the same stored value reads back differently depending on the reader's zone. TimestampNTZ Type represents these zoneless types faithfully and zone-invariantly.

Does this PR introduce any user-facing change?

Yes. Oracle TIMESTAMP (and DATE under the driver default oracle.jdbc.mapDateToTimestamp=true) now reads as TimestampNTZType instead of TimestampType. Set spark.sql.legacy.oracle.timestampNTZMapping.enabled=true to restore the previous behavior. Documented in the SQL migration guide.

How was this patch tested?

New unit tests in JDBCSuite (type mapping, zone-invariance of the conversion, compileValue literal, and that the mapping stays microsecond TimestampNTZType under the nanosecond-timestamp preview) and new/updated OracleIntegrationSuite docker tests (NTZ read, invariance to JVM/session/Oracle/driver time zones, WHERE pushdown, write round-trip, and mapDateToTimestamp behavior). The full Oracle integration suite passes.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Anthropic Claude Opus 4.8)

This is my original work and I license it to the project under the project's open source license.

Oracle DATE and TIMESTAMP are zoneless wall-clock types, so read them as
TimestampNTZType by default, independent of the preferTimestampNTZ read option.
Oracle DATE follows this only when the driver default oracle.jdbc.mapDateToTimestamp
surfaces it as TIMESTAMP; TIMESTAMP WITH [LOCAL] TIME ZONE stay TimestampType.
The new spark.sql.legacy.oracle.timestampNTZMapping.enabled flag restores the
pre-4.4 behavior.

Co-authored-by: Isaac
.booleanConf
.createWithDefault(false)

val LEGACY_ORACLE_TIMESTAMP_NTZ_MAPPING_ENABLED =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add withBindingPolicy @aleksandar-trajkovic-db

…onfig

Fixes SparkConfigBindingPolicySuite (the failing CI check) and addresses the review comment: new configs must declare a binding policy.

Co-authored-by: Isaac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants