Commit c32aee1
[SPARK-55243][CONNECT] Allow setting binary headers via the -bin suffix in the Scala Connect client
### What changes were proposed in this pull request?
Automatically use the `Metadata.BINARY_BYTE_MARSHALLER` for `-bin` suffixed header keys, assuming base64-encoded header value strings set through the Scala Spark Connect client builder.
### Why are the changes needed?
The Scala Spark Connect client currently only allows setting `Metadata.ASCII_STRING_MARSHALLER` headers and fails if one tries to put a (binary) header with `-bin` key suffix:
```
[info] java.lang.IllegalArgumentException: ASCII header is named test-bin. Only binary headers may end with -bin
[info] at com.google.common.base.Preconditions.checkArgument(Preconditions.java:445)
[info] at io.grpc.Metadata$AsciiKey.<init>(Metadata.java:972)
[info] at io.grpc.Metadata$AsciiKey.<init>(Metadata.java:966)
[info] at io.grpc.Metadata$Key.of(Metadata.java:708)
[info] at io.grpc.Metadata$Key.of(Metadata.java:704)
[info] at org.apache.spark.sql.connect.client.SparkConnectClient$MetadataHeaderClientInterceptor$$anon$2.$anonfun$start$1(SparkConnectClient.scala:1112)
[info] at org.apache.spark.sql.connect.client.SparkConnectClient$MetadataHeaderClientInterceptor$$anon$2.$anonfun$start$1$adapted(SparkConnectClient.scala:1106)
[info] at scala.collection.immutable.Map$Map1.foreach(Map.scala:278)
[info] at org.apache.spark.sql.connect.client.SparkConnectClient$MetadataHeaderClientInterceptor$$anon$2.start(SparkConnectClient.scala:1106)
[info] at io.grpc.stub.ClientCalls.startCall(ClientCalls.java:435)
```
### Does this PR introduce _any_ user-facing change?
Current behaviour: Fails for all header key-value pairs if the key has the `-bin` suffix with an `IllegalArgumentException`.
New behaviour: Adds a `Metadata.BINARY_BYTE_MARSHALLER` header if the key has a `-bin` suffix and the value string is base64-encoded.
### How was this patch tested?
Added a test to `SparkConnectClientSuite`.
### Was this patch authored or co-authored using generative AI tooling?
No.
Closes apache#54016 from dillitz/fix-bin-header.
Authored-by: Robert Dillitz <r.dillitz@gmail.com>
Signed-off-by: Herman van Hövell <herman@databricks.com>1 parent 5c320f4 commit c32aee1
File tree
2 files changed
+84
-7
lines changed- sql/connect
- client/jvm/src/test/scala/org/apache/spark/sql/connect/client
- common/src/main/scala/org/apache/spark/sql/connect/client
2 files changed
+84
-7
lines changedLines changed: 73 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
25 | | - | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
45 | | - | |
| 46 | + | |
46 | 47 | | |
47 | | - | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | | - | |
| 51 | + | |
| 52 | + | |
51 | 53 | | |
52 | 54 | | |
53 | 55 | | |
| |||
622 | 624 | | |
623 | 625 | | |
624 | 626 | | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
625 | 693 | | |
626 | 694 | | |
627 | 695 | | |
| |||
Lines changed: 11 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
1093 | 1094 | | |
1094 | 1095 | | |
1095 | 1096 | | |
| 1097 | + | |
| 1098 | + | |
1096 | 1099 | | |
1097 | 1100 | | |
1098 | 1101 | | |
| |||
1103 | 1106 | | |
1104 | 1107 | | |
1105 | 1108 | | |
1106 | | - | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
1107 | 1116 | | |
1108 | 1117 | | |
1109 | 1118 | | |
| |||
0 commit comments