Commit e355228
[SPARK-49960][SQL] Custom ExpressionEncoder support and TransformingEncoder fixes
### What changes were proposed in this pull request?
4.0.0-preview2 introduced, as part of SPARK-49025 pr #47785, changes which drive ExpressionEncoder derivation purely from AgnosticEncoders. This PR adds a trait:
```scala
DeveloperApi
trait AgnosticExpressionPathEncoder[T]
extends AgnosticEncoder[T] {
def toCatalyst(input: Expression): Expression
def fromCatalyst(inputPath: Expression): Expression
}
```
and hooks in the De/SerializationBuildHelper matches to allow seamless extension of non-connect custom encoders (such as [frameless](https://github.com/typelevel/frameless) or [sparksql-scalapb](https://github.com/scalapb/sparksql-scalapb)).
SPARK-49960 provides the same information.
Additionally this PR provides fixes necessary to use TransformingEncoder as a root encoder with an OptionalEncoder, use as an ArrayType and MapType entry/key.
### Why are the changes needed?
Without this change (or similar) there is no way for custom encoders to integrate with 4.0.0-preview2 derived encoders, something which has worked and devs have benefited from since pre 2.4 days. This stops code such as Dataset.joinWith from deriving a tuple encoder which works (as the provided ExpressionEncoder is now discarded under preview2). Supplying a custom AgnosticEncoder under preview2 also fails as only the preview2 AgnosticEncoders are supported in De/SerializationBuildHelper, triggering a MatchError.
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
Test was added using a "custom" string encoder and joinWith based on an existing joinWith test. Removing the case statements in either BuildHelper will trigger the MatchError.
### Was this patch authored or co-authored using generative AI tooling?
No
Closes #50023 from chris-twiner/temp/expressionEncoder_compat_TransformingEncoder_fixes.
Authored-by: Chris Twiner <[email protected]>
Signed-off-by: Herman van Hovell <[email protected]>
(cherry picked from commit 50a328b)
Signed-off-by: Herman van Hovell <[email protected]>1 parent 13d9c91 commit e355228
File tree
9 files changed
+291
-20
lines changed- sql
- api/src/main/scala/org/apache/spark/sql/catalyst/encoders
- catalyst/src
- main/scala/org/apache/spark/sql/catalyst
- encoders
- test/scala/org/apache/spark/sql/catalyst/encoders
- connect/common/src/main/scala/org/apache/spark/sql/connect/client/arrow
- core/src/test/scala/org/apache/spark/sql
9 files changed
+291
-20
lines changedLines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
276 | 276 | | |
277 | 277 | | |
278 | 278 | | |
| 279 | + | |
| 280 | + | |
279 | 281 | | |
280 | 282 | | |
281 | 283 | | |
282 | 284 | | |
283 | | - | |
| 285 | + | |
| 286 | + | |
284 | 287 | | |
285 | 288 | | |
286 | 289 | | |
| |||
Lines changed: 6 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
270 | 270 | | |
271 | 271 | | |
272 | 272 | | |
| 273 | + | |
| 274 | + | |
273 | 275 | | |
274 | 276 | | |
275 | 277 | | |
| |||
447 | 449 | | |
448 | 450 | | |
449 | 451 | | |
450 | | - | |
| 452 | + | |
451 | 453 | | |
452 | 454 | | |
453 | | - | |
| 455 | + | |
454 | 456 | | |
455 | 457 | | |
456 | | - | |
| 458 | + | |
457 | 459 | | |
458 | 460 | | |
459 | 461 | | |
| |||
Lines changed: 10 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
306 | 306 | | |
307 | 307 | | |
308 | 308 | | |
| 309 | + | |
309 | 310 | | |
310 | 311 | | |
311 | 312 | | |
| |||
418 | 419 | | |
419 | 420 | | |
420 | 421 | | |
421 | | - | |
| 422 | + | |
422 | 423 | | |
423 | 424 | | |
424 | | - | |
| 425 | + | |
425 | 426 | | |
426 | 427 | | |
427 | | - | |
| 428 | + | |
428 | 429 | | |
429 | 430 | | |
430 | 431 | | |
431 | 432 | | |
432 | | - | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
433 | 437 | | |
434 | 438 | | |
435 | 439 | | |
| |||
486 | 490 | | |
487 | 491 | | |
488 | 492 | | |
| 493 | + | |
489 | 494 | | |
490 | 495 | | |
491 | 496 | | |
| |||
Lines changed: 25 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
29 | 54 | | |
30 | 55 | | |
31 | 56 | | |
| |||
Lines changed: 10 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
215 | 216 | | |
216 | 217 | | |
217 | 218 | | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
218 | 226 | | |
219 | 227 | | |
220 | 228 | | |
| |||
228 | 236 | | |
229 | 237 | | |
230 | 238 | | |
231 | | - | |
| 239 | + | |
| 240 | + | |
232 | 241 | | |
233 | 242 | | |
234 | 243 | | |
| |||
0 commit comments