-
Notifications
You must be signed in to change notification settings - Fork 28.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-42554][CONNECT] Implement GRPC exceptions interception for con…
…version ### What changes were proposed in this pull request? This PR adds GrpcStub and GrpcExceptionConverter utilities to the Spark Connect Scala Client so that the client can intercept the GRPC Exceptions and convert them to Spark related exceptions. The change converts all GRPC RuntimeStatusException to SparkException as a starting point. ### Why are the changes needed? Intercept GRPC Exceptions in Spark Connect Scala Client and convert them to Spark related exceptions for making exceptions more compatible with the existing behaviors ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Existing tests Closes #41743 from heyihong/SPARK-42554. Authored-by: Yihong He <yihong.he@databricks.com> Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
- Loading branch information
1 parent
4b77aad
commit 9f87e19
Showing
10 changed files
with
130 additions
and
21 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
...m/src/main/scala/org/apache/spark/sql/connect/client/CustomSparkConnectBlockingStub.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.spark.sql.connect.client | ||
|
||
import io.grpc.ManagedChannel | ||
|
||
import org.apache.spark.connect.proto.{AnalyzePlanRequest, AnalyzePlanResponse, ConfigRequest, ConfigResponse, ExecutePlanRequest, ExecutePlanResponse, InterruptRequest, InterruptResponse} | ||
import org.apache.spark.connect.proto | ||
|
||
private[client] class CustomSparkConnectBlockingStub(channel: ManagedChannel) { | ||
|
||
private val stub = proto.SparkConnectServiceGrpc.newBlockingStub(channel) | ||
|
||
def executePlan(request: ExecutePlanRequest): java.util.Iterator[ExecutePlanResponse] = { | ||
GrpcExceptionConverter.convert { | ||
GrpcExceptionConverter.convertIterator[ExecutePlanResponse](stub.executePlan(request)) | ||
} | ||
} | ||
|
||
def analyzePlan(request: AnalyzePlanRequest): AnalyzePlanResponse = { | ||
GrpcExceptionConverter.convert { | ||
stub.analyzePlan(request) | ||
} | ||
} | ||
|
||
def config(request: ConfigRequest): ConfigResponse = { | ||
GrpcExceptionConverter.convert { | ||
stub.config(request) | ||
} | ||
} | ||
|
||
def interrupt(request: InterruptRequest): InterruptResponse = { | ||
GrpcExceptionConverter.convert { | ||
stub.interrupt(request) | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...lient/jvm/src/main/scala/org/apache/spark/sql/connect/client/GrpcExceptionConverter.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.spark.sql.connect.client | ||
|
||
import io.grpc.StatusRuntimeException | ||
import io.grpc.protobuf.StatusProto | ||
|
||
import org.apache.spark.{SparkException, SparkThrowable} | ||
|
||
private[client] object GrpcExceptionConverter { | ||
def convert[T](f: => T): T = { | ||
try { | ||
f | ||
} catch { | ||
case e: StatusRuntimeException => | ||
throw toSparkThrowable(e) | ||
} | ||
} | ||
|
||
def convertIterator[T](iter: java.util.Iterator[T]): java.util.Iterator[T] = { | ||
new java.util.Iterator[T] { | ||
override def hasNext: Boolean = { | ||
convert { | ||
iter.hasNext | ||
} | ||
} | ||
|
||
override def next(): T = { | ||
convert { | ||
iter.next() | ||
} | ||
} | ||
} | ||
} | ||
|
||
private def toSparkThrowable(ex: StatusRuntimeException): SparkThrowable with Throwable = { | ||
val status = StatusProto.fromThrowable(ex) | ||
// TODO: Add finer grained error conversion | ||
new SparkException(status.getMessage, ex.getCause) | ||
} | ||
} | ||
|
||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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