davidm-db opened a new pull request, #56449:
URL: https://github.com/apache/spark/pull/56449

   ### What changes were proposed in this pull request?
   
   This is a small, type-system-only refactor of the Types Framework. The 
server-side `TypeOps`
   trait now extends the api-side `TypeApiOps` trait instead of `Serializable`:
   
   ```scala
   -trait TypeOps extends Serializable {
   -  /** The DataType this Ops instance handles. */
   -  def dataType: DataType
   +trait TypeOps extends TypeApiOps {
   ```
   
   Concrete `*TypeOps` classes already extend their matching `*TypeApiOps`
   (e.g. `TimeTypeOps extends TimeTypeApiOps(t) with TypeOps`), so this change 
has no effect on any
   existing implementation -- it only lifts that relationship to the trait 
level. As a result the
   duplicate `def dataType: DataType` declaration on `TypeOps` is removed (it 
is inherited from
   `TypeApiOps`), and the class doc / implementation guidance are updated to 
match.
   
   ### Why are the changes needed?
   
   The framework factory `TypeOps.apply(dt)` returns `Option[TypeOps]`, so call 
sites manipulate
   values whose static type is `TypeOps`. The client-side operations (`format`, 
`toSQLValue`,
   `getEncoder`, ...) are declared on `TypeApiOps`. Before this change, 
invoking a client-side
   operation on a value known only as `TypeOps` required a runtime 
`isInstanceOf[TypeApiOps]` narrow,
   which is sound only by the convention that every concrete `*TypeOps` happens 
to extend a
   `*TypeApiOps` -- nothing in the type system enforces it.
   
   Making `TypeOps` extend `TypeApiOps`:
   - lets callers holding an `Option[TypeOps]` invoke client-side methods 
directly via `.map`, without
     an unsafe downcast;
   - turns "every server-side `TypeOps` is also a client-side `TypeApiOps`" 
into a compile-time
     guarantee rather than a runtime invariant -- a new `*TypeOps` that does 
not provide the
     client-side operations will not compile;
   - removes the now-redundant `dataType` declaration that both traits 
previously carried.
   
   This is a forward-looking modeling change: as more server-side integration 
points need client-side
   operations on a `TypeOps` value, they can call them directly and safely.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No. This is an internal, type-system-only refactor with no behavioral change.
   
   ### How was this patch tested?
   
   No new tests are needed -- this is a compile-time-only change with no 
behavioral difference. It is
   covered by compilation and the existing Types Framework test suites.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code
   
   This pull request and its description were written by Isaac.
   


-- 
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]

Reply via email to