[SPARK-57855][SQL] Refactor JDBC value getters into a sealed type for readability#56936
Closed
Gamal72 wants to merge 2 commits into
Closed
[SPARK-57855][SQL] Refactor JDBC value getters into a sealed type for readability#56936Gamal72 wants to merge 2 commits into
Gamal72 wants to merge 2 commits into
Conversation
f714a95 to
481b94e
Compare
481b94e to
ac2d7e8
Compare
cloud-fan
approved these changes
Jul 2, 2026
cloud-fan
left a comment
Contributor
There was a problem hiding this comment.
0 blocking, 0 non-blocking, 1 nits.
A clean, faithful, behavior-preserving refactor. Transcription verified arm-by-arm; every old match arm matches its new getter case, including ArrayGetter's error args (dt -> arrayType) and the case object singletons being stateless.
Nits: 1 minor item (see inline comments).
…rces/jdbc/JDBCValueGetter.scala Co-authored-by: Wenchen Fan <cloud0fan@gmail.com>
Contributor
|
thanks, merging to master/4.x |
cloud-fan
pushed a commit
that referenced
this pull request
Jul 2, 2026
… readability
### What changes were proposed in this pull request?
`JdbcUtils.makeGetter` builds a per-column reader (`JDBCValueGetter`) that reads a column from a `ResultSet`, converts it to Spark's internal representation, and stores it into an `InternalRow`. `JDBCValueGetter` was a private type alias for `(ResultSet, InternalRow, Int) => Unit`, so `makeGetter` returned an anonymous closure per column.
This PR makes the getter an explicit type:
- Adds `JDBCValueGetter.scala` with a `private[jdbc]` sealed trait `JDBCValueGetter` (single `apply(rs, row, pos)` method) and one named case per getter in its companion object — `case object` for stateless getters, `final case class` for parameterized ones — plus the getter-only helpers `nullSafeConvert` / `arrayConverter`.
- `JdbcUtils.makeGetter` becomes a straightforward `DataType` -> getter selection.
Class hierarchy (sealed):
```
JDBCValueGetter
├─ BooleanGetter, DoubleGetter, FloatGetter, IntGetter, LongGetter, ShortGetter,
│ ByteGetter, StringGetter, RowIdGetter, BytesGetter, BinaryLongGetter,
│ BinaryBitGetter, TimeGetter, LogicalTimeGetter, PostgresBitArrayGetter, NullGetter (case object)
└─ DateGetter, DecimalGetter, TimestampGetter, LogicalTimeNTZGetter, TimestampNTZGetter,
YearMonthIntervalGetter, DayTimeIntervalGetter, ArrayGetter (final case class)
```
Each getter's body is transcribed unchanged from the corresponding `match` arm, and the selection order and guards in `makeGetter` are unchanged.
### Why are the changes needed?
Because `JDBCValueGetter` was only a function alias, the getter chosen for a column was not expressed in the type system: `makeGetter` read as a large `match` returning indistinguishable closures, and an individual getter could not be named or referred to. Turning it into a sealed trait with one named case per getter makes the set of getters explicit and self-documenting, and reduces `makeGetter` to a simple selection over the column's `DataType`, separating "which getter to use" from "what each getter does".
### Does this PR introduce _any_ user-facing change?
No. This is an internal, behavior-preserving refactor of private (`private[jdbc]`) symbols; the per-column read/convert/store logic is unchanged, and there is no public API or binary-compatibility (MiMa) impact.
### How was this patch tested?
Existing JDBC test suites (`JDBCSuite`, `JDBCV2Suite`, `JDBCWriteSuite`, `JdbcUtilsSuite`, etc.). This is a behavior-preserving refactor with no new behavior, so no new tests were added — the getter logic is a direct transcription of the previous `match` arms.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code
Closes #56936 from Gamal72/jdbc-value-getter-sealed-type.
Authored-by: Abdelrahman Gamal <a.gamal@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
(cherry picked from commit 589e007)
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
JdbcUtils.makeGetterbuilds a per-column reader (JDBCValueGetter) that reads a column from aResultSet, converts it to Spark's internal representation, and stores it into anInternalRow.JDBCValueGetterwas a private type alias for(ResultSet, InternalRow, Int) => Unit, somakeGetterreturned an anonymous closure per column.This PR makes the getter an explicit type:
JDBCValueGetter.scalawith aprivate[jdbc]sealed traitJDBCValueGetter(singleapply(rs, row, pos)method) and one named case per getter in its companion object —case objectfor stateless getters,final case classfor parameterized ones — plus the getter-only helpersnullSafeConvert/arrayConverter.JdbcUtils.makeGetterbecomes a straightforwardDataType-> getter selection.Class hierarchy (sealed):
Each getter's body is transcribed unchanged from the corresponding
matcharm, and the selection order and guards inmakeGetterare unchanged.Why are the changes needed?
Because
JDBCValueGetterwas only a function alias, the getter chosen for a column was not expressed in the type system:makeGetterread as a largematchreturning indistinguishable closures, and an individual getter could not be named or referred to. Turning it into a sealed trait with one named case per getter makes the set of getters explicit and self-documenting, and reducesmakeGetterto a simple selection over the column'sDataType, separating "which getter to use" from "what each getter does".Does this PR introduce any user-facing change?
No. This is an internal, behavior-preserving refactor of private (
private[jdbc]) symbols; the per-column read/convert/store logic is unchanged, and there is no public API or binary-compatibility (MiMa) impact.How was this patch tested?
Existing JDBC test suites (
JDBCSuite,JDBCV2Suite,JDBCWriteSuite,JdbcUtilsSuite, etc.). This is a behavior-preserving refactor with no new behavior, so no new tests were added — the getter logic is a direct transcription of the previousmatcharms.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code