Gamal72 opened a new pull request, #56936:
URL: https://github.com/apache/spark/pull/56936
### 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
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]