Skip to content

[SPARK-57555][FOLLOWUP][SQL] Add TimeType support to MySQLDialect#57198

Open
shrirangmhalgi wants to merge 3 commits into
apache:masterfrom
shrirangmhalgi:SPARK-57555-mysql-time-dialect
Open

[SPARK-57555][FOLLOWUP][SQL] Add TimeType support to MySQLDialect#57198
shrirangmhalgi wants to merge 3 commits into
apache:masterfrom
shrirangmhalgi:SPARK-57555-mysql-time-dialect

Conversation

@shrirangmhalgi

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Add TimeType support to MySQLDialect and precision-preserving DDL for writes:

  • getCatalystType: map Types.TIME to TimeType(scale) when spark.sql.timeType.enabled is true, gated by legacyJdbcTimeMappingEnabled
  • getJDBCType: add TimeType => TIME(p) for p in [0,6], bare TIME for out-of-range precisions (e.g. nanosecond TimeType)

Why are the changes needed?

This is a followup to #56653 which added core JDBC TIME support in JdbcUtils. That PR handled scalar read/write correctly via the generic path, but:

Does this PR introduce any user-facing change?

Yes. When spark.sql.timeType.enabled is true, MySQL TIME and TIME(p) columns now correctly read as TimeType and write with precision-preserving TIME(p) DDL. Non-TIME columns are unaffected.

How was this patch tested?

Added integration tests in MySQLIntegrationSuite:

  • Scalar read: verifies existing dates table TIME column is read as TimeType(0) and TIME(3) as TimeType(3) with correct values
  • Scalar write round-trip: writes TimeType(0) and TimeType(6) values and reads them back
  • Precision preservation: TimeType(3) -> TIME(3) -> read back as TimeType(3)
  • Nanosecond write: TimeType(9) -> bare TIME -> read back as TimeType(6) with microsecond truncation
  • Legacy mode: asserts TIME reads as non-TimeType when legacyJdbcTimeMappingEnabled=true

Unit tests: JDBCSuite (127 tests, all passing).

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

CoAuthored using Claude Opus 4.6

@shrirangmhalgi shrirangmhalgi changed the title Spark 57555 mysql time dialect [SPARK-57555][FOLLOWUP][SQL] Add TimeType support to MySQLDialect Jul 11, 2026
Add TimeType support to MySQLDialect:
- getCatalystType: maps Types.TIME to TimeType(precision) when
  timeType.enabled=true and legacyJdbcTimeMappingEnabled=false.
  Precision is derived from JDBC metadata (scale parameter).
- getJDBCType: maps TimeType(p) to TIME(p) DDL for write path.
- Integration tests: read round-trip, write round-trip, and
  legacy escape hatch verification.
…clamping, proactive fixes

- getCatalystType: use md.build().getLong("scale") for fractional-second
  precision (getScale reports DECIMAL_DIGITS, not display width). Accept
  scale=0 for bare TIME (TIME(0) is valid).
- getJDBCType: use TIME(p) for p<=6, bare TIME for out-of-range
  precisions (e.g. nanosecond TimeType), matching PostgreSQL pattern.
- Fix read test: bare TIME column reports scale=0, truncates fractional
  seconds (value 13:31:24 not 13:31:24.123).
- Add precision preservation round-trip test (TimeType(3) -> TIME(3))
- Add nanosecond TimeType(9) write test (MySQL truncates to micros)
- Add comment explaining precision source from JDBC metadata
…SION

MySQL Connector/J Bug #84308: getPrecision()=8 and getScale()=0 for all
TIME columns regardless of declared precision. Override updateExtraColumnMeta
to query INFORMATION_SCHEMA.COLUMNS.DATETIME_PRECISION and inject the real
precision into the metadata, which getCatalystType then reads.
@shrirangmhalgi shrirangmhalgi force-pushed the SPARK-57555-mysql-time-dialect branch from 499448d to 75cd5c7 Compare July 11, 2026 14:13
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.

1 participant